Tuesday, February 28, 2006

Road Trip to developing a forum : Goal accomplished

I was really busy since three days to make any update on this blog. I was working on writing a forum board from scracth on, and guys it was too hectic. My good buyer was very cooperative and inspite of having a very tough deadline, he took me with patience. Finally after around 30 hours of coding,testing,evaluation,correcting and what not, i successfully completed the Message Board, say Pre-Release of Message Board. :)) It was written in ASP.NET from scratch, i basically tested it thoroughly with Ms Access Database and later ported to SQL Server DB. This is really cool, cos with just few classnames changed, the code for works for any DB!!! Isnt that good? Ofcourse i did not make use of any Stored Procedures, which i really dont know how to write. Well guys, it was really great experience, and i would say its a dream come true. I implemented Forms Authentication too and beleive me, it is not as tough as it looks in the online articles. Very soon, i would post an article here on my blog or in my upcoming site.

Well apart from this news, we four friends are soon forming a software freelancers team.(names not disclosed :)) ). Well once we get moderate success, we shall think of expanding the unit by adding few more of my taleneted friends. But for now no vacancies :)) Wish us all the best for Embryo Software Services(well i shall change the name in another day, changed the name twice till now)

I dont have moood to talk about .NET technical issue, i am fed up and i worked for around 16 hrs each day since sunday, and it was all .NET, right now i need to relax and start Servlets Programming tomorrow. And dont expect any code segments for the forum board from me, it is the property of my buyer :)) So i cannot disclose any code here. Thanks for visiting. See you later.

Wednesday, February 22, 2006

Good Will Hunting : Tweleve Performance Tips

This is an extract from MSDN article.

Twelve Performance tips
  • Load fewer modules at startup
  • Precompile assemblies using NGen
  • Place strong-named assemblies in the GAC
  • Avoid base address collisions
  • Avoid blocking on the UI thread
  • Perform lazy processing
  • Populate controls more quickly
  • Exercise more control over data binding
  • Reduce repainting
  • Use double buffering
  • Manage memory usage
  • Use reflection wisely
You can read the article at
http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/default.aspx#Tips

Lot of information available in it. Check it out for sure.

Tuesday, February 21, 2006

Fast and Furious:Make .NET apps a hare that wins

The future is all virtual machine based-i mean to say every platform would become more and more managed. But at the cost of performance. C++ is still favorite of many because machine code is directly generated but not any MSIL or a bytecode. This makes the applications very fast to executed. But the managed environments provides developer a lot many comforts for which they are ready to give up performance to some extent. But with recent research in optimized JIT compilers, even Managed applications could be faster(not as much as native code). Well let me not drag the topic - i aint writing any book! I wanted to share some information which could be used to make your applications a bit faster(by applications i mean .NET apps)
  • Firstly, create as many less objects as possible - if your application runs for longer durations. Then also make sure to set the object reference to "nothing"/"null" when you are done while using it.
  • Read FxCop rules and also PMD rules from pmd.sourceforge.net, though PMD is for Java the rules are well applicable to .NET since both of them rely about the same basics of runtime.
  • Make sure that you save unnecessary loops, reducing loops always saves you CPU time. Also read this article on MSDN about performance of .NET applications. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt13.asp
  • One thing is that, avoid Boxing/UnBoxing as much as possible - the lesser the work for CLR for type-casting, better the performance.
Well, these so called tips are almost useless, not many want to learn something extra to improve the performance of their code. Do we??? Well, when using Visual Studio you can improve the performance. Select Project in Solution Explorer, go to project properties, then go to Build Tab. There you can see "Optimize Performance" and "Integer Overflow checks". Check the Optimize Performance and also if you dont wish to perform any integer overflow checks, make that setting too.

There is also a tool called NGen that ships along with .NET SDK. Ngen.exe could be used to generate JIT compiled code and it saves the compiled code in GAC. Make a note that even this compiled code is managed, but when the application whose NGEN code is available in the GAC, JIT is no more functional at runtime- performance improves drastically. The documentation for NGen is really stupid and overly complex. Very soon i shall be working with Ngen and then i would post a simple tutorial on how to use it. Till then those interested can refer MSDN article here :
http://msdn.microsoft.com/msdnmag/issues/05/04/NGen/
Also there are more articles on Ngen and none of them are cool :( unfortunately they arent meant for you and me, they are for advanced geeks.

Monday, February 20, 2006

I got a Date with DateTimePicker

Well, Recently i came across one cool problem. Yes! the problem is really cool and what makes me blog here is that there is no simple solution available online, for what i encountered.Thanks for Visual Studio.NET I could rectify the problem myself.

DateTimePicker is a good control that solves most of our calender problems. It could be customized in different ways. Like we can customize the format in which the date appears. Also the look could be changed. Inorder to change the look from ComboBox style to updown-style just change the property "ShowUpDown" to true. It would give you two small updown arrows, that could be used to change the value.

Each of us have our own taste for the way the date should appear, not only taste sometimes our requirements makes us change the display to something else. For example, at times we might need something like :
1/1/2005 10:05:00 AM
and sometimes just :
Jan 1 2005 10:05 AM
What i mean is that there are numerous ways in which DateTimePicker should display the value. So how do you tell the control what format it should display?
The answer is simple, you have the Format property on the DataTimePicker, which can take different values like Long,Short,Time and Custom(Clearly it is an enumeration).Programatically you can change the value as

dtp1.Format=DateTimePickerFormat.Long or
dtp1.Format=DateTimePickerFormat.Short and so on.

The most powerful of these Format values is Custom, which gives us fine grain control about the display. Working with Custom format is complex at first for those who havent worked with it till now. But it is simple then on. The steps are simple.
1. Set the Format property to "Custom"
2. You have another property "CustomFormat" on the DateTimePicker control which gets into action when Custom format is applied.
3. It is a string, so you can set a format as a string here. For example in order to display the date/time as February 21 10:00:00 PM, you can set the custom format as :

dtp1.Format=DateTimePickerFormat.Custom
dtp1.CustomFormat="MMMM dd hh:mm:ss tt"

4. Its over!!! Apply changes, check it out. You see exactly what i showed above.

There are really numerous ways to customize like - you can also display the Day name like Friday, sat or Sun, more and more control is possible. You can even specify 24 hour format, i.e., if its 2 pm it could be shown as 14:00 . How do you do that?
See the following statement :
dtp1.CustomFormat="MMMM dd HH:mm:ss"
The display would be then February 21 14:00:00 ( its in 24 hour format now)

Well i am done with my date, you need further details about the Customformat take a look at this link on MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatetimepickerclasscustomformattopic.asp

Now let me come to the cool problem i was talking about !!!
Cool Problem - very hot!!
My requirement was that as soon as i load the form which has a DatetimePicker control, the control shoud display the current time ! Well it is rather simple, could be done in two ways.
1. dont set any default value during design time. OR
2. In the form load property, you can work this out as :
a) first set the MaxDate property of dtp to DateTime.Max or anything else you wish. But not that if you set MaxDate as 2004 and you try to set the value greate than the MaxDate, say 2005, you ll encounter an exception. What i do usually is :

dtp1.MaxDate=DateTime.MaxValue.AddDays(-2)

I subtracted -2 because, the DateTimePicker cannot support anything that is after 12/31/9998 12:00:00 AM. if you say

dtp1.MaxDate=DateTime.MaxValue

You encounter this exception:
"DateTimePicker does not support dates after 12/31/9998 12:00:00 AM. Paramter name:value"

And if you know, DateTime.MaxValue is "12/31/9999 11:59:59 PM. That is what DateTimePicker can support is exactly 1 year 1 sec less than the MaxValue. So you can Add -1 year and then add -1 second, but I wanted to be on safer side, so i directly add -2 years(means i remove 2 years from MaxValue which makes it 12/31/9997 11:59:59 PM, which is totally fine.
b) setting the MaxDate is really important because, if you dont do it and then say
dtp1.Value=Date.Now
you shall encounter this exception :
'1/21/2006 1:06:00 PM' is not a valid value for 'Value'. 'Value' should be between MinDate and MaxDate.

Now one can ask if i need to even set MinDate, well it is not actually needed, but what you set at default value is applied as MinDate. So most of the times not needed, incase you set something other than Date.Now to the value of dtp and if you get an exception, you better set even the MinDate property to something else.

All code at single place :
In Form load event

dtp1.MaxDate=DateTime.Now.AddYears(-2)
dtp1.Value=DateTime.Now ' you can set the value.

If you take the exception message 'Value' should be between...... and search in google - all you get is about DataBinding and databases. Well I havent worked on DataBinding much, so no idea about it. But there was no solution for this simple problem, atleast i did not find it.

So I thought it would add my blog little value, if i present some article on how to work with DateTimePicker and a general problem when using it- along with my solution.

Hope you .NET guys find it useful as much as i do. See you soon with another article.

Sunday, February 19, 2006

Chronicles of DotNetNuke:Krish, .NET 2.0 and DNN

I was just wondering how much DotNetNuke is getting popular. At RAC, I often see atleast one major DNN project every week. By major i mean it would definitely take a week or more to complete. Hey wait! What is DNN?

Well DotNetNuke is a community effort - a CMS that could be used as internet and intranet web applications. Written entirely in asp.net, it is as good as any other CMS. PhP is widely used for CMS and there are excellent such CMS in the form of phpBB, vBulletin.

Well one thing that unlike most think, CMS is not all about Forums, but it is much more. Take a look at PhpNuke based portals you can see how powerful they are. For us what interests more is that a well accepted CMS generates a lot of jobs, be it part time or full time. Like I happened to notice quite a few custom module development projects for DNN. So isnt it good?

That is the reason, i wanted to learn something about DotNetNuke, if possible contribute all i can to the Microsoft Open Source Community. If i can get atleast 10% out of DNN by end of March, then i would consider myself efficient. Trust me, there is going to be a lot of future and opportunities for those who are well versed with DNN. It has become so much popular in just an year and half(when i first learnt asp.net, Dnn wasnt that popular) There are jobs, especially my fellow guys/gals who wish to pursue MS abroad - you should learn DNN if you are well versed with ASP.NET

These days Video Based training has become so much popular. Even DNN has good training videos available, at their website, heres the link.
Documentation: http://keihanna.dl.sourceforge.net/sourceforge/dnn/DotNetNuke_4.0.2_Docs.zip
Training videos at :
http://www.dotnetnuke.com/About/TrainingVideos/tabid/810/Default.aspx

Believe me guys, I am not wrong most of the time especially in catching things useful for career. First when i opted to learn .NET most of the people laughed thinking its not such a good idea, but today it has given me part time job and lots of satisfaction. So those who are familiar with .NET and vb.net language, you better lay your hands on DNN. join hands with me - we can learn things together.

Saturday, February 18, 2006

Tribute: John Vlissides

Recently, i came across this thread on DevSourcel through which i came to know about the demise of Mr.John Vlissides. Well not many of us know him, but the core of software developers, the most professionals guys out here definitely knows him as one of the "Gang of Four".
Heard of Design Patterns? If so then, you should know this person. Mr. Vlissides is one of the four persons at IBM who gave the world the notion of Design Patterns and more importantly the key person behind the launch of Project Eclipse. He expired after a 19 day illness due to brain cancer. Without his effort on design patterns and project Eclipse, the world of software would not have been what it is now. So please pray for him.

Hide and Seek : WebServer utility

I just found this cool article on still cool utility that comes along with .NET 2.0 SDK; Using this utility, the article says, one doesnt need IIS to run their applications. As in the previous entry; i earlier has lot of problems setting up IIS for Asp.net and this is something cool. This is really cool for beginners too - beleive me banging your head with IIS is very tough than using this utility. There are some limitations but it ll not matter for newbies. So go ahead read that article.

And you know how i found out that one? through ads on my blog :D; i am not trying to sell my blog - but that is the truth. i was clicking on the ads myself and in turn visited to devsource - made a few searches over there and got this one !! So click ads and learn something :))
By the way link for the article
http://www.devsource.com/article2/0,1895,1886246,00.asp

Friday, February 17, 2006

Haunted Mansion : ASP.NET and SQL Server Express

If there is no other technology as good as the .net platform, then there is no other technology with as many vague-properly undocumented issues as the Asp.net platform. There are several server side issues both during development and deployment. Long ago, when i first started asp.net programming it was hell for me, to set up IIS working because even if you have a single virus active ASP.NET applications refused to run. And more over with Visual Studio 2003, unless IIS is working properly you cannot imagine programming Asp.net applications.

With .NET 2.0 and Visual Studio 2005, i thought the issues are all over, i guess i saw somewhere that you dont need IIS to develop Web Applications(ofcourse to run and test them you do need IIS) Then i thought i could give IIS, a finger - because it has really irritated me so much. As it is I hate web programming and with IIS, my hatred grew. But future is all about ASP.NET and Web Services, even if you arent in love with them, you have to marry both.

Real nuisance i would say are the Xml configuration files. I agree they are really nice feature, but i would say from developer perspective they are nuisance. When Microsoft lovers are more inclined towards GUI way of programming, with Visual Tools workin with stupid XML files is really painful. You talk about security, you see web.config or machine.config; that is really stupid. There is a reason for me to get irritated so much. Recently I was working on C#-Vb.NET conversion project. It involves SQL Server Express 2005. Yeah fine, i had it installed and wanted to test it with asp.net application. But the connection refuses to open when running the program it says:
Login failed for the account Archsoft\ASPNEt
(Archsoft is my machine name)
I have been banging my head since two days, trying to figure out what is to be done. But nah!!, i dont get any feasible solution.

I thought of installing the SQL Server Express Management Studio, which is ofcourse free(30mb download, i wonder why it isnt included with SQL Server Express) But my drive where sql server epxress is installed is only 4000mb of size and i am left with only 30mb of free space.(it needs 191 mb of free space)

Now i googled out for one last time, before i give up and found this link.
http://forums.asp.net/1176822/ShowPost.aspx

Anyway the worst part of this is that, the issues are very new compared to what we had in .NET 1.1(they were age old with quite a few solutions online) . And you know what !!! Check out MSDN support's answer for that issue, here :
http://support.microsoft.com/default.aspx?scid=kb;en-us;316989
It says


To resolve this issue, use one of the following methods:
Method 1. Programmatically change the security context of the ASP.NET worker process to a user who has the correct SQL Server permissions.
Method 2. Change the default configuration of ASP.NET so that the ASP.NET worker process starts and runs under the context of a user who has the correct permissions in SQL Server.
Method 3. Grant the correct permissions on SQL Server so that the aspnet_wp account (or NetworkService account, for an application that runs on IIS 6.0) has the appropriate access to the required resources.



Come on!! The exception i get during developmet clearly says
Login failed for user 'MachineName\ASPNET
Any dumbass with common sense knows that the account ASPNET doesnt have sufficient privileges. So one expects the support article to answer "how to set aspnet the required privileges?" But as you can notice above they gave 3 methods on how to resolve this problem and all are statements !! Is that any kind of support??? Well if it is then i m a dumbass then.

Very soon i shall figure out the solution and i shall provide the support what the article doesnt. Till then join me and abuse that article :))

See you soon with solution.

Freedom of Expression in .NET with Express Editions

Well Microsoft has realized that the apart from being an excellent platform, the major reason for the success of Java is that it is community friendly - most of the Java stuff is free for developers and thus attracts huge newbies. There was one thing which Microsoft always boasted about - its IDE - THE VISUAL STUDIO. Inspite of being very expensive, it has become so powerful that everyone was willing to buy.(ofcourse those who are loyal to ms)

With advent of Eclipse, things changed a bit more than what one has expected. Earlier the IDE market for Java was ruled by Borland whose Delphi is also very popular amongst Windows Developers. But again Borland Studio wasnt free(there is a free developer version,limited). Eclipse is the best IDE for Java, but what i feel is that it really needs a high end machine( my machine is 733Mhz P-III with 256MB SD RAM and I run .NET Studio successfully, but it always makes me dull when i run Eclipse - somehow i might be doing somehting wrong) Anyway that is a different story, but Eclipse is a bigggggggg hit. There are thousands of plugins for Eclipse, which can all be used to extend the IDE to unimaginable extent. NetBeans is also getting popular, with its free community edition being released. Anyway this is not a Java blog, so let me get back to the topic.

Microsoft has taken a whole new strategy to get a fair share of developer market through its .NET 2.0. Apart from being the best release by Microsoft so far, another cool offer from Microsoft is their Express Editions. There has been a lot of publicity and encouragement from Microsoft for developers to try their Express Editions. Well, just for information for any IDE, there are usually numerous versions - Professional. Enterprise, Express,etc. Express Editions are free for download and there are three Express Editions as of now. Visual Basic Express Edition, Visual C# Express Edition and SQL Server 2005 Express Edition. All of these are free for download, for almost another 10 months. They have almost all the features that a normal developer needs or uses in Visual Studio 2005. Some of the advanced features might be missing, but frankly inspite of using Visual Studio .NET since two years almost everyday, I feel i dont even use 5% of the features .NET provides. The major use for an IDE atleast for a normal developer like me is Intellisense and Debugging. Very soon, i shall add an article about Debugging, and how it makes developers life very easy to make their applications error-free.

Anyway for those who wish to try .NET and are scared to get VS 2005, can just download the express editions and get most of the .NET features at your place; then try out. They are each somewhere near 400-500 mb.

Well before i end just let me tell you, that from tomorrow, i shall a daily funda to my blog. The funda would have few curious questions about .NET/C#/Vb.NET and answers to them. And hey, as you have already visited my blog, just click over the Ad that is placed on the top of this page- that fetches me some money dude!!

Thursday, February 16, 2006

Asynchronous Programming - Delegates : Always a problem for 90% of .NET developers

Most of us when working with GUI applications has definitely encountered certain problems with updated refresh of view. I mean to say that if you perform a task which takes atleast 10 seconds odd to finish, and then you try to switch between windows and attempt to get back to the main application window, you can notice that the application has freezed. You have numerous options to overcome this. the simplest one is write a void method/sub procedure and create a thread that executes that sub procedure. Inside the sub procedure, you can call the Refresh() or Update() method of the form you wish to refresh the view. Well this topic is not about how to use threads to make Windows applicaitons free of freezing effects, but is about asynchronous programming.

Asynchronous method call is where we call the method and proceed to execute the next line after the call. We do not wait for the method to return. So how will you know when your method has finished execution? what if you want to return some information or a value once the method has been computed? As an answer to all these questions, there is the CALL BACK function. The call back function is that function that is executed when the method that has been invoked asynchronously has returned(completed execution) The call back function is passed as a delegate and so is the function that is being called. So learning how delegates work is the first step for one who wish to use asynchronous calls to functions. Almost all tasks which takes considerably good amount of time to execute have asynchronous versions, already provided. For example on a stream you have a BeginRead() method. All the methods that are asynchronous starts with "Begin" and has a corresponding "End" method which is actually a call back method.

First of all. Let us look at working with delegates in simple terms. I am no expert and this is no documentation. So spare me if you dont understand and go join some coaching classes.

Basic Signature
public delegate [returntype] [function-name] ([parameters]) //C# version
public delegate
[function-name] ([parameters]) as [returntype] ' Vb.NET version

For example
public delegate int MathOperation(int a,int b);

We have declared a delegate. delegates could be treated as objects, just that they can call only one method. Just follow the steps you shall understand.

Step 1
1. Declare a delegate, usually outside the class as shown
public delegate int MathOperation(int a,int b);
2. You need to prepare a method same as the delegate signature. For example, for MathOperation a valid method would be as
public int Addition(int a, int b)
{
return a+b;
}
3. You need to then create an instance of delegate passing the method name that it is supposed to call. Here,
public static void Main(string[] args)
{
//create an instance of delegate
MathOperation add=new MathOperation(Addition);
Console.WriteLine(add(10,20));
}
As you can see you invoke the method through delegate instance as shown [ add(10,20) ] It appears as if we have given a new name to the method instead of using the exisiting name. So what is the use of delegates when i could do the same without using delegates.

Usage??
The need for delegates rises in the situtaion where there are two objects say obj1 and obj2. Obj1 has a reference to obj2, so obj1 can invoke any method on the obj2b, but what if obj2 needs to invoke a method of obj1 whose reference it doesnt have. In that situation obj2 would provide a method to which obj1 can pass a delegate which holds the reference to the method of obj1 which obj2 needs to invoke. Inside the method of obj2, the delegate is registered with the obj2, so it is not the object reference that obj1 has but direct link to method of obj1. I hope you understand this. If you dont, then read again :))

[to be continued .....
[Next ... how to perform asynchronous method calls?]

Wednesday, February 15, 2006

Code Central

Just wanted to say more - if any of you guys need some kind of help in resolving bugs for your .NET projects, feel free to contact me at krishnabhargav@yahoo.com; you need any code snippets, just ask over here. I really have a lot of code with me, and I am ready to share with you all. But hey, dont demand - i am an head strong egotist. So better, request and leave. I shall definitely answer any question within my reach. That one thing i can promise.

Beauty and Beast - Advanced Serialization

Serialization is a technique in which an object is coverted into a form that could be streamed over any Stream - this includes a FileStream and HttpWebRequest 's RequestStream etc I intentionally mentioned Request stream here. Everybody who has programmed for an year or so, uses Serialization on FileStream to save their objects, but recently i could use it differently. My requirement was that - I want to send an "object" from a windows applciation to a Remote ASPX application. I thought of Remoting the server on IIS, but it involves a new learning cycle for me as i have never worked on deploying remote objects on IIS. So this is the technique i could come up with. I opened a http request on the aspx page which accepts the object that i am going to send. On the request, i could get the request stream say "rs", then i serialized my object on the response stream using BinaryFormatter. That is it. But the serialized data to be streamed, you should also fetch the response, only when you call the GetResponse() your data would be actually streamed.

In the aspx page, i created another BinaryFormatter in the Page Preload event handler. There i fetched the request object and the base stream inside it, Then i called the Deserialized over it to get back my object.

This was really cool way to establish communication between a windows application and web application. If it was XML serialization , then probably i could even communicate with a servlet or a JSP container. I did not try it out yet, but if anyone does that, post a comment over this blog.

I had another requirement where I used serialization again, but here the requirement was that the object had some not so secret, but information that my client wanted to secure. So i thought of encrypted serialzation and i have found a good article whose link i posted it over here. But somehow i could not implement it successfully. Then i thought if data is compressed, it is not human readable in any text reader like notepad or wordpad. So i thought of using the compressed serialization as in the link i gave. But GZipCompression did not work for me and i had to go for DeflateCompression method. I created a compression stream over the filestream and i used it for serialization. The important point is htat deserialization shall not work unless you add the Flush() statment after the serialization is performed. I shall add the code block, in the next blog.

The applicaitons of Serialization is not well covered anywhere in the documentation. It could be well used, and its so beautiful. But hey! there are numerous issues you shall face during deserialization. As i get more acquainted with blogging, i shall make this blog a better and excellent place for information on .NET and sometimes Java. I love bill Gates, just because he gave us .NET platform.(ofcourse i would have loved Jennifer Lopez, had her company come up with something as good as .NET)

Monday, February 13, 2006

A Valentine's day serialization

Recently, I have worked on almost three projects involving only serilization. I mean pure serialization. Right now i have a work to do, so I just want to save a link on my blog.
This is an excellent article on Serialization and how one can create an advanced Binary Serializer.
Also shows how to perform encrypted Serialization,Compression,etc.

http://www.marcclifton.com/Articles/Performance/RawSerializer/tabid/130/Default.aspx

I can also show you real world use of serialization when i talk about it later. Also i would show how to perform FTP UPload/Download in .NET( my latest project is that) using two different ways - using WebClient and other using FtpWebRequest/Response(.NEt 2.0 only)


For now that is it.

Tuesday, February 07, 2006

Pain with DHCP

having searched online for all possible ways to know if the DHCP is enabled on a system, i could finally get hold some WMI way to do so. Thanks to aspfree, i did not go through it yet but woud do so very soon. Anyway heres the code:

Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Dim dt As DataTable = globals.getNetworkInfoStructure
For Each queryObj As ManagementObject In searcher.Get()
Dim IPAddress As String = ""
If queryObj("IPAddress") Is Nothing Then
IPAddress = queryObj("IPAddress")
Else
Dim arrIPAddress As String()
arrIPAddress = queryObj("IPAddress")
For Each arrValue As String In arrIPAddress
IPAddress &= arrValue
Next
End If
globals.addNetworkInfo(dt, queryObj("Caption"), queryObj("Description"), queryObj("DHCPEnabled"), queryObj("DHCPServer"), queryObj("DNSDomain"), queryObj("DNSHostName"), IPAddress)

Next
Me.DataGrid1.DataSource = dt

Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try

This is ofcourse only a part of the code and i shall update it very soon, once i modify it as per my need.
Anyway heres another new thing i learnt in .NET SDK.
You have this mgmtclassgen tool which you should run from visual studio commmadn prompt and generate a vb or C# or any other .net class which functions exactly like the WMI object, just that you need not use any managementobjectsearcher. More information on it later. Meanwhile just google out for "mgmtclassgen" and you ll get the information needed.
Thats it for now.

Sunday, February 05, 2006

Me, .NET and FxCOP

Well its been long since i posted my first blog, probably about how to approach BeanShell and PMD. Well to add another fact , i received a complimentary copy of PMD Applied and guys this book is really cool and one cannot ask for a better and simple book. PMD is an open source tool to test Java code for consistency and coding standards based on some pre defined rules. We have a similar tool for .NET Platform called the FXCop which i have just downloaded. I have to try out yet and i shall try it out on my final year project. Its high time i start my project and i hope to finish it at the earliest.

Coming to FXCop, it has a cool but outdated GUI look(i checked out 1.32) it appears like some old good tools - anyway the functionality is what matters more. I wish it has some project import option and can check the entire project of VS.NET 2003 Studio. For those who doesnt know how to go about with FxCop, you just need to create a nw project in FxCop and add your assemblies to the to the project. Assemblies is a cool term and it really makes me feel wow when i last heard about its definition. Well i dont want to recall that and type that over here but simply put - an assembly is a building block on .NET applications.(well its not the definition, atleast for you all).
Once you add the assemblies, you can use the tree explorer to your left to check out the rules.

Just for your information, based on the documentation of FxCop - it uses MSIL Decompilation, and other such ways to test if the rules are applied. PMD works a bit different over here. It is a static code testing tool, it doesnt use any memory profiler, just raw interpretation of Java Code in its original form. I havent tested it out yet of bulkier code, will test it out soon.

I am now going to test the rules against my assemblies and i am using only the Remote Machine part of my project(there is another administrator part) If everything goes well i shall add this information in my project report on how my application has passed the FxCop Test. When we are ready to test, we just need to click the "Analyze" button on the top, with a play icon. It really performs quickly - i expected something around 5 mins for some code :) Hey wait , i have deleted one assembly from the Project and it raised an exception. :-? Not well debugged. Well this is usually the case with excellent community products. I hope it has been rectified in the .NET 2.0 Version. I shall check that out very soon. Well let me start the tool again and check this time for rule violations in my code only. This time i shall let you know even the time it takes to verify the assemblies. Well it takes only matter of 5 to 6 seconds, but what is irritating is that it is giving some information about the violations in the code which you havent written. So what i did is that i have unchecked all the rules in the rules tab and then i have checked only the "Performance Rules" and you can really expand the performance rules and check only that are applicable and which makes sense. I would like to test if my application performs well, i am least bothered about auto generated code- i cannot change it can i? There is a rule "Mark Method as static if "this" or "ME" is not used inside the method" well, what if it accesses the members of the same class to which its currently member of? So the rules doesnt appeal as much to me. So i uncheck that rule for a while, because when designing my application i have made sure that the methods are made static wherever necessary, but my app deals with Remoting and Static Methods in Remoting are big pain, instead i already use Singleton objects. Am i correct here?

The cool aspect of using such features is that we get to know the performance issues and we should really read the ruleset properly and it improves our coding techniques. Let me explain. When i tested my code with FxCop for only Performance and i have unchecked "mark methods as static", there is one rule violation that has caught my eye. It says "Test for empty strings using string length" Seeing that i clicked on the rule violation info displayed and to the bottom i can see the description - the bad part is that the description is in IL :)) Well i normally test for empty string using Equals() method this way:
If string1.Equals("")
return
End if

There is clearly performance problem which i havent noticed till now - We create an empty string object, call a function, so there is lots of process being performed at the back. Instead I could have done it with simple string1.Length property as
If string1.Length=0
return
End if

There is no creation of new object, no stack operations are performed and this definitely improves the code performance. Good! I learnt a new thing which i shall keep in my in the near future. This is why i said such tools and their rulesets are always interesting.

One thing with FxCop is that it tests for autogenerated code, i guess. And it annoys me. I wish there is a way where it tests only for my code. I shall have to check out the options.
At this point i would also like to tell about "Channels" in Remoting. Having played with .NET Remoting for my application, which involves sending image across the channel. I have discovered two things:
1. Images cannot be sent directly like other objects. Instead, create a Stream object and save your image in the stream and send the stream instead. Later you can use Image.FromHStream method to extract the Image.
2. There is helluva difference between the performance of HttpChannel and TcpChannel. When i used a HttpChannel to send the image capsuled in a stream object, it took reasonable amount of time. Later i replaced HttpChannel with a TcpChannel and it has improved the performance significantly.

My project requirement also includes "communication over encrypted and compressed channel". I have no clue as of now, how to implement such a channel of communication in my application. But just for a feature i have mentioned it and i can remove it anytime, once i see a performance degradation cos of those features. Atleast i have a reasonable answer if question is raised.

There is a lot of scope for one to research in .NET Remoting and i am worried before i learn something in Remoting, it would be replaced soon by WCF(I think its for distributed computing) I have had my friend download the latest Windows Vista SDK. Got to check that out very soon. .NET is fun and Microsoft software development tools are better than any other tools in the market. That is for sure. ( i am not a java antagonist, just that i love .net more, cos it makes me feel wanted :)) )

RAC Life is not as smooth as it was earlier. I just took up a C# to Vb.NET Converssion project and it removed the hell out of me. Well it was really fun and i really learnt some cool things which i wasnt aware earlier. Well that is all the work i had at RAC, though it appears pending projects are "4", 3 of them i have reported work complete. There are some good buyers out here at RAC and i really enjoy working for them. Ezra, Levent(my java tips boss) and now Uwe are now the most cool guys i met at RAC. Special thansk to Uwe who gave me an extended deadline for C# to VB Conversion project. Anyway always thankful to one person on this earth without whom my life would have been differently painful.

Just for those who wish to try out software development on Linux, you can get hold of different Linux LiveCD which doesnt need any installation to be done. You have good set of cds and heres the list.
http://www.frozentech.com/content/livecd.php?pick=All&showonly=development
Recently i downloaded Monoppix to try out Mono.NET on Linux platform and later i shall download Pollix for Java Development. Mono-Live i heard is cool, but it was 700 mb odd n i wanted to download as early as possible so decided to go for Monioppix which is 470mb odd.

Well guys, see you soon again with .NET fundas.

Krish