by Ahmadreza Atighechi
5. May 2009 12:13

During developing applications we have always use unwritten rule in programming or if it is written in design documents user should consider them in development. For example if developer wants to call a method which has an integer parameter and this parameter is used as an index of array he should be aware calling that method with negative value or greater than array lenght. Calling method with negative value causes runtime error.
There are lots of contracts that a developer should consider during development. Recently I came across new concept (However it is in research phase) named CodeContracts which is really wonderful. It seems that this concept will be in VS 2010. CodeContracts will organized all written and unwritten rules & contract in development. In order to clarify CodeContract usage imagine following code:
static void Swap(string[] arr, int itemIndex1, int itemIndex2)
{
string temp;
temp = arr[itemIndex1];
arr[itemIndex1] = arr[itemIndex2];
arr[itemIndex2] = temp;
}
What are possible errors when we want to call Swap method?
- None of itemIndex1 and itemIndex2 could be negative (both should be positive)
- None of itemIndex1 and itemIndex2 could be greater than arr.length
- Array arr should be not null
Before code contracts developer should always consider possible situation and avoid breaking rule. But CodeContracts provides rich methods by which you can add your Code Contracts to your method and after compiling application Contracts checker will warn about breaking rules. Let see how it should be implemented with CodeContracts
static void Swap(string[] arr, int itemIndex1, int itemIndex2)
{
Contract.Requires(arr != null);
Contract.Requires(itemIndex1 >= 0);
Contract.Requires(itemIndex1 < arr.Length);
Contract.Requires(itemIndex2 >= 0);
Contract.Requires(itemIndex2 < arr.Length);
string temp;
temp = arr[itemIndex1];
arr[itemIndex1] = arr[itemIndex2];
arr[itemIndex2] = temp;
}
I added five contracts to this method which mean this method needs not null array as first parameter, second and third parameter (itemIndex1, itemIndex2) should be greater or equal to zero and should be less than array length.
In the next post I will show how to implement this with CodeContracts
But now I want to introduce some resources:

by Ahmadreza Atighechi
24. April 2009 04:38

Graffiti CMS express edition is popular amid developers as well as Community Server. At the moment I wanted to decide between Graffiti And Community Server I couldn't made my mind. Blog subsystem of community server has a simple theme which is similar to MSDN blog theme (Like current theme). This theme was inducement of community server. Finally, I used graffiti because of simplicity, anyway , Recently I decided to convert simple theme of community server 2008 to graffiti CMS theme.
I put first version of simple theme here
by Ahmadreza Atighechi
15. April 2009 10:44
SQL Server 2005 is installed without any samples - at least versions I installed don't contain Northwind and pubs databases -. However Microsoft put SQL Server 2005 Samples and Sample Databases in Codeplex, light version of these two sample databases were always famous in a way that you can find one of them in most database related samples with high probability. You can find SQL Server 2000 Sample here. After installation file is downloaded take following two steps:
1. Install msi file. Some files will be copied in C:\SQL Server 2000 Sample Databases
2. Attach Northwind.mdf file which is located in C:\SQL Server 2000 Sample Databases. Repeat this step for pubs mdf file.
by Ahmadreza Atighechi
6. April 2009 12:28
Informing user about application state is one of important aspects in user experience. In windows applications mouse icon indicates one of great application states. When an application is busy mouse icon should be changed to wait cursor mode or hourglass icon. In windows application you can achieve this by changing Cursor property of any Control, Usually by changing "this.Cursor" which "this" is current form in application. See example:
this.Cursor = Cursors.WaitCursor;
Since control class in compact framework does not have Cursor property, not only developer could not change every control cursor icon but also he could not change form cursor property. So what should developer do in order to indicate application state?
There is a static class in System.Windows.Forms named Cursor and it has a property named "Current" which developer should set it to an appropriate cursor based on application state.
System.Windows.Forms.Cursor = Cursors.WaitCursor;
Or
System.Windows.Forms.Cursor = Cursors.Default;
by Ahmadreza Atighechi
30. March 2009 13:42
After long absence I'm back now. Recently I wanted to develop an application for windows mobile with .Net Compact framework. In this application I need to measure elapsed time in millisecond resolution. First of all like everyone I tried to use Millisecond property of DateTime.Now static class. But it won't work at all in .Net Compact framework even in version 3.5!
If you want to use a timer with millisecond resolution you have to use TickCount property of Environment class.
//Will be zero.
lblMillisecondVal.Text = DateTime.Now.Millisecond.ToString();
//Total milliseconds elapsed since the system started.
lblTickCountVal.Text = Environment.TickCount.ToString();
Here is an example of using TickCount Instead of Milliseconds
by Ahmadreza Atighechi
28. October 2008 00:07
Currently, I'm working on Pocket PC development. During last week I've found interesting resources about windows mobile development with .Net compact framework. first of all Windows Mobile Team Blog would be a sophisticated resource. Moreover you could find other useful links in this weblog.
Other blogger's web site would be good resources, like Chris Craft's Blog. CJ's weblog contains a series of posts for a month. For each day he wrote a post about windows mobile programming. It would be a good starting tutorial for beginners.
Another web site that could be useful is www.dotnetfordevices.com .
However, I'll post related news and experiences during windows mobile development
by Ahmadreza Atighechi
7. August 2008 03:44
Embedding other resources like Cascade style sheets and images is possible as well as JavaScript file. I wrote "How to embed JavaScript file in an assembly" in previous post. For embedding images you have to do same way with minor changes in accessing resource. You should add you file into your project and
change the value of "Build Action" property to "Embedded Resource". In Assembly info file you should add following line for images into AssemblyInfo.cs file:
[assembly: System.Web.UI.WebResource("EmbededJSControl.Logo.GIF", "img/gif")]
And following line for css file:
[assembly: System.Web.UI.WebResource("EmbededJSControl.Stylesheet.css", "text/css")]
To use image resource in your pages you should add following code. In case you use resource in same project you could use this.GetType() as first parameter otherwise you should create an instance of control from project in which you included resource and get type of that control.
Image img = new Image();
img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "EmbededJSControl.Logo.GIF");
For including stylesheet use following code:
string cssLink = "<link rel='stylesheet' text='text/css' href='{0}' />";
string location = Page.ClientScript.GetWebResourceUrl(this.GetType(), "EmbededJSControl.Stylesheet.css");
LiteralControl css = new LiteralControl(String.Format(cssLink, location));
Page.Header.Controls.Add(css);
Complete sample code is available here

by Ahmadreza Atighechi
22. July 2008 05:10
Developing ASP.NET web controls is always interlocked with creating javascript codes in order to create client side functions. Moreover, a developer always has a tendency to release minimum files, most of the time an assembly (DLL) which includes all requirements for web control, is best case. This post is an attempt to represent how to embed JS file in an assembly.
First of all you have to create an ASP.Net AJAX-Enabled Web Site named "EmbededJSTest" and add System.Web.Extensions references to project . In order to add this assembly you have to install ASP.NET AJAX 1.0. Add another Web control library project to solution named "EmbededJSControl". Add project reference of "EmbededJSControl" to "EmbededJSTest".
Create a JavaScript File to project named "JSResource.js". Open js file and write code:
function HelloWorld()
{
alert('Hello World!');
}
Save and close this file
In property page of this file change the value of "Build Action" Property to "Embedded Resource".
Open AssemblyInfo.cs at the end of file add following line
[assembly: System.Web.UI.WebResource("EmbededJSControl.JSResource.js", "application/x-javascript")]
Open Default.aspx file in source mode. Change ScriptManager Control to following:
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Assembly="EmbededJSControl" Name="EmbededJSControl.JSResource.js" />
</Scripts>
</asp:ScriptManager>
Add a HTML button :
<input id="Button1" type="button" value="Hello" onclick="HelloWorld()" />
Save file and close this file.
Execute project and click on Hello button.
By applying this method in your Web Control projects there is no need to release js file with assembly dll's.
You can also download source sample here
by Ahmadreza Atighechi
18. June 2008 09:43
I had many experiences in different projects to create installation with "Wise Installation System Professional 9.0" especially in visual basic 6.0 projects. This version was extremely mach with visual basic 6.0 projects and its scripting was easier than that of competitive products.
Recently I was looking for a reliable packaging software and predictably I went in for new version of Wise installer supporting .Net applications . I found two version of Wise installer in company web site named "Wise installation studio " And " Wise installation express " .At the beginning I wanted to evaluate " Wise installation studio " It was frustrating! because at the beginning it was a little complicated, However, I know that it is designed for an enterprise system development and it is more than an installer editor for medium-sized projects. I have historic problem with "express editions" which remind me limited features of an application. But " Wise Installation Express 7.0 " is something else and it seems more than an express edition of Wise installation and It will completely useful in small and medium-sized projects specially in windows applications. I've found it simple, easy to use and sophisticated. You can find full feature comparison grid here but for me highlighted features are listed below:
Wise Installation Studio/Express 7.0 Advantages from my point of view
- Interface key-points is same as previous versions
- Supporting Microsoft Windows Installer (msi)
- Support for 64-bit installations
- Support mobile device packaging
- Supporting Merge modules
- Patch Wizard
by Ahmadreza Atighechi
17. May 2008 08:16
Although it wasn't easy for me, finally I made up my mind to create a web log and write my experience and note about .Net issues and development. As far as I concerned many problems I'm recently grappling with are solved by blogs either I previously know or I find in search engines. Since give-and-take is one of basic rules in technical societies, taking advantage of others blogs without giving information does not seem fair. Hopefully, I'll do my best to submit some useful post.
Moreover, I am enthusiastically looking for your comments and I believe that your comments will help me in order to improve my blog.
489812d9-1936-4e23-a842-e94fedcf8623|0|.0
Tags:
Blog