Sunday, May 13, 2007

Verifying .net assembly attributes recursively

I was once given the responsibility of verifying the assembly attributes of all the assemblies in a .NET solution prior to each release. This was a very monotonous job considering the fact that this had to be done manually. For two of the releases, I used to open the properties of each dotnet assembly and verify if the attributes were correct in the release version. In a better situation I would have gone through the assemblyinfo.cs in each project and verified it (which is no better), but sadly I did not have access to the versioning server.

I did a bit of soul searching and decided that this was not the correct way to go through it. I wrote a small win app that could be used to do this

FileStream txtfile;

StreamWriter sw;

private void btnCheck_Click(object sender, EventArgs e)

{

try

{

txtfile = new FileStream(txtOutputFile.Text, FileMode.Create , FileAccess.Write);

sw = new StreamWriter(txtfile);

txtDirectoryPath.Text = dlgDirBrowser.SelectedPath;

string directoryPath = txtDirectoryPath.Text;

DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);

TraverseFolder(directoryInfo);

}

catch

{

MessageBox.Show("Directory path incorrect");

}

finally

{

sw.Close();

txtfile.Close();

MessageBox.Show("Done. File created "+ txtOutputFile.Text);

}

}

public void TraverseFolder(DirectoryInfo directoryInfo)

{

foreach (FileInfo fileInfo in directoryInfo.GetFiles("projectname*.dll"))

{

FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(fileInfo.FullName);

bool finalCheck;

finalCheck = (Assembly.LoadFrom(fileInfo.FullName).GetName().Version.ToString() == txtAssemblyVersion.Text)

&& (fileVersionInfo.ProductVersion == txtProductVersion.Text)

&& (fileVersionInfo.FileDescription == fileVersionInfo.OriginalFilename.Substring(0,fileVersionInfo.OriginalFilename.Length -4))

&& (fileVersionInfo.FileVersion == txtFileVersion.Text)

&& (fileVersionInfo.LegalCopyright == txtLegalCopyright.Text)

&& (fileVersionInfo.CompanyName == txtCompanyName.Text )

&& (fileVersionInfo.InternalName == fileVersionInfo.OriginalFilename)

&& (fileVersionInfo.ProductName == txtProductName.Text);

if (finalCheck == false)

sw.WriteLine(fileInfo.Name + " : Incorrect");

//else

// sw.WriteLine(fileInfo.FullName + " : Correct");

}

DirectoryInfo[] directories = directoryInfo.GetDirectories();

foreach(DirectoryInfo newDir in directories)

{

sw.WriteLine(" ");

sw.WriteLine("Directory: " + newDir.FullName);

TraverseFolder(newDir); // recursive call

}

}

Managing remote connections without tsadmin

Most of those who have worked on remote terminals using the Remote Desktop Connection utility would have faced the problem of not being able to connect because of disconnected session. The solution usually is to use the tsadmin utility to close the sessions. However, while working on a Windows XP, this is not available.

However, Windows XP does provide the following to perform this action
- qwinsta (Query Windows Station)
qwinsta /server:servername allows the user to view the sessions and obtain the session ids on a remote windows host
- rwinsta (Reset Windows Station)
rwinsta sessionid /server:servername