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.

Sunday, March 25, 2007

Atlas: Assertion Failed: Could not find an HTML element with ID “ContentView_PageLayout_xxxx_xxxx” for control of type “Sys.UI.Control”

This is a common error in atlas when you put a atlas updateProgress inside a panel with panel.visible = false. Toggling panel is a common task when you create a wizard like application. Therefore, in order to make it happen, all is needed is to put a dummy reference to the updateprogress control's clientId.

Which looks something like...

<asp:Panel id="dummyControlPanel">
<div id=ctl00_SomePage_controlName" />
</asp:Panel/>

Now, with the script manager's partial rendering set to true, atlas framework wont complain about that anymore, but before turning on the actual panel that holds the progress panel, you have to set dummyControlPanel.Visible= false, so that altas framework does not get confused in initializing control with duplicate Id.

Friday, March 16, 2007

WINFS (Windows Future Storage)

Highly anticipated WINFS is not shipped with Windows Vista RTM, It is still under development, from some blogs i found out that it will be released with an update

May be with SP1 :-)

Tuesday, March 13, 2007

Javascript and Google Searchbot

Let's say you have made an online document management software, which is built with ajax flavor. No matter , how well is your app, it can turn out to be worthless, if people cant discover the right doc through their search keys that your app is supposed to give.

Yesterday , i have found a tiny research work of a guy, who proved it right that contents generated by javascript can never be indexed by a search engine (ex. Google).

As we all know search engines cant never execute javascript.Therefore,the growing number of ajax apps could lead goggle to think in different way for their search algorithm or it just don't matter.

Read it out..
does-google-index-dynamic-javascripted-content


A Reader's Toolbox

Many companies using Google standards for business internet marketing online for better reach of customers. For successful business you do not need only cheap domain name. In many countries free wireless internet is used boosting up servers for fast communication. You can see in many webhosting reviews use of internet booster is recommended for better speed. Especially for site hosting because to increase your website traffic your site should take less time to download. Many people use data recovery programs if they lost their data but if you keep you use pc backup then you can get

Friday, March 9, 2007

My Vista experience

I was planning to install vista in my hp core duo laptop , since its beta release , but in blogs and forums was said by most people, the OS is not yet ready, made me think twice. Until, after the Jan 30 world wide release , I finally decided to try it on my own.

Therefore, one fine morning, I bought a Vista Business Edition DVD. I wanted to do a clean installation. I backed up everything and boot the pc with Vista DVD. I was really astonished to see the great improvement of installation process of windows, the installation UI is far advanced and it not only safely removed my existing Windows XP to a separte windows.old folder with settings and documents , but also detected all my hardware(note: my laptop is vista capable) with no pain.

After installation , my network card is behaving normally, I have successfully installed VS 2005 and SQL Server 2005 , although i have to install SQL server SP2 and VS SP1, though it was not required but recommended.

The Aero is working fine, I really liked 3D menu switching feature, and the new ready boost feature (you can use a flash drive as system memory) of vista really rocks.

I will keep you posted with more in coming days....

A Reader's Toolbox

With latest modification of vista customers are experiencing new options for webhosting. There is lots of internet phone provider who have started vista hosting for their websites. You can see the vista popularity even webhosting domain companies are using this operating system. This gives a powerful platform for web host using this operating system. There are many business web hosting that are providing same services but to find out real money saving cheap hosting gator is best. There is tough competition among the hosting providers so you can get discounted deals.

Thursday, February 22, 2007

Reading Syndic8 Feeds with Xml-RPC using C#

Recently , i need to query syndic8 database for feeds with some interest. The syndic8 is an excellent source for all types of feeds. This site is caching feeds since 2001 and got richer in content by its graceful users.

Syndic8 lets query in XML-RPC. The web-service section of the site provides all the necessary function informations to get you started. There are also some references of how to write app consuming XML-RPC.As i like to get things done in C#. I found a pretty cool xml-rpc library written completely in C# that enables you to make proxy in WCF(Windows communication foundation) style.I would definitely suggest to give a try. The library could be found at- http://www.xml-rpc.net/.

To get started with this , all it takes an Interface with endpoint defination and some method skeletons.

For example , a sample interface could look something like the following.

[XmlRpcUrl("http://www.syndic8.com/xmlrpc.php")] -- // end point
public interface ISyndic8 : IXmlRpcProxy
{
[XmlRpcMethod("syndic8.GetAllFeedTags")] -- function signature in sydnic8
string[] GetAllTags();

[XmlRpcMethod("syndic8.FindFeeds")]
int[] FindFeeds(string pattern, string field, int limit, int index);

[XmlRpcMethod("syndic8.GetFeedFields")]
string[] GetFeedFields();

[XmlRpcMethod("syndic8.GetFeedInfo")]
Feed GetFeedInfo(int feedId);

[XmlRpcMethod("syndic8.GetFeedInfo")]
Feed[] GetFeedInfos(int[] feedId);

}

Note, i have also defined a custom struct for holding the syndic8 feed ,which is nothing but a struct filled with properties defined in sydic8 that i have found from their own GetFeedFields routine.

Finally to wrap this up , i just created simple interface reference using the rpc library and the rest is just call and get.

ISyndic8 proxy = (ISyndic8)XmlRpcProxyGen.Create(typeof(Syndic8Test.ISyndic8));
//the proxy will expire after single call, so that you can call multple methods in one instance. Default is true.
proxy.KeepAlive = false;


Hope, this gives a brief overview of sydic8 repo and xml-rpc libray for .net for getting your database filled with feeds in no time.

Sunday, February 18, 2007

Http POST variables from C# to php

In php >= 4(so far i know) , developer can do set-get with POST variables in the following way

HTTP_POST_VARS['flakeIds'] = array('guid1','guid2','guid3');

This means you have array of guids in post vars, which has a element id named "flakeIds".Now, let's say someone gives you a php link that takes array of items, which you need to send from your C# code as confirmation or something like that.

Generally you will do a web request , with method type set to POST. This type of scenario , where it is necessary to pass array items over http POST,you should prepare your query string in the following way..

string params = "flakeids[]=1171722632&flakeids[]=1171723000";

byte [] bytes = System.Text.Encoding.ASCII.GetBytes(params);

Notice , just the same element name terminating with an "[]". Interesting huh.

Happy Coding!

Friday, February 16, 2007

Life at Startup

Though , working in startup is always a fun, with the sheer adrenalin rush and round the clock routine. Still, one should try,only if he is really bored with his life(Please dont try this at home).

In normal job, life is more streamlined. You will go to office at 9 and come at 5 and blah blah... But startups are complete different in that context. It has no fixed time, every day is a new day and every night can just become a nightmare for you when you have gone to bed thinking , what a perfect day it was, and suddenly your boss calls you up telling that your code crashed the server or a piece of text, inside a span tag that works in all browser, does not even show in IE6 :-)

Hey, scared already. Good news is people join at startup, because they want to do something on their own or see a baby grow right in front of their eyes. it is always a fun to see a little company growing bigger or vice-versa.
To be honest, if you like to work and work , join a startup, else go to bed.

Sunday, February 4, 2007

Windows Vista goes live

The worldwide release of Windows Vista , ended up with parties and musics. Anyone , who wish to see how the release looked like, can go to Microsoft's website and hit for the on-demand webcast. It's a pretty nice one, where Bill Gates, gave an overview of how it was like 12 years back , when the release of windows 95 takes the world by storm and how technology has evolved since, with pcs having lesser form factor, easy broadband access and ever growing web 2.0 apps.

Here in Kualalumpur, Malaysia the feel isn't much different. Release event in KL convention center, shows and games in Plaza Low Yat celebrating the release of windows vista were just awesome. Being an early adopter, i was walking around the stores hoping to upgrade from my vista beta to RTM. I saw some stores selling copies which are meant for delivering with newly assembled pcs, but will wait until the original retail copy of "Vista Ultimate" is available :-).

A Reader's Toolbox

There are basically two types of business web hosting one is for windows server and second is for UNIX server. You will find windows cheap hosting as compared to other hosting. Most of hosting companies are offering package sales and providing free web site templates. There are many companies providing webhosting reviews. There are lots of companies that are providing wireless hosting services for their customers. You can easily find web host online so that you can get all information about. The best hosting services are available for you at gator so you can use them.

Tuesday, January 30, 2007

Dan Cohen from My Yahoo joins Pageflakes!

Monday was a great day for Pageflakes, when Dan joined the team.

Before joining Pageflakes, Dan led MyYahoo!, the personalized startpage of Yahoo!. Before that, he worked at Google for Google’s personalized startpage. Prior to joining Google, Dan founded and successfully sold a mobile technology startup. His experience at Google and Yahoo arguably makes Dan the #1 expert on personalized startpages in the world. And we are really happy to have Dan among us.

Thursday, January 18, 2007

Call Stack and Locals can save a lof of time

Few days back , when i was debugging with Visual Studio, i got an "Execute Reader" exception, which happened from a function that calls up a stored procedure that i have modified, the stored procedure has some if-then-else and i need to know the value for which the call failed. So, i clicked on the "Call Stack" tab, went to the function where the actual db operation is held.I clicked on the Locals tab, noted down the possible values that i need to re-check.I went to the stored procedure and revised out the code for each value. Finally, ran the code with fix.

Although,it is simple, but the impact is real big. If there was no Call Stack / Locals then i would have performed a manual debugging, which is no time saver in terms of a huge solution.

What a bless that we don't realize! :-)

Tuesday, January 16, 2007

Accessing Master page variables from user control

Recently , i had a task to generate meta tags depending on the list of items that are shown on each page (Pageflakes Community Gallery). The list is generated using a repeater and it is under a user control. The header tag is in the Master page, inside which i need to generate the meta tags. Within the header tag , i have <%= MetaTag %>, which dumps whatever assigned to it. MetaTag holds the string of meta tags, which is generate from a predefined schema , after doing some content processing.

Now,calling a public method in master page from user control is bit tricky.To call a public variable from a user control , the following line must be copied to the top of user control with appropiate master page location.

<%@ Reference VirtualPath="~/YourPath/youMasterPage.master" %>

This enables to take the reference of the master page codebehind class and access its public variables.

ASP.MysNameSpace_MasterPageClass myMaster = (ASP.MysNameSpace_MasterPageClass)this.Page.Master;

myMaster.MetaTag = GetMetaTag(.....);


This process of accessing public variable though simple, yet very effective way of dynamic inclusion of meta tags, scripts, style tags and even custom title on to the header tag which is under a common master page.

Ping me if you have anything to share with me.

Configuring multiple sites under a common root

When there are several sites under a common root site, For ex, mysite - >mysite/forum - > mysite/blog , where all three are different solutions and each has a separate config file with some common settings. Due to inheritance nature of web.config, the child config gets the attributes of the parent config.

Therefore, if you have the following, both in mysite and mysite/forum without the location tag, then it will surely cause a runtime error ,"Same session cannot be removed twice"

<httpModules>
<remove name="Session"/>
</httpModules>



To solve this, we can use location tag, which is declared right before the system.web tag.

<location path="mysite">
<system.web>
<!-- do things here ->
<system.web>
</location>



By using the location tag, we can ensure that a particular setting will be applied only to mysite, not to mysite/blogs or myiste/forum.

Similarly , we can avoid such scenarios by removing the common blocks in child config, if we dont want to use location tag.

A Reader's Toolbox

Since the advent of affiliate marketing program many companies use to configure multiple sites under common root. It is quite easy for web companies because it provides lot of web space. This option is not available with all hosting providers but you can know this through webhosting reviews. Most of companies are using wireless security for their servers to avoid risks for servers. You should make plans when buying a web name so that you can implement it easily. You can get all information about hosting using phone service. There are many companies that are providing online support for webhosting net.

Tuesday, January 2, 2007

A year of accomplishments in Pageflakes

In Pageflakes we almost work day and night to make great a startup that will work for all type of users, it was kinda busy year for all of us here. Throughout the year Pageflakes has gone through massive development.Plenty of good flakes, community, new look , better and improved RSS reader, are few features that kept us awake.Finally, it has been a great experience for being a part of such a wonderful yet talented team that is called Pageflakes.:-)