A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Archive for February, 2008

Why ObjectContainerDataSource?+WCSF

Posted by kiranpatils on February 29, 2008

Why ObjectContainerDataSource?

–> for strictrly following MVP.

–> Why not we use ObjectDataSource or SqlDataSource?
ObjectDataSource = it binds up with Custom object or Business entiy some where in Middle tier. which we don’ want.
SqlDataSource = when you do onSelecting,OnInserting,OnUpdating etc. events it fires to sql server.

–>where our Hero-ObjectContainerDataSource fires the event OnSelecting,OnInserting,OnUpdating event on thise event a page can
register a Presnter method here for the operations.

That’ why we use ObjectContainerDataSource..

if Some one has more views to share pls do it

Posted in Web Client Software Factory | Leave a Comment »

Visual Studio 2008 Free DVD

Posted by kiranpatils on February 28, 2008

Hi folks..too much busy in coding,Debugging and runing[oh ya unit testing also with Nunit]. So can’t share anything with you…so, sorry for that. But i have one gift for you all.

If you want FREE Visual Studio 2008 DVD free at your door step?

Here is the link http://go.microsoft.com/?linkid=8410810

So, book today and share it with your network.

Happy VS 2008!!

Posted in Latest happenings, VS 2008 | Leave a Comment »

Policy Injection – Unrecognized element ‘categories’+Enterprise Library+WCSF

Posted by kiranpatils on February 19, 2008

Hi, I have faced Unrecognized element ‘categories’ for PolicyInjection with EnterpriseLibrary under WCSF..Goggled it first than also not able to find any solution

StackTrace:

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.


Parser Error Message: Unrecognized element ‘categories’.

Source Error:

Line 33: priority=”-1″ severity=”Information” type=”Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”

Line 34: name=”Logging Handler”>

Line 35: <categories>

Line 36: <add name=”DataAccess” />

Line 37: </categories>

Source File: C:\Employee\Tests\Employee.Net.Host\web.config Line: 35

Solution:

Looks Strange na..but i have its solution.

1. Right Click your WCSF Host Application or for other under your solution where you have configure this block. as shown in Server Error in ‘<SOLUTION NAME>’ Application.

2. Add Reference->Locate Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.dll [for me it is at :\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin folder].

3. That’s it.

Have a Happy Policy Injection!!!

Posted in Enterprise Library, Web Service software Factory | 2 Comments »

Checking Execution Time with C#.NET+ Use of it In WSSF+WCSF

Posted by kiranpatils on February 14, 2008

Today I am going to show you how to check an Execution time-Time taken by a function for executing its code block.

In today’s fast world all wants fast task [1Mbps, 1 Gbps…] and if your application’s response time is not fast than Boss you are lost with your application.

As per my Mind I ask “Why?” Why I need to check execution time because client wants final product for that I have to write code than why should I do this Execution time stuff.

For answering above question. Let us see some examples

Example1. Suppose you logged in your Banking site in which you have link called “View last transactions” and suppose that you are a shop keeper and have a current account than it’s obvious that you will have so many daily transactions. Now you clicked on link and from last 10 mins. Page says “Please wait…..” I am sure that you will close the browser window and will go physically at bank’s branch and ask for bank statement. [Gradually people won’t believe in software, applications means our Job is in danger.]

Example2. Now suppose you have U.S.A. Client for whom you are creating one software. And if response time is too slow than he will say “Indian peoples can’t create good software”. And will suggest to others also that don’t ask Indian people to develop your software. [Everything will be ost!!!!!!].

Now you are agree with me that response time is too important in our field.

So, let’s have a look on it how to do it with C#.NET with one example.

  1. I have created one Console Application for testing it. Its code is shown as below.

DateTime ExecutionStartTime; //Var will hold Execution Starting Time

DateTime ExecutionStopTime;//Var will hold Execution Stopped Time

TimeSpan ExecutionTime;//Var will count Total Execution Time-Our Main Hero

ExecutionStartTime = DateTime.Now; //Gets the system Current date time expressed as local time

//this is the main block for which we are checking execution Time

for (int i = 0; i < count; i++)

{       //Code of Block to do Execution

      Console.WriteLine(“Hi i am”+i.ToString());

      Console.Clear();

}//Execution Completed

ExecutionStopTime = DateTime.Now; //Gets the system Current date time expressed as local time

//Now Just calculate the duration taken by a Block

ExecutionTime = ExecutionStopTime – ExecutionStartTime; //Total Time

Console.WriteLine(“********Execution Time Summary*********”);

Console.WriteLine(“Loop Count = “+count.ToString());

Console.WriteLine(“TotalHours = “ + ExecutionTime.TotalHours.ToString());//Total Hours Console.WriteLine(“TotalMinutes = “ + ExecutionTime.TotalMinutes.ToString());//TotalMinutes            Console.WriteLine(“TotalSeconds = “ + ExecutionTime.TotalSeconds.ToString());//TotalSeconds            Console.WriteLine(“TotalMilliseconds = “ + ExecutionTime.TotalMilliseconds.ToString());//TotalMilliseconds            Console.WriteLine(“***************************************”);

OutPut when Input = 10000

image0011.jpg

Means my function has taken 2.03125 Second and 2031.25 Milliseconds.

So now just check the function do some “Code optimization” and check the Execution time. Decrease it as possible as you can.

Quick Check:

  1. Before execution starts take time using DateTime.Now
  2. After execution stops take time using DateTime.Now
  3. Check a difference using TimeSpan-which has so many useful properties.
  4. That’s it.

Real world use in WSSF+WCSF:

Microsoft has developed software factories and repository factories and they say that it has too quick response time. But than how you will check it that your service has been written good enough to respond quickly.

You can use the above steps for checking service response time also. Let me show with one example how you can do it.

Example:

  1. I guess that you have Service ready in WSSF Solution and eager to test it with Client Side-WCSF.
  2. Now come to WCSF and add Reference of your service let’s say “Employee Proxy”.
  3. Employee Proxy has one function “BookingProxy.BookingResponse GetEmployeeByID(BookingProxy .bookingrequest)”
  4. Now when you call your service using BookingProxy in Controller before calling “GetEmployeeByID” service take a time as a start time
  5. and when service returns [next line of GetEmployeeByID] take this time as a Stop time
  6. Do a TimeSpan and you will have a time taken by your service.
  7. So now you will have a code which looks like as under:

DateTime ExecutionStartTime = DateTime.Now;

BookingProxy.BookingResponse response = GetEmployeeByID (BookingProxy .bookingrequest);

DateTime ExecutionStopTime = DateTime.Now;

TimeSpan ExecutionTime = ExecutionStopTime – ExecutionStartTime;

Note it down and Enjoy!!!

Happy Executing optimum code block!!!!

-Kiran Patil

Reference Link:http://www.codersource.net/csharp_measure_execution_time.aspx

Posted in .NET, Web Service software Factory, Windows service Factory3.0 | 1 Comment »

Running your ASP.NET website/WSSF Service with VS 2005 Development server using Manual Port

Posted by kiranpatils on February 14, 2008

When I develop a Website using VS 2005 and run it than it runs under Development server given by VS which is called “Cassini”. But I have noted that it gets new port e some time when I run a site….why is it so???? And so many of my colleagues also has asked me the same issue….Finally I figured out why it happens and what its solution. Looks Eager to know…..let me reveal it..

Problem:

If your website runs on different port each time do a build and run???

Your WSSF Service starts each time on different port?????

Than I have its solution.

Solution:

  1. I guess you have Website ready [how stupid I am you are facing port problem and I am asking site is ready!!!!]
  2. Open Solution Explorer [CTRL+W,S].
  3. click on Website as shown below [just do a click on ManualPortWebsite]

image001.jpg

 4.Press F4. [While having Website name selected]. It will bring up a Properties window.

image002.jpg

  1. For giving Static Menu
    1. Do Use Dynamic Ports = False
    2. Port number = <Any number> for example 1234
  2. So, now Properties window looks like this:

image003.jpg

  1. That’s it now run your website and check that every time you will have a url like this: http://localhost:1234/MyWebsite

For WSSF Peoples who wants to run their service using Static Port:

Do the same step as shown above except in step 3. Select your Host [which has all .svc files and right click on it “Expose service” recipe comes] project and Press F4

Happy Website Development!!!

Kiran Patil

 

 

 

 

Posted in .NET | Leave a Comment »

Name Mangling with MasterPages and javaScript+ASP.NET

Posted by kiranpatils on February 11, 2008

from last few days we are working with Master Page and Java script and as the all Javascript do it gets the control by ID using “document.getElementByID(<ID OF CONTROL>).value”..That’s it.it looks simple but frankly speaking it has wasted our so much time…..Looks funny na???so let me tell you why??

defn [Name Mangling wikipedia]: In software compiler engineering, name mangling (more properly called name decoration, although this term is less commonly used) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages.

Problem:

you can do it simply by document.getElementByID..but you will get stuck when your control lies under Master Page…if you keep the same function which you have used for simple page[without Master page] IE Will say “Object required”. Because in your simple page the ID of control will be same…and if you add Master Page than id will be something like ctl00_ContentPlaceHolder1_txtName.. let’s see it by example

Suppose you have one control in simple ASP.NET Page and has ID txtName.

Now if you put it in MasterPage which has ContentPlaceHolder and had ID= ContentPlaceHolder1.

so now your ID= ctl00_ContentPlaceHolder1_txtName So the pattern for generating name i like :

ctl00_<ContainerID>_<CONTROL ID> for example ID = ctl00_ContentPlaceHolder1_txtName

Hope you are clear now.. so how you will find you control by this ID????

Solution:

in old Javascript you will refer control like:

document.getElementById(“txtName”).value

and Now you have to do:

document.getElementById(“<%= txtName.ClientID %>”).value

That’s it.

Looks cool na??

Hope you have enjoyed this article.

Happy Java scripting.

Kiran Patil

UPDATED 19-2-2008 VER 1.1

I have tried this with my page which has .js file located under different folder and i have linked it with page using tag.

But it was not working because Visual studio doesn’t Parse this  file and ClientID will not work.

So, Conclusion is that  you can’t use ClientID with different .js file

Posted in ASP.NET | Tagged: , | 10 Comments »

ASP.NET TEMP ERROR While Building+WCSF/General ASP.NET

Posted by kiranpatils on February 8, 2008

from last few days when we are implementing WCSF. we are facing some errors which are really not ours..it is of TEMP files generated by ASP.NET.

Problem:

Suppose i have one Interface named as IEmployee and it has 3 members EmpName,EmpID,EmpAddress and one of my page let’s say Employee.aspx implements it so it looks like this:

Employee.aspx:IEmployee

{

//Three Members implemented

}

now i build and it shows “Build Succeeded” .

after sometime i think that i don’t need “EmpID” in interface so i delete it and also deleted its implementation from Employee.aspx and now when i Build it. it shows me error and when i click on it it points to me ASP.NET Temp files location. which are not mine. [For your knowledge i want to say that ASP.NET Generates Temporary files at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\<Web site name>]. so it will point you there. But as i think it should work fine……..for that i have to work around it for hours and hours..so want to know its solution???

Stack Trace:

Error:
Error 126 ‘Employeet’ does not implement interface member ‘IEmployee.EmployeeID’ c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\developmentwebsitea97a19d\326f353\App_Web_euqzzc2o.0.cs 14

Solution:

For solving this error just follow me:

1.Take Copy/Backup of Employee.aspx page.

2.Now Delete if from WebSite Solution.
3.Now Build Solution. [you will not found that error]

4. Now add that page again from Backup path.

5. Now Build it and That’s it…..You have killed the errors successfully.

Enjoy ASP.NET!!

-Kiran Patil

Posted in ASP.NET, Web Client Software Factory | Tagged: | 2 Comments »

Generate Scripts from Database+SQL SERVER 2005

Posted by kiranpatils on February 6, 2008

Hi.. yesterday one of my colleague has asked me that how can i generate a script from Database with A Relationship,Tables and all the stuff….and i have shown it may you need it tomorrow..

Scenario/Problem:

Want to generate a Script from  Database with all the Relationship,Tables…etc..

Solution:

Just follow me:

1. I guess that you have opened Management studio and ready with Database.

2. just Right click on your database.

3. Will popup a  context menu. Select “Script Database as”->”Create to->New Query Editor Window [you can select anyone of it nothing strict in it :) ].

It will generate a Script for Creating a Database. Now let’s see how can we create Script for Tables and all the stuff

4. Now, Right click on Database->Tasks->Generate Scripts.

5.follow a Wizard..[By clicking Next..Next] .

5.1. select database

5.2.Next

5.3. select Object types you need [Table,SP,Views]

5.4 Choose SP [better do Select All].

5.5. Choose Tables.

5.6. Select Script mode..which is simple..so keep it on you for braveity.

5.7 Now make one file of both of this scripts and make it one [TOTAL SCRIPT=DATABSE SCRIPT+TABLE,SP,VIEWS SCRIPT]

5.8 That’s it now distribute. it to your client.. and enjoy!!!

6. How to generate  a database from Script file which was earlier generated.

6.1 Just open generated file in new query editor window.

6.2 Press F5 [to run script] .

6.3 That’s it.

you will have Database with all the stuff..

Happy Database Scripting!!!

-Kiran Patil

mcprgb.gif

Posted in SQL SERVER 2005 | Leave a Comment »