Friday, April 13, 2007

File merge with Powershell

Powershell, is a great tool for handy scripting. It is often needed that you need to write sql scripts in isolated files. The is good in terms of finding errors in script, and focusing on one part while developing part of the sytem.But , as the number of script files grows big , the deployment issue becomes a headache for the release manager to handle your scripts.

I used to think that the best solution, for merging files, is to use dos copy /xcopy commend, but this often gets screwed up for really big scripts having evernt large srings within.

Though .Net has rich libray for that,it not aways easy to make a console app which i can share with my collegues, therefore i started tiny a powershell that made my life more easier.

The goal of my power shell, i will give source dirercoty , exetenstion(filetype to be included in merge) and optionally a diliminator(for ex. i want to have "GO" keyword at end of each sql file).


Logic:

Get all files for provided extenstion
Read the whole content, and append it in a string builder
Add the diliminator
Finally Combine them to one file.


Code

Param ($source="c:\Test", $extenstion ="*.sql", $outputFile = "outputFile.sql" , $blockTerminator = "GO" )

[System.IO.DirectoryInfo]$directoryInfo = New-Object System.IO.DirectoryInfo($source);
$rgFiles = $directoryInfo.GetFiles($extenstion);

$builder = New-Object System.Text.StringBuilder;

foreach ($fileInfo in $rgFiles)
{
[System.IO.FileStream]$fReader = $fileInfo.OpenRead();

if (-not ($fileInfo -eq $null))
{

write $fileInfo.Name;
$reader = New-Object System.IO.StreamReader($fReader);
$builder.AppendLine($reader.ReadToEnd());
$builder.AppendLine($blockTerminator);
}
}

[System.IO.FileStream]$fWriter = New-Object System.IO.FileStream($outputFile, [System.IO.FileMode]::OpenOrCreate);
$writer = New-Object System.IO.StreamWriter($fWriter);

$writer.Write($builder.ToString());
$writer.Flush();
$writer.Close();



Terminology

Param - This excepts user input from shell, optionally you set default value
All the status methods in .net are called with double "::".
Classes are declared with fully quilifed name
New-Object : use for class declartion , optionally you can use -comObject to declare com objects.


How to use

Copy the code , paste it in a text file , rename it to .ps1 extenstion.
Get the exeution poiicy of your shell enviroment , by default it is Restricted , you can know that from calling Get-ExecutionPolicy command. In this mode you cant run scriptlets. Use Set-ExecutionPolicy RemoteSinged.
Run the script , do add the ".\" sign before your file name.


Example

PS C:\Users\mehfuz> .\FileMerge.ps1 c:\community\ *.sql c:\output\merged.sql GO

A Reader's Toolbox

For web page designers powershell is a useful tool as this can help in good designs. Many internet marketers focus of design of their website because this is one factor that any search engine looks for ranking. There are few things that you should consider in hosting of your website. Whenever you launch any new website, you should go for webhosting review so that you can make right choice. There are many internet companies providing internet phone for setting up your call center and pc backup support for any kind of troubleshooting.

Thursday, April 5, 2007

Configuring Mobile Device in Windows Vista

windows vista does not support Active sync family, rather there is a whole new app called window mobile device center which can be downloaded from

http://www.microsoft.com/windowsmobile


Using widnows mobile device center setting up your windows mobile with windows vista is just couple of clicks away.

Step 1;

After installing windows mobile device center , connect your mobile device to windows vista and it will automatically detect things out for you.

Next you have to make click on the "setup mobile device" option.




Step : 2

Here, the wizard will ask for the mode of connectivity. For single pc mode ,choose the first option.




Step 3:

Choose which items , you generally need to syc. I choose , calender , notes, contacts and files for my need.



Step 4 :

Cofimaration and choosing a friendly name for your device.




Step 5:

You are ready to roll.



Windows mobile device center is much more interactive and user friendly then its predessors, it comes with loads of new features that you must need to check out.

My 02 Xda mini(window mobile 2003 second edition) is working fine with it, so no worry about backward compatibility.

Saturday, March 31, 2007

Configuring IIS for asp.net in windows vista

In Vista , by defualt the windows authentication feature for IIS is checked off. In order to debug or to create web application from vs 2005, you must check this on. This is located under programs and features option in control panel.



Now to enable it, go to IIS manager.In the featured view , go to authenticaton to enable it.



Also,you must also need to turn the asp.net impersonation on.

Finally , in order to be able to load asp.net web projects (which needs the frontpage server extenstion) , you must install the IIS compatibiliy layer under programs and features option(required).

Finally, i have found that those who use skype, they cant possibly turn their IIS to running state and get protocol violation in loading web project. Therefore to avoid that, turn off the port 80 check under connection tab(skype).

Have fun.