Sunday, November 09, 2008

Webcasts on Oslo, WCF, WF (.net 4.0) & Dublin


Just found these 2 webcasts by Alan Smith reviewing some of the recent bits provided from PDC 08 :

Enjoy Learning !!!

Wednesday, October 01, 2008

Simple Introduction to Extensible Applications with the Managed Extensions Framework

Here is a excellent post from Brad Abrams explaining the Managed Extensions Framework (MEF)

“The Managed Extensibility Framework (MEF) is a new library in .NET that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed.”
Simple Introduction to Extensible Applications with the Managed Extensions Framework

Monday, September 29, 2008

Run a Server Side Code and Open a Popup Window onClick of a Link in Asp.net


There are 3 ways we can achieve this :

1) Create a LinkButton and add both client side as well as server side onclick event handlers :

<LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click>LinkButton <asp:LinkButton>

protected override void OnLoad(EventArgs e)
{
LinkButton1.Attributes.Add("onclick", "window.open('test.aspx');");
}

protected void LinkButton1_Click(object sender, EventArgs e)
{
//Server side code here
}

(Problem : Both the events occur simultaneously so if we have a scenario wherein we want the popup to open after the server side code is executed, this isn’t useful)

2) Render the script using Response.Write :

protected void LinkButton1_Click(object sender, EventArgs e)
{
//Server side code here

Response.Write("&lt;script&gt;");

Response.Write("window.open('test.aspx','_blank')");

Response.Write("&lt;/script&gt;");
}

(Problem : In some browsers the CSS of the background window gets affected with this solution)


3) Use the Page.ClientScript.RegisterClientScriptBlock method :

protected void LinkButton1_Click(object sender, EventArgs e)
{
//Server side code

string _url = "test.aspx";

this.Page.ClientScript.RegisterClientScriptBlock(
this.GetType(),
"openNewWindow", "window.open(\"" + _url + "\");",
true);
}

The 3rd one is the most efficient way in my view.

Wednesday, September 03, 2008

Whoa! Google Chrome has crashed. Restart Now ?

Google Crome

This was the first message I got after installing google’s new browser Google Chrome . . . :-)

But since then its working like a charm. . . . . Here are some of the features I like the most :

Thumnail view of the ‘Most Visited’ sites when you first open the browser

Google Crome Most Visited

Opening ‘incognito window’ for private browing (seems similar to IE-8 privacy feature )

Google Crome incognito window

‘Inspect Element’ to see the HTML source code of that element along with the DOM

Inspect Element

Inspector Window

John and Rory have also posted some performance and memory usage benchmarks compared to IE7 here and here.

Monday, September 01, 2008

A Paragraph that explains LIFE . . . .


Recently I got this email from one of my friend which really inspired me and gave a different vision of looking at life . . . . .



Arthur Ashe, the legendary Wimbledon player was dying of AIDS which he got due to infected blood he received during a heart surgery in 1983.

From world over, he received letters from his fans, one of which conveyed: "Why does GOD have to select you for such a bad disease"?

To this Arthur Ashe replied:

"The world over -- 50 million children start playing tennis, 5 million learn to play tennis,
500,000 learn professional tennis, 50,000 come to the circuit, 5000 reach the grand slam,
50 reach Wimbledon, 4 to semi final, 2 to the finals,
when I was holding a cup I never asked GOD 'Why me?'.
And today in pain I should not be asking GOD 'Why me?' "



Happiness keeps you Sweet,

Trials keep you Strong,

Sorrow keeps you Human,

Failure keeps you humble and Success keeps you glowing, but only

Faith & Attitude Keeps you going....

Wednesday, August 27, 2008

WoW64 (Insights from ‘CLR via C#’)

I am currenly reading ‘CLR via C#’ by Jeffrey Richter and would be posting some insights from it as I read along.
Windows 32-bit on Windows 64-bit (WoW64) is an emulation layer that enables 32-bit Windows applications to run seamlessly on 64-bit Windows platforms. Microsoft provides WoW64 to ease the burden of migrating to 64-bit platforms for application developers and to help encourage the adoption of 64-bit computing.”
You can also find the Best Practices Whitepaper for WOW64 which has been recently updated for Windows Vista.
Note: I would hightly recommend every .net developer to read this book at least once.

Monday, August 04, 2008

Interacting between JavaScript and Silverlight 2 functions

How to call a JavaScript function from SilverLight ?

The simplest way which I found is by calling the Invoke method of the HtmlWindow class using the HtmlPage object.

1

As you can see the method take 2 arguments, first being the name of the function and second is the object array for parameters. HtmlPage class is available under System.Windows.Browser namespace.

How to call a SilverLight function from JavaScript ?

Lets take a simple scenario that we need a string trimming functionality on the client side. Since the Silverlight library already has this functionality buildin, we would try to reuse it by exposing a method from Silverlight and calling it from JavaScript.

I have created a separate class for the function to make is easy.

2

The function which we need to access from the client side should be marked with the [ScriptableMember] attribute.


The next step is to register the scriptable objects when the application is started.

3

The Application_Startup event can be found in the App.xaml file. The RegisterScriptableObject inturn calls the :
NativeHost.Current.RuntimeHost.RegisterScriptableObject & NativeHost.Current.BrowserService.ReleaseObject methods for the interop.

Now to access this registered object we need to handle the OnPluginLoaded event and get the reference of the entire silverlight control first.

4

5

Now we can use the silverLightControl object and access the registered methods like this :

6

Does this mean that a Silverlight control could access any of your client side code on the hosting page ?

No, we can disable the silverlight to access any of the html/client side content by setting the HtmlAccess property as below:

7

The default is set to “Enabled”.

Learning is Inevitable !!!

Wednesday, July 30, 2008

ASP.net Performance tuning

Excellent list of 25 Resources for Tuning Your .NET Application Performance ” :

http://effectize.com/23-resources-tuning-your-net-application-performance

One that I liked the most from the list is -

- Speed Up Your Site! 8 ASP.NET Performance Tips (By Jeff Atwood and Jon Galloway )

It covers many interesting topics like :

  • Tracing
  • Compressing the ViewState
  • Storing the ViewState on Server
  • HTTP Compression
  • OutputCache & SQL Cache Dependency etc

Learning is Inevitable . . . .

Sunday, July 27, 2008

using ValidatorHookupControlID() and ValidatorTrim() functions in asp.net Validators

Scenario
Lets imagine a scenario where we have 2 input boxes and we need to validate that atleast 1 of them should contain some value.

image

Solution
Asp.net CustomValidator comes handy here. Here is the code which would help us validate this simple scenario:

image

All works fine except that the validation occurs on the server side. What if we also want this validation from the client side ?

Its simple, create a client side function to validate the same scenario and specify the name of that function in the ‘ClientValidationFunction’ property of the CustomValidator.

image
<asp:CustomValidator ID="validateAddress" runat="server"
ErrorMessage="Please enter atleast 1 Address"
ClientValidationFunction="validateAtLeastOneAddressHasData"
OnServerValidate="validateAddress_ServerValidate1">
</asp:CustomValidator>

This enables the client side validation but there are still 2 issues with the above code :
1) There is no trimming happening in the client side validation code
2) The client side validation is fired only on the button click event.

For trimming there is a function provided by the asp.net validation scripts named ‘ValidatorTrim’ which is kind of hidden and only available once you start the page. This is how we can use it :

textBox1Value = ValidatorTrim(textBox1Value);
textBox2Value = ValidatorTrim(textBox2Value);

Now for the second issue, ideally the client side validation script should be fired on the onblur() event of any of the textboxes. To do that we would have to hookup the textboxes with the CustomValidator.

Hooking the first textbox is simple. Just specify it in the ControlToValidate property and set the ‘ValidateEmptyText’ property of the CustomValidator to true.

<asp:CustomValidator ID="validateAddress" runat="server"
ErrorMessage="Please enter atleast 1 Address"
ClientValidationFunction="validateAtLeastOneAddressHasData"
OnServerValidate="validateAddress_ServerValidate1"
ControlToValidate="txtAddress1"
ValidateEmptyText="True" >
</asp:CustomValidator>

For hooking the second textbox we would have to use a startup script function 'ValidatorHookupControlID as below :

<script type="text/javascript">

ValidatorHookupControlID ( '<% = txtAddress2.ClientID %>',
document.getElementById('<% =validateAddress.ClientID %>')
);
</script>

Wednesday, July 23, 2008

Excellent Whitepaper on : ‘Tools of Agility’

Recently I came across this brief but excellent whitepaper written by Kent Back on Tools of Agility.

I found these two diagrams from the whitepaper very interesting as they clearly explain,
- how the process flow differs in agile practise
- how the different tools are interwoven and support the agile practice


Waterfall

image

Agile

image


Tools to support Agility

image

Learning is Inevitable ! ! !

Tuesday, July 22, 2008

‘Foundations of Programming’ – Karl Seguin


Before few weeks Karl Seguin released an excellent free ebook titled 'Foundations of Programming' which covered many interesting topics focused more around design and coding fundamentals rather than API and framework details like :
- Design Principles
- Domain Driven Design
- Dependency Injection
- ORM's
- Why Unit Testing & Mocking ?
and some really interesting 'Back to Basics' stuff.
And now he also released the 'Foundations of Programming - Learning Application'.

Worth reading material for all . . . .

Thursday, July 17, 2008

Back to Basics - Page_Load & OnPreRender events with nested Web Controls

While working on some refactorings in my recent project I came across a piece of what I would like to call ‘ignorant code’*.

I have tried to get the gist of the scenario with the below diagram :


scenario


Its a pretty basic scenario where we have multiple web controls clubbed together in a single control. (Although I not a huge fan of nested web controls)

What’s important to consider here is the use of Page_Load and OnPreRender events in the Parent and Child web controls.

Probably we all know that Page_Load always occurs before the OnPreRender but the OnPreRender only occurs if the ‘Visible’ property of the web control is set to true.

So in the above scenario although the controls were made visible according to the page, the Page_Load event of all the 7 sub web controls was called everytime. The solution to this is to simply move the hefty code from Page_Load to the OnPreRender event. As the rendering would only occur if the control is visible it would only execute the hefty code on the relevant pages.

*ignorant Code : No code is crap code or bad code its just that we do not know a better way to do it at that point of time

Tuesday, July 15, 2008

Private & Public behaviours with Explicit interface member implementations


Have a look at the below code :

InterfaceCode

Here we are using the Explicit interface member implementation to differentiate the methods.

Now if we try to access these methods from an instance variable. . .

privateIntellense

We can’t !!! Because there is no access modifier specified in the implementation and hence the methods are treated as ‘private’.

So we try specifying the ‘public’ access modifier for these methods but that too generates a compiler error in visual studio !!!

So then how do we actually use any of those methods . . . .

privateIntellenseDone

So what’s confusing here is that although the methods were private they are behaving like public.

ilcode

Finally I managed to find the answer to this behaviour. . . .

Here is a good explanation of this and how the IL code for implicit & explicit Interface Contracts.

Thursday, June 12, 2008

Debugging Assemblies in 'GAC'


Visual Studio requires the program database (.pdb) files to find the debugging information of any assembly. Now to debug assemblies in GAC we can either :
- Create a symbol server and put all the pdb files there and configure visual studio to use it.
- Or else we can copy the .pdb files to the global assemble cache folder.
Now the c:\windows\assembly folder is not the real folder where the files are stored, it is just a virtual folder. To get to the real folder, we need to do the following:
Click: Start -> Run
Type: %systemroot%\assembly\gac [ENTER]
This will open the real GAC folder where the files are saved. Now go 1 level up :
assemblyfolder

Go inside the folder [GAC_MSIL]. Find the folder [assembly Name] \ [assembly version in format of #.#.#.#]__[assembly public key token].
Open the folder and you would be able to see your assembly. Now copy the PDB file to that folder and then attach the debugger and enjoy debugging . . . !!

Tuesday, June 03, 2008

A-Z Guide to being an Architect

While reading the Architecture Journal I came across this excellent list of skills from A-Z which really depicts that architecture is as much about softer skills—good judgment, balance, and other wisdom—as it is about understanding the broad technical landscape, or the skills required to design and implement an architecture.

I have compiled this table to stick it on my desk This would constantly remind me 'where I can imporve myself' . . .

architect

Monday, June 02, 2008

Microsoft's Source Analysis Tool for C#

Microsoft released a Source Analysis tool for C# last friday. It is released under Ms-PL License and can be found at MSDN Code Gallery (Source Analysis 4.2)

Source Analysis covers around 200 best practises and rules around code formatting including line spacing, placement of brackets, file and method headers for documentation and many more. This blog covers more details and future plans for this tool.

One of the rule which draw my interest and made me 'google' around is the 'using' directive ordering rule:

source1

I haven't heard many people recommending this as a good practise and hence I started searching around, trying to find when this rule could be useful.

On my search I came across this interesting blog post by Eric Lippert. The comments in this post also has couple of scenarious when this could be used.

Monday, April 21, 2008

Languages & Runtimes


One of the points on my TODO list is exploring few things around Languages and Runtimes. As a part of it I am going to play around with IronPython for the next few days and would keep on posting any interesting stuff.
I am using the Ben Hall's Getting Started with IronPython to start this adventure

Monday, January 07, 2008

My Company Blog

Please tune in here for my adventures :

http://blogs.conchango.com/jomitvaghela/

Wednesday, June 21, 2006

The Companies have redefined themselves as

1. INFOSYS: Inferior Offline Systems
2. WIPRO: Weak Input, Poor & Rubbish Output
3. HCL: Hidden Costs & Losses
4. TCS: Totally Confusing Solutions
5. C-DOT: Coffee During Office Timings
6. HUGHES: Highly Useless Graduates Hired for Eating and Sleeping
7. BAAN: Beggars Association And Nerds
8. IBM: Implicitly Boring Machines
9. SATYAM: Sad And Tired Yelling Away Madly
10. PARAM: Puzzled And Ridiculous Array of Microprocessors
11. HP: Hen Pecked
12. AT & T: All Troubles & Terrible
13. CMC: Coffee, Meals and Comfort
14. DEC: Drifting and Exhausted Computers
15. BFL: Brainwash First and Let them go
16. DELL: Deplorable Equipment and Lack Luster
17. TISL: Totally Inconsistent Systems Limited
18. PSI: Peculiar Symptoms of India
19. PCL: Poor Computers Limited
20. SPARC: Simply Poor And Redundant Computers
21. SUN: Surely Useless Novelties
22. CRAY: Cry Repeatedly After An Year
23. TUL: Troubles Un Limited
24 CTS: Coffee Tea and Snacks
25. ICIM: Impossible Computers In Maintenance
26. BPL: Below Poverty Line
27. NIIT: Not Interested in IT
FINALLY
ICICI : Incredible Calls from Irate Customers of India

Friday, June 16, 2006

AddIn