TechnicalArchitectureWorx

The (Unofficial) ITWorx Technical Architecture Blog

Passing Parameters to Flex

Posted by archworx on August 16, 2007

Adobe Flex is a great way to do Rich Internet Applications (RIA). When you need to pass a parameter the flex flash movie, you can do that simply by adding a line in the generated script tag.

...
} else if (hasRequestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    AC_FL_RunContent(
        "src", "Main",
        "flashVars", "i=15&employeeName=xyz", // add this line with the vars you want to pass
        "width", "100%",

...

Then, in flex, you can access this parameter as follows:

application.parameters.i

Posted in El-Geish, Flex | 3 Comments »

What are the Best Practices for Versioning?

Posted by archworx on July 5, 2007

Versioning is mainly used to identify multiple revisions of the same unit of information/code. Versioning is the corner stone of Software Development – it is used to differentiate between the different work you do everyday. If you do not version it is almost like you haven’t accomplished anything.

RULE #1
Version number should be stored in object code, for example a .NET assembly.

  • This is so it can be accessed from the code itself. This is important because, for instance you can use it to gauge compatibility with other systems that you need to interact with. For example:

    • If you are using a web service, there should be a way to query the web service’s version number from the web service itself. The Web Service itself may also need to know its client’s version numbers. With this information, you can programmatically control version compatibility, for instance the web service can deny the service to its clients because it knows that it is of an incompatible version.

RULE #2
Version Numbers Must be Unique and non-repeated.

  • No two releases with any differences can hold the same version number. Even if it is just a minor bug fix. Even if it is a spelling mistake.

RULE #3
Version Numbers must be related to the Source Control Label/Tag.

  • This works both ways, for example:
    1. The Source Safe label used in labeling a release should contain the same version number stored in the compiled binary, or part thereof.
    2. The Version Number produced inside the binary must be as closely related as possible to the label/tag name. Ideally part of the version number should be retrieved from the Source Control system. For example, using SourceSafe/KeyWordExpansion

RULE #4
Version numbers must be user accessible.

  • Users of the application must be able to find out which version of the software they are using. Do not hide it from them, and make sure they can access it relatively easily.

RULE #5
Version numbers must be consistent across Configuration Items

  • The version numbers stored inside the product binary must be the same as that reported to the user, as well as being strongly related to the source control label/tag name. The best way to achieve this is via a build control tool such as NAnt and/or Cruise Control for example.

More about Version numbers:

  • Version numbers can look like x.x.x or x.x.x.x depending on mechanism or technology used.

Posted in Configuration Management, MZayet | 10 Comments »

Testing Webservices with NUnit

Posted by archworx on July 1, 2007

Because NUnit is an exe and you sometimes you need to access web.config and objects that are only present in a web context, you will need to do the following:

– Open the command prompt and cd to C:\Program Files\Microsoft Visual Studio 8\VC, or in Visual Studio 2005 Command Prompt, type wsdl url (where url is the WSDL URL). A C# file will be generated with the name of the webservice. You can add some command line arguments to change the file name or the language. Just type wsdl without any arguments to show the help.

– Move the file to your test project and use it. It will call the webservice 🙂

There’s a great article about Implementing Service-Oriented Integration with ASP.NET .. check it out.

Posted in El-Geish, Unit Testing | 4 Comments »

Testing Private Methods

Posted by archworx on June 21, 2007

Test Driven Development a practice that is becoming very popular due to the quality assurance that it adds. While it is easy to test public methods, How do I test private methods?

There are 2 ways:

  1. Using Helper Class discussed on The Code Project
  2. Using Microsoft’s build in Testing Tools

Example:

using Microsoft.VisualStudio.TestTools.UnitTesting;
PrivateObject po = new PrivateObject(new TestClass());
po.Invoke('PrivateMethodName'); /*This will invoke the private method*/
po.GetField('PrivateFieldName'); /*This will get the value of a private variable*/

Posted in Unit Testing, YShahin | Leave a Comment »

Nunit vs MsTest

Posted by archworx on June 10, 2007

After doing a lot some investigations and trying it for ourselves, we came to the conclusion that its better for us to use Nunit instead of using Mstest (the automated unit tests generated by Visual Studio 2005). Of coarse that’s not a general rule, depends of the project and your environment, but in most of our projects, we prefer Nunit for the following reasons

  1. It’s an open standard
  2. Works on all versions of Visual Studio, whereas MsTest only works with Team system or VSTS
  3. Much easier to integrate with Cruise Control (our continuous integration server)
  4. More suited for test driven development cause it allows you to start by coding the tests, whereas the main benefit of MsTest is that it can generates test stubs from your code.

Decide based on your project.

Posted in Continuous Integration, Extreme Programming, Nader | Leave a Comment »

Developing Reusable .NET Components

Posted by archworx on June 10, 2007

Hello All,

I have been developing Custom ASP.NET Server Controls for a while now and I think it is worthwhile to write a series of blog posts about how to develop them. So here we go with the first introductory blog. First, let us think why developing .NET components is important. Well, first of all Microsoft has developed a decent set of components and controls for the .NET framework, but surely these preexisting components don’t fit every scenario that you might need when you are developing your application, so this is why creating new components (or extending existing ones) is needed. More importantly it is the concept of reusability that particularly makes developing such components useful. Identifying certain recurring scenarios and common functionalities and developing a certain component that can be reused by yourself and others without having to re-write the same code again is very valuable. A friend of mine has recently told me that “A good developer only writes code once”. This proverb, albeit an oversimplification, captures the essence of reusability. Great, so what implications does this have on you as a developer? Well, being able to capture repetitive scenarios into reusable code is very important. So next time you write code try to think if you have written this code before (or if you are going to write it again in the future) and if so then you can try to encapsulate it into a component that can be reused (even if this means creating a simple code snippet). This doesn’t only apply to code that you write, but if you are smart enough you can identify recurring patterns inside applications that your organization is developing and hence suggest how reusable components can be used within the company to improve the development process. So, with this introduction over we will turn to talking about Custom Controls in .NET and how they differ from User Controls. But alas, this will have to wait till the next blog.

Posted in .NET 2.0, AFathalla, Programming, Reusable Components | Leave a Comment »

MsTest working in CruiseControl.Net

Posted by archworx on June 6, 2007

I’ve trying to get MsTest, the unit tests generated by Visual Studio 2005, to work with cruise control for a while now. So finally I was able to get it to work following these steps below 

Let’s say we have a solution called ITT in the following path c:/ITT, first we’ll look at the ccnet config file, after you compile using the msbuild task, you have to call an exec task to execute the MsTests, but before that you have to delete the test results file because MsTest won’t run if the file is already there, we are doing this by calling a batch file to delete this test results file and also delete the temp folders created by MsTest. After that you have to merge the results file with build output so I can be displayed in the dashbaord.

 <project name=”ITT”>
    <webURL>http://localhost/ccnet</webURL&gt;
    <triggers>
      <intervalTrigger seconds=”100″ />
    </triggers>
    <modificationDelaySeconds>120</modificationDelaySeconds>

    <!– here you do the task to get the project from the source control –>
    <!–sourcecontrol type=”vss” autoGetSource=”true” applyLabel=”false”>
    </sourcecontrol–>

    <tasks>
      <!– task to build the solution–> 
      <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
        <workingDirectory>c:\ITT</workingDirectory>
        <projectFile>ITT.sln</projectFile>
        <targets>Build</targets>
        <timeout>60</timeout>
        <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
      </msbuild>

      <exec>
        <!– call a batch file that deletes results.trx –>
        <!– this is required as MsTest will not create the file if it exists–>
        <!– the batch file also deletes the temp folders created by MsTest –> 
        <executable>delTestLog.bat</executable>
        <baseDirectory>c:\ITT</baseDirectory>
        <buildArgs></buildArgs>
        <buildTimeoutSeconds>30</buildTimeoutSeconds>
      </exec>
     
      <exec>
        <!– the exec task to execute the MsTest task –>
        <executable>C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\MSTest.exe</executable>
        <baseDirectory>c:\ITT</baseDirectory>
        <buildArgs>/testcontainer:\ITT\AnalysisLibTests\bin\Debug\AnalysisLibTests.dll /runconfig:localtestrun.testrunconfig /resultsfile:results.trx</buildArgs>
        <buildTimeoutSeconds>600</buildTimeoutSeconds>
      </exec>

    </tasks>
    <publishers>
      <!–to get the test results in the dashboard we have to merge the results XML file –>
      <merge>
        <files>
          <file>c:\ITT\results.trx</file>
        </files>
      </merge>
      <xmllogger />
      <email from=”CruiseControl” mailhost=”mail” includeDetails=”TRUE”>

      </email>
    </publishers>
</project>

The next step is to modify the dashboard config file to display the test results, first we update the dashboard.config file to include the MsTests details menu item and then we add the MsTest results summary to the main build page. The required xsl files are already included with ccnet, you can customize the xsl to fit your needs

<buildReportBuildPlugin>
  <xslFileNames>
    <xslFile>xsl\header.xsl</xslFile>
    <xslFile>xsl\modifications.xsl</xslFile>
    <xslFile>xsl\compile.xsl</xslFile>
    <xslFile>xsl\MsTestSummary.xsl</xslFile> <!– MsTest results summary in main page–>
    <xslFile>xsl\unittests.xsl</xslFile> <!– Nunit test results, can be removed if not required any more –>
    <xslFile>xsl\fxcop-summary.xsl</xslFile>
    <xslFile>xsl\NCoverSummary.xsl</xslFile>
    <xslFile>xsl\SimianSummary.xsl</xslFile>
    <xslFile>xsl\fitnesse.xsl</xslFile>
  </xslFileNames>
 </buildReportBuildPlugin>
 <buildLogBuildPlugin />
   <xslReportBuildPlugin description=”NUnit Details” actionName=”NUnitDetailsBuildReport” xslFileName=”xsl\tests.xsl” />
   <xslReportBuildPlugin description=”NUnit Timings” actionName=”NUnitTimingsBuildReport” xslFileName=”xsl\timing.xsl” />
   <xslReportBuildPlugin description=”MSTest Report” actionName=”MSTESTReport” xslFileName=”xsl\MsTestReport.xsl”/> <!– menu item –>
   <xslReportBuildPlugin description=”NAnt Output” actionName=”NAntOutputBuildReport” xslFileName=”xsl\NAnt.xsl” />
   <xslReportBuildPlugin description=”NAnt Timings” actionName=”NAntTimingsBuildReport” xslFileName=”xsl\NAntTiming.xsl” />
   <xslReportBuildPlugin description=”FxCop Report” actionName=”FxCopBuildReport” xslFileName=”xsl\FxCopReport.xsl” />
   <xslReportBuildPlugin description=”NCover Report” actionName=”NCoverBuildReport” xslFileName=”xsl\NCover.xsl” />
   <xslReportBuildPlugin description=”Simian Report” actionName=”SimianBuildReport” xslFileName=”xsl\SimianReport.xsl”/> 

 That’s all

Posted in Continuous Integration, Nader, VS 2005 | 3 Comments »

Visual Studio Team System Adventures – Architect Edition Designers

Posted by archworx on June 5, 2007

I got this question from someone about the Visual Designers in VSTS Enterprise Architect Edition, basically the person was confused with all the designers available and what each one does.

I decided to do a little explanation here, but first I would like to discuss the concept of VSTS Arch Edition. Basically the whole idea behind VSTS is to have Architects (Enterprise, Solution, Infrastructure), Developers, Quality Engineers, Configuration Managers, Project Managers all working together from the same IDE and to have the output of each role saved to a central server so that the whole team can collaborate and communicate easily.

Using VSTS the whole idea of the Architect who walks in, draws fancy diagrams, and lets the developers and project implementers handle the details is over. This type of collaboration helps verify that designs are implementable and keeps the architect in the picture as the design evolves towards implementation requirements.

VSTS Architects Edition:

This edition of Visual Studio is used by Architects to design the system, and communicate those designs with the other members of the team. The word Architect here is very generic, because in reality you can have lots of different types of Architects, each looking at the system from a different perspective.

The main roles and perspectives that are found in almost every software project are as follows:

  1. The Enterprise Architect:This person makes sure that the system being design acts as part of a bigger larger system that benefits the organization as a whole and that conforms to the organization’s standards. The main focus here would be integration with other systems and standards compliance including performance and messaging.
  2. The Infrastructure Architect:This person focuses mainly on the system Physical Architecture, so the diagrams produced would contain information like the number of servers, server configuration, locations, communication lines.
  3. The Solution Architect:The main focus here is the solution at hand; this person takes the input from the Enterprise and Infrastructure Architect and creates a solution that would fit in the Physical and Logical requirements of the entire system. The diagram produced would contain information like the Logical Architecture, the distinct system layers, and the communication points with other systems.

    

The Designers and how they fit in:

VSTS Architects Edition has a lot of designers that can be used to represent different views of the system. As mentioned above it is possible for each of the above roles to be performed by a different person which makes consolidating and validating these designs all the lot harder. VSTS makes this task so much easier by validating the diagrams against each other, hence allowing the Architects to work together and not to break each other’s designs.

I will mention the most important designers:

  1. Distributed System Designer
  2. Application Designer
  3. Class Designer
  4. Deployment Designer
  5. Logical Datacenter designer

In this posting I will basically answer the question about the Application Designer, I will post on each of the designers I mentioned here in coming posts.

Application Designer is used to design applications that can provide or use services within the scope of a Visual Studio solution. It is a designer mainly used for high level tasks.

I will explain some common scenarios for this tool :

1. If you have a visual studio solution and would like to reverse engineer it so you could see the different components and how they communicated Application Designer would be the tool to use.

2. You could also specify settings and constraints for my application like which protocol it would use to communicate with other services, and connection strings in the web.config.

3. You could define the databases and web services that communicate with my application.

4. You could specify a custom communication protocol that my application will use with windows communication foundation.

After designing your application, you would need to perform the following tasks:

1. Evaluate the application for deployment on the deployment production environment using the development configurations, this would help determine whether or not your logical design is compatible with your physical design.

2. Design parts of your system for reusability.

These are the main features of Application Designer, please post your comments if you there is anything that needs clarification and I will address them in my coming posts.

Posted in MSamy, Visual Studio Team System | Leave a Comment »

Generating Documentation for .NET assemblies using SandCastle

Posted by archworx on June 4, 2007

I was developing a Control Library for .NET 2.0 and wanted to generate neat looking documentation from XML tags that I had written in code. So I googled around for a bit until I found that you can use a tool called SandCastle to generate HTML documentation that could be transformed into CHM and HxS formats. Here are the steps you have to do:

1- Inside VS2005 right click your project in the Solution Explorer and choose ”Properties”.

2- Click “Build” tab, under “Ouput” make sure that you check the “XML documentation file” checkbox. Once you do so, you can fill in a textbox that specifies the path of where the XML file (that contains the tags you put in code) will be generated.

3- Download and Install HTML Help Workshop .

3- Download and Install SandCastle March 2007 CTP .

4- Download and Install SandCastle Help File Builder (A really cool project on CodePlex that provides a UI that utilizes Sandcastle to generate Help Files)

5- Use SandCastle Help file Builder to generate your documentation .

Voila, you’ve got a cool professional documentation for your .NET project

Posted in .NET 2.0, AFathalla, Documentation, VS 2005 | 5 Comments »

Cygwin NFS Server HOWTO

Posted by archworx on May 31, 2007

This document shows how to install a minimal Cygwin enviroment to host an NFS server.

If you’re using Windows XP, be sure to check out the last sections on firewall and network device problems before you try testing your configuration.
Please read the official documentation first

Things often change in the Cygwin project .After installing Cygwin and the nfs-server (see below) you will find the documentation here:
/usr/share/doc/Cygwin/nfs-server-x.y.z.README

You need a directory for the Cygwin installation.
c:\Cygwin

You will also need a place to archive the Cygwin packages. This should be where you keep other installers. For this example, we create the directory:
e:\CygwinInstaller

Enter this string in your browser’s address bar:
http://www.cygwin.com/setup.exe

Download the installer (setup.exe) to:
e:\CygwinInstaller

Now run the setup.exe program. Press Next on the splash window and select
Install from Internet

Press Next.
Your root directory should be:
c:\Cygwin

Select: “Install For: All Users”
Select: “Default Text File Type: Unix”
Press Next.
Specify your local package directory: (for example)
e:\CygwinInstaller

Press Next. Select: “Direct Connection” Press Next.

Choosing a mirror is tricky. You want to find a fast one. I’ve had good luck with:
http://cygwin.get-software.com

Press Next.
A list of packages will rapidly appear in the setup window.

Installing extra packages

Several packages are needed beyond the default installation. If you’ve been messing around, press the “View” button repeatedly to cycle through to the “Category” view.

Adding vim:
Click on the + sign next to the Editors category. Scroll down to find the “vim” item and click on the word “Skip.” Each time you click in this area, the text will change, scrolling through the available versions of the package. Often, it is a good idea to select the most recent version of the package. For example, “6.2-3”. The box in the “Bin?” column should be checked automatically.

Or you can add mono
A powerlfull but much simpler text editor because anybody who are not familiar with vi editor will probably face some dificulties 🙂
Click on the + sign next to the Editors category. Scroll down to find the “mono” item and click on the word “Skip.”

Adding nfs-server:
Click on the + sign next to the Net category. Scroll down to find the nfs-server item and click on the word “Skip” so it becomes “Install.” Select a recent version of the package. Note: The nfs-server is fairly new, so if you don’t see it in the Net category, back out and try a different Cygwin server.

Adding sunrpc:
This component is found in the Libs category. Scroll down to find the sunrpc item and click on the word “Skip” until it becomes “Install.” Select a recent version of the package.

Adding cygrunsrv:
This utility lets you configure the nfs server as a Windows system service. Click on the + sign next to the Admin category. Scroll down to find the cygrunsrv item and click on the word “Skip”. Select a recent version of the package.

Press Next.
All your packages as well as any packages they require will be downloaded and installed.
Configuring the server

Run the configuration script

In the cygwin shell window, run:
/usr/bin/nfs-server-config

A number of warnings will appear about you installing cygwin for a single user, even though you didn’t. You can ignore these complaints.

Editing the configuration files

You probably need to learn the “vi” editor so you can easily create or modify Cygwin configuration files without installing all of X-Windows to support a GUI editor. You will be annoyed if this is your first exposure to vi. Give in. Learn it. It Is Your Destiny.

Otherwise, use Notepad and find some way to convert from windows to unix text format. (Try the drag-n-drop programs uf2d and df2u.)

Host access control files

If you perform the installation of cygwin as described above, you will not need to edit /etc/hosts.allow or /etc/hosts.deny. If you have installed tcp-wrappers by accident or because you decided to install everything, you will need to edit them:

Edit:
/etc/hosts.allow

To enable access by just one host:
nfsd: 148.150.62.152

To enable an entire subnet:
nfsd: 148.150.0.0/255.255.0.0

Edit
/etc/hosts.deny

Comment out any lines that appear in this file. It will be empty unless you have chosen to install other Cygwin network packages.

The hosts.allow and hosts.deny files support more complex authorization schemes. See “man hosts_acccess” and “man hosts_options” if you need more precise control.

Export directories

Edit:
/etc/exports

This is where you export local directories.

This example exports the /pub directory to everyone in the 148.150.62 subnet.
/pub 148.150.62.0/255.255.255.0(ro, no_root_squash)

The option “ro” means read-only. Use “rw” for read-write.

You cannot use the wildcard “*” in host numbers:
No: 148.150.62.*

You can use the wild card in host names:
Yes: *.mts.com

To use ip names, the name must be a real DNS name or it must in your /etc/hosts file.

Note: The Cygwin hosts file: /etc/hosts is actually a shortcut to your windows hosts file at:
c:\winnt\system32\drivers\etc\hosts

For some reason, nfs mounts are MUCH faster if you don’t authorize entire subnets. It is better to list specific hosts.

Per-user authorization

If the user and group numbers on the client machine match those of an authorized user on the server, access is allowed based on the privilages granted to the user on the server.

Note: You can only have users & permissions in Cygwin if you are using NTFS in windows. If you have FAT32, you must connect as root from the remote system.

The root account is special. Access is never allowed to remote root users unless the “no_root_squash” option is used (as shown in the example above.)

The easy way is to access the server from a client running as root and use the no_root_squash option.
Starting the server

Run:
Start Menu/Programs/Administrative Tools/Services

There are three services associated with NFS:
Cygwin mountd
Cygwin nfsd
Cygwin portmap

Right-click on each of these and use the pop-up menu to start all three servers. You will find that portmap starts automatically when you start either nfsd or mountd first. There is a dependency between system services that Windows tries to maintain automatically.

After editing any of the configuration files the /etc directory, you must restart these services. Because mountd and nfsd are configured to depend on portmap, it is sufficent to right-click on portmap and select “restart.” A dialog will appear to confirm that you also want to restart mountd and nfsd.
Mounting an nfs share on the client machine

The client machine in the following example is assumed to be a Linux or other Unix system. If you have a nice free NFS client for Windows, I’d like to hear about it so I can add a link on this page.

For this example, we assume that the NFS server running on your Windows machine has an ip name “remote” and an exported directory “/pub” defined under /etc/exports as shown above.

The name “remote” only has to be defined on the Linux/Unix client. You can define the name in /etc/hosts or just use the ip number of your Windows server in the following example.

Log into your client machine. You probably need to be “root” to mount the remote nfs directory.

Create a local directory:
mkdir /mnt/there

Mount the share:
mount -t nfs remote:/pub /mnt/there

You should now be able to poke around in /mnt/there, and see any files located in the “/pub” directory on the Cygwin/Windows side.

Important update: A reader of this HOWTO has discovered that CygwinNFS does not support NFS version 3, which is now the default in Linux. To overcome this problem you must add an option to the mount command line: “-overs=2” The full command line becomes:
mount -t nfs -o nfsvers=2 remote:/pub /mnt/there

An alternative specification using “vers” also works on Linux and other Unix-like systems:
mount -t nfs -o vers=2 remote:/pub /mnt/there

(Thanks to Mr. Ostrozhansky!)
Exporting other Windows directories

If you run “mount” with no parameters in the cygwin shell, you will see a list of mounted directories.

The Windows root directories, c:\, d:\ etc will also appear in this list. They are accessed through the special path names /cygdrive/c, /cygdrive/d etc. If you visit the root “/” of cygwin, you will find that these mount points don’t actually exist. If you try to list them in the nfs /etc/exports file, they will fail to mount on the client system.

This is probably a bug, but there is a simple work-around:

Create a directory for each Windows volume you want to export and then mount them directly to the windows pathname:

Make directories to use as mount points:
mkdir -p /mnt/c
mkdir -p /mnt/d

Mount the windows directories:
mount c:/ /mnt/c
mount d:/ /mnt/d

Now you can export these directories in /etc/exports:
/mnt/c myClient.com(rw, no_root_squash)
/mnt/d myClient.com(rw, no_root_squash)

Don’t forget to restart the portmap service in Windows.

You may be worried about what happens to your mounts when you reboot windows: They are stored in the registry, rather than /etc/fstab. After a reboot, they are restored and they will be available to remote systems via NFS.

In fact, if you reboot windows when an nfs mount was created on a remote client, the mounted files will still be available after windows reboots.
Uninstalling Cygwin

Stop the services:
cygrunsrv –stop mountd
cygrunsrv –stop nfsd
cygrunsrv –stop portmap

Remove the services:
cygrunsrv –remove mountd
cygrunsrv –remove nfsd
cygrunsrv –remove portmap

If you use Cygwin to run other services such as X-Windows, you should stop these processes now.

Exit the shell and run the Cygwin setup.exe Use the “View” button repeatedly to cycle to the “Category” view, then click on the “Default” text next to category “All” to cycle through until you see Uninstall.

Press Next-> to remove everthing.

Cygwin is one of those programs that doesn’t really like to be uninstalled. To finish the job, delete everything in your c:\cygwin directory. You may find that you need to stop residual cygwin processes with the Task Damager before you can delete everthing in the Cygwin folder. Reboot if necessary.

Next, run Regedit and search for cygwin. Delete all the keys you find and any surrounding “Cygnus Solutions” folders.
Windows XP Issues

Many people report trouble running the NFS server under Windows XP. Since service pack 2, XP has a firewall which will block NFS connections by default.

A great thanks for Hugh Sparks who made this document.
http://www.csparks.com/CygwinNFS/index.xhtml

Posted in Bubly, Open Source | 4 Comments »