Archive

Archive for July, 2009

Internet Explorer 8 ViewSouce Viewer

July 30, 2009 Leave a comment

When you hit the “View Source” command in IE, it opens in a refreshing viewer. I mentioned viewer because you are not allowed to edit :) .  Previous version used the notepad as an editor. If you still want to use the notepad as the default editor then press F12 to open developer tools Click File-> Customize Internet Explorer View Source –> select – Notepad. And one more thing to be mentioned – Developer tools Fantastic.

IE8ViewSource

Here is the developer tool screenshot:

image

Check out the Menu Items to know what you can do with this handy tool bundled with IE8.

 

Cheers!

Silverlight: What is inside a .xap?

July 24, 2009 Leave a comment

Start a new silverlight application(File->New Project-> Silverlight Application), ensure “Host the Silverlight application in a new website” is checked. Now for time being just build the solution. After the build completion look for a file with.xap extension inside the “ClientBin” folder.
Ever wondered wat iteez? No – then here iteez: .xap is a package file and it is nothing but a compressed form of your silverlight dlls, which will be extracted at the runtime from the browser. So did that mean it is some form of .zip? Yeah – just rename the file’s extension to .zip and you should be able to extract it and see whats inside. Do let me know whats inside. iteezzzz ;)

Cheers!

Categories: Silverlight Tags:

Understanding Dependency Property

July 23, 2009 Leave a comment

Everyone who get introduced to Windows Presentation Foundation(WPF) are familiar with this term. But lot many get confused on it or never get what it is. I will try and make this post very simple so that it is easier to understand. My intentions are not to provide the complete technical stuff behind the Dependency property, but to keep things simple to understand and to get started. You should probably work on this lot many times to understand it better.

If you are not new to .net or any other OOP language, you are not new to Property. Dependency property was introduced in .net 3.0 and it is all together new implementation of normal properties. Dependency property differ in terms of its storage mechanism, it uses Sparse Storage and its implementation saves per-instance memory compared to a typical .NET property. However benefits of dependency property is more than just storage. One of the significances of Dependency property is its support for notification change – that means any change in the value of the property is notified down the element tree in WPF. This point particularly becomes very important to understand this.

Before I completely get on with Dependency property, let me give a gist of what attached property is. Let me explain this in a way a lay man understands: Consider a “<Canvas></Canvas>” element in your XAML. Now if you want to add a child element “<TextBlock>” to it, how do you place them in the canvas? – Here it is:

<Canvas>
       <TextBlock Canvas.Top=”100″ Canvas.Left=”100″ Text=”Hello World”/>
</Canvas>

OR an example with a Grid

<Grid>
   <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition/>
   </Grid.ColumnDefinitions>
   <Grid.RowDefinitions>
      
<RowDefinition/>
      
<RowDefinition/>
   </Grid.RowDefinitions>
  
<TextBlock Grid.Column=”0″ Grid.Row=”0″ Text=”Hello World  1″/>
  
<TextBlock Grid.Column=”1″ Grid.Row=”0″ Text=”Hello World 2″/>
  
<TextBlock Grid.Column=”0″ Grid.Row=”1″ Text=”Hello World 3″/>
  
<TextBlock Grid.Column=”1″ Grid.Row=”1″ Text=”Hello World 4″/> 
 
</Grid>

So what we do is we set the Canvas’s Top and Left property in the TextBlock child element or even the Grid’s Column and Row property in the child elements. This is achieved using attached property.

So here is the MSDN explanation: “An attached property is intended to be used as a type of global property that is settable on any object. One purpose of an attached property is to allow different child elements to specify unique values for a property that is actually defined in a parent element.”

In the above example, we see the property element of a parent is changed by the child, and the same gets reflected throughout the child elements. I have explained this so that you don’t confuse attached property with dependency property.

Let us extend couple of lines of code more and now understand dependency property.

And here it is:

<Canvas>
<Slider Canvas.Top=”10″ Canvas.Left=”10″ Name=”MySlider” Minimum=”10″ Maximum=”1000″ Ticks=”100″ Width=”300″/>
 <Ellipse Canvas.Top=”130″ Canvas.Left=”150″ Width=”{Binding ElementName=MySlider, Path=Value}” Height=”{Binding ElementName=MySlider, Path=Value}” Fill=”Red”/>
 </Canvas>

The output of the above example is: When the slider is moved, automatically the ellipse gets larger or smaller based on the value of the slider. So what we understand from this is without writing event handlers or any code behind to handle the slider movement and the ellipse height and width setters – we achieve this. This is because the property “Value” of the slider is a dependency property and it notifies the change to all the elements in the XAML, and since the Ellipse’s width and height are bound to the “Slider.Value” it automatically reflects the change.

This was just an introduction, there are couple of more things I want to cover like – creating your own dependency properties for the custom controls etc, which will be updated in the next post.

Cheers!

Silverlight for the Newbie!

July 21, 2009 Leave a comment

It is been really long I have worked on Web development – close to 2 years and I really miss every bit of it. I have moved on to a world where it is just business logic. Though this is more challenging – as it involves developing performance efficient and highly object oriented codes, I still miss the art of developing rich User Experience(UX).  Words “Ajax”,”Silverlight” and few others revolve around me every night, as I take lot of time reading about them and mostly few minutes before my nap. And hence I started to explore myself. Since I had worked on Asp.net Ajax and WPF before, it was not that difficult for me to understand. The intention of this post is to help the newbie get started with the Microsoft’s Magic Web Wand called Silverlight – “Light up the Web!”.

What is Silverlight?

When the internet was born, it was primarily used for sharing static content over the network with the help of a simple web browser. But things have changed over a period of time. Internet moved on from static content –to- dynamic content –to- rich user experience. Let it be shopping online, social networking, banking or any other web activities, user demands a rich Experience. And thus the Silverlight. Silverlight is a client runtime which provides rich user experience. It runs on user’s browser with limited capabilities on the user’s system resources. It is a free downloadable one time installer. It supports all the latest browsers like IE, Mozilla, Safari etc on Windows, Mac, and Linux platforms.

Let us tackle couple of questions to understand better:

  1. Why Silverlight?
    Think about developing a website for a multimedia company/ad-agency where you need to show a gist of their actual work, do you think their clients at their web page expect to see some static content and get impressed of their work? Of course no, they want to see things more lively. Now think of developing a dynamic web page, which should create less load on the server, perform better on the client, show animations, stream videos, etc. I am sure this is not an impossible task, with Javascript and any server side code this is very much possible. But think of the time it takes to develop one. One more important thing which comes to your mind the moment you think about Javascript is browser and platform compatibility. Think of writing “If-else” statements over and again. Silverlight solves all these problems. You don’t have to worry about the client platform or the browser, you don’t have to think of including different players for the video streaming, and most importantly you don’t need to know javascript. All you need to know is simple C# and XAML and you are good to light up the web.
  2. How is it different from Ajax?
    Imagine the lines of code you need to write in Ajax to make an animation, stream media, etc. Since Silverlight uses WPF’s Subset UI programming, you can use the markup language XAML to do things for you. At user point of view Silverlight only differs from the point of execution – Silverlight uses the runtime to execute whereas a Ajax executes inside the web browser. Both the technologies are given equal prominence by Microsoft. With all of these technologies in place we are closely bridging the gap between a web application and a stand alone desktop application.
  3. Why should one not use Flash instead of Silverlight?
    The answer is pretty simple – Do you want to learn flash, or depend on a flash programmer to finish your application? Or simply add few more lines of code in XAML and C# – you may land up doing things better than a designer.

Versions of Silverlight(Release):

  • Silverlight 1.0
  • Silverlight 2.0
  • Silverlight 3.0

Prerequisites for development:

  1. Make sure you have .net 3.5 SP1 and above
  2. If you are using Visual Studio 2008 (any edition) – make sure you have VS 2008 SP1 installed.
  3. Install the Visual Studio tools for  Microsoft Silverlight 3 and SDK

In this post I have limited to the introduction in simple terms.

More posts to come on Silverlight architecture, CLR usage, WPF Subset UI usage etc.

Cheers!

Categories: Silverlight Tags:

XMLPreprocess Getting Started

July 19, 2009 Leave a comment

XMLPreprocess is a simple command line utility that can be used to deploy config files to multiple environments without having to maintain multiple copies. It can be used as a custom action in your MSI to transform the files as they are being deployed to different environments.

The goal of this tool was to minimize the maintenance of multiple configuration files for deployment and I should say it neatly meets the goal.  To understand it better – a single config file can be written and maintained as the source of truth, and it can be decorated with non-breaking comments that contain the instructions for the preprocessor.

Example:

<configuration>
<system.web>
 <!-- ifdef ${production} -->
 <!-- <compilation defaultLanguage="c#" debug="false"/> -->
 <!-- else -->
 <compilation defaultLanguage="c#" debug="true"/>
 <!-- endif -->
 </system.web>
</configuration>

Look carefully at the comments part of the above snippet. You can easily understand that we are trying to turn off the debug page compilation when in production. 

Now that is about the introduction, moving on to the actuals:

First thing first: Download the XMLPreproces from CodePlex, and extract the zip.

For this example, I will be using the spreadsheet(XML Spreadsheet 2003) as the storage of the environment specific variables. However you can also store it in a normal xml file.

I am using the sample files which came along with the download. I copied the sample.config and the SettingsSpreadSheet.xml into my xmpreprocess bin folder – I just did this to make the demo simpler – You can always provide the path for processing.

My folder looks like:

xmlprep1

Open the SettingsSpreadsheet.xml

xmlprep3

The columns represent the different environments you are targeting, and the values in the rows of Column A are the variables you will use in the config file. While preprocessing, the values of the variables are replaced with the corresponding value stored in the environment column.

For e.g. Let us say I want to generate a config file for testing environment, then I store the variable ServiceLocation in the column A, and then I provide the corresponding value in the column of “Test” – now when preprocessed “${ServiceLocation}” in the config file will be replaced with the corresponding value in the xml file.

Open the sample.config file;

xmlprep2

Look at the value in the comments section “${ServiceLocation}” – as mentioned above you should add this to the variable in the settings files – just add “ServiceLocation” (dollar and braces are not required in the settings file), and provide different values for different environments.

Now use this command to preprocess:

“XmlPreprocess.exe /v /q /nologo /i sample.config /x SettingsSpreadsheet.xml /e Test /o Processed.config /d test ”

Once you run the above command, it generates another config file named Processed.config and you will have the value ”testserver” instead of localhost, in the new config file.

Now think of adding this to your WIX setup, or calling the bat file with the preprocessing info as part of build scripts. This will reduce the work of maintaining different config files for different environments.

This tool is really simple to understand, and when used efficiently gets rid of maintenance problems.

Few other resources which may help:

Loren’s Blog

Scott Hanselman’s Blog

Cheers!

Categories: Deployment, XMLPreprocess

Windows Azure Commercial Pricing Announced

July 14, 2009 Leave a comment

Today Microsoft officially announced the business and partner model for the Windows Azure platform including service level agreements and support programs.

And here is the link.  Also at here.

This part of the blog is really interesting:

“Windows Azure compute hours are charged only for when your application is deployed so while developing and testing your application you may want to remove the compute instances that are not being used to minimize compute hour billing”

Cheers!

Categories: Windows Azure

LogParser 2.2 – First Look

July 12, 2009 6 comments

Recently I got introduced to a tool called LogParser while working on a critical enterprise application. It is used to extract information from the log files as easily as querying a SQL database. Guys working in enterprise applications know how important is to log a particular event, and maintain it for a period of time – it contains information deemed crucial to a business. Logs help the admin guys to troubleshoot an issue on a production box as well as for developers when the debugging is not used – mostly when the app is running on the test environment. But some times it is a nightmare to even look at the logs specially if they are on flat files and trace out the information what you really need. Log files are mostly very large in size and almost impossible to find a meaningful information out of it. LogParser bridges this gap by providing a SQL like querying ability. LogParser allows user to treat log files as just another SQL table, the rows of which can be queried, and formatted as per the users choice.

LogParser helps filter the log entries matching specific criteria and to sort the resulting entries according to values of specific files. Log parser consists of three components, which are: 1) Input processor, 2) SQL query parser, and 3) Output processor. Log parser can accept any common log format and output it into one of many formats.  When you are done, you can combine all your separate logs into one common format for analysis.

Ok now lets get started. First thing to do is download the LogParser 2.2, and install it on your machine where you want to process the log files. Next run the log parser from you program files to execute the samples provided here.

Look at this sample Query: logparser.exe -i:EVT -o:NAT “SELECT TimeGenerated, EventID FROM System”

And here is the output:

output

Now the first part of the query : –i:EVT is processed by the input processor, –o:NAT is processed by the output process and the rest is the SQL Query processed by the SQL parser. In the above SQL Query you may see the fields like TimeGenerated, EventID – to know how exactly we can get to know these fields,  try commanding with a help attribute (-h).

Query example: LogParser -h -i:EVT

And here is the output:

help

- i:EVT , the parameter “EVT” is used to query the System Event Log.

-o:NAT, the parameter “NAT” is used to output to a readable and nicely formatted text to the Console Window.

In the select query you can also use the “where”, “order by”, and “group by” clauses to narrow down your result output.

To output to a text file use the SQL Query with “INTO”. For e.g. logparser.exe -i:EVT -o:NAT “SELECT TimeGenerated, EventID  INTO C:\out.txt FROM System” You can also write the output to a CSV file – just replace .txt to .csv. You can also output to a  datagrid, use –o:datagrid.

So that was little of basics, and now let us look at a scenario, where we need to query a text log file and output to another format based on certain criteria. Now the very basic question people have is - why should they use the logparser if the intention was to extract information from one file and put it to another. To answer this think of a situation, where your log file is of size 10mb or more and it is on a server located at the other side of the globe.

Look at this query which partially addresses this problem:

LogParser ” SELECT INDEX,TEXT INTO C:\out.CSV FROM \\server\app\logs\runningTrace.log WHERE TEXT LIKE ‘%@@Start%’OR TEXT LIKE ‘%@@End%’ OR TEXT LIKE ‘%TimeStamp%’ ORDER BY INDEX  ASC” -i:TEXTLINE  -o:CSV

The log file which is queried upon almost looks like this:

Timestamp: 7/7/2009 11:12:30 AM
Trace Msg: 
MethodName : abc.HelloWorld
TraceMessage : ——————– Processing abc.HelloWorld() ——————–

***************
Some text logged here
***************
@@Start: CriticalMethod.Processing.Started at 11:12:30:5625000

*****************
Some text Logged here

*****************
@@End: CriticalMethod.Processing.Ended at 11:12:30:6875000

————————————————————————–

Now the situation was to calculate the time taken by the method for various scenarios. And this had to be noticed for a weeks time. Think of the size of the file it would have generated for a week and now going through and analyzing them would have been a real pain. The above query provides a narrow result which can be easily analyzed by just looking at it or by an application(user-written) which can be used to read this output.

The query used here is just a sample, the actual query we use is more complicated and more powerful (think of a complicated SQL query which gives a base result). I was just amazed to see this app addressing the issue of looking into the logs, and I posted this so that it should be of help to someone. Do let me know how this has helped you guys, and do share if you come across some interesting issues.

Here is the book I found on Google. Should help.
And this one too is too good. Click Here
Cheers!

Categories: Logging, LogParser

Windows 7 on VMWare

July 1, 2009 3 comments

I returned back from the tech-ed event with lot many TODOs, and the top most priority being exploring Windows 7. The very first thing to do was to Download Windows 7 RC and decide on the installation. Currently my machine(Toshiba m70 Laptop with Intel Centrino 1.7Ghz, 1.2Gb of Ram, Intel 915 mobile graphics and 60Gb HDD) runs a Windows XP which was pre-installed by the vendor. I never upgraded to Windows Vista, though lot many times I tried convincing myself for. After reading couple of news, articles, blogs on the problems with Vista it was too risky for me to take a call. I decided to stick to XP, as I was very comfortable and a need for an upgrade was never there. But VJ and Vic’s session on Windows 7 was an eye opener for me, and I still cant forget the statement on running Windows 7 on a 700 Mhz cpu. I thought I should really give this a try, and see what worst is kept for me, with the marriage of my old grandpa machine and the beautiful princess Windows 7. :) After a series of permutation and combination in my brain (the math on risk vs beauty) I decided not to try and Install as a parallel boot, rather go with another new concept which is installing it virtually. I downloaded the VMware WorkStation, and installed it on my machine to test drive the princess in a far more secured(from the grandpa) platform. I really doubted whether VM could detect the Windows 7 and to my surprise it detected as Windows Vista. I thought to go with it and see what happens, after all it is the Vista which is underneath.

Here are the few steps which may be helpful to you guys if you want to go with VMWare.

Win-7-Installation Click on the File-> New Virtual Machine to get this screen and select Typical. Click Next2 

Select the Iso image(Win 7 image file) and you can see that – “Windows Vista Detected”. Now Click next

 3 4  4_15

Provide the Windows Key which you would have generated before the Windows Download. Also provide the disk space as per your requriement in the following forms. Inthe virtual machine name provide windows 7 or so. Follow the rest of the instructions and click finish.

 

You are done from the VMware side, now it will boot your Windows 7 setups, follow the instructions until complete. And that is it! So finally i had the Windows 7 in my laptop.

A simple note: Aero Expereince was disabled for me, since I did not have the graphic driver with WDDM support, and also VMware had defaulted my graphic driver to a VMware SVGA II. So guys if this feature is a must for you, then have a check on your graphic driver. If not just be happy with the basic display and trust me it is really smooth and fast.

My experience so far is really cool, I think this will be the next long lasting OS from MS after Windows XP.

More insights coming soon :)

Cheers!

Categories: VMWare, Windows 7
Follow

Get every new post delivered to your Inbox.