Thursday, December 18, 2008

Insert multiple records at a time with single insert statement..

This is very interesting question I have received from new developer. How can I insert multiple values in table using only one insert? Now this is interesting question. When there are multiple records are to be inserted in the table following is the common way using T-SQL.USE YourDB
GO
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('First',1);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Second',2);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Third',3);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Fourth',4);
INSERT INTO MyTable (FirstCol, SecondCol)
VALUES ('Fifth',5);
GO
The clause INSERT INTO is repeated multiple times. Many times DBA copy and paste it to save time. There is another alternative to this, which I use frequently. I use UNION ALL and INSERT INTO … SELECT… clauses. Regarding performance there is not much difference. If there is performance difference it does not matter as I use this for one time insert script. I enjoy writing this way, as it keeps me focus on task, instead of copy paste. I have explained following script to new developer. He was quite pleased.USE YourDB
GO
INSERT INTO MyTable (FirstCol, SecondCol)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
UNION ALL
SELECT 'Fourth' ,4
UNION ALL
SELECT 'Fifth' ,5
GO
The effective result is same

Thursday, November 27, 2008

Hosting of WorkFlow at WCF

Hosting through Web app
protected void btnSubmit_Click(object sender, EventArgs e)
{
WorkflowRuntime WFRuntime = new WorkflowRuntime();
WFRuntime.StartRuntime();
ExternalDataExchangeService edx = new ExternalDataExchangeService();
WFRuntime.AddService(edx);
edx.AddService(new ApproveReq ());
Anada.AbsenceManager.Workflow.Model.Request Req = new Anada.AbsenceManager.Workflow.Model.Request();
Req.RequestId = 1;
Req.EmployeeId = 1;
Req.BossId = 3 ;
Req.StartDate = DateTime.Now;
Req.EndDate = DateTime.Now.AddDays(5);
Req.RequestStateId = 4;
Req.RequestTypeId = 1;
Req.UserName = "Prakash";
Req.CreateDate = DateTime.Now;
Req.ModifyDate = DateTime.Now;
Req.RequestDate = DateTime.Now;
Dictionary paras = new Dictionary();
//paras.Add("CountryID", Convert.ToInt32(txtCountryID .Text));
//paras.Add("mPersonId", Convert.ToInt32(txtPersonId .Text));
//paras.Add("CalendarId",Convert.ToInt32(txtCalendarId .Text));
//paras.Add("username", "Prakash");
//paras.Add("FromDate", Req.StartDate);
//paras.Add("ToDate", Req.EndDate);
//paras.Add("FromDate", Convert.ToDateTime(txtFromDate.Text));
paras.Add("mAppRequest", Req);
////WFSvc.WorkFlowSVCClient obj = new WFSvc.WorkFlowSVCClient();
////obj.GetRequestWFInstance(Anada.AbsenceManager.Workflow.Flows.Request mrequest, ////paras);
WorkflowInstance instance = WFRuntime.CreateWorkflow(typeof(Anada.AbsenceManager.Workflow.Flows.ApproveRequest), paras);
//instance.Start();
}

Monday, November 24, 2008

Custom Code activitys parameters validation

This is the code for validating the parameters of custom code activitys.
Use the validation manager class.
Here testing the Mail objects.
and in activity we have to use the attribute like....

[ActivityValidator (typeof (Anada.AbsenceManager.Workflow.Activity.CalendarPersonIDValidation ))]

public class SendMailValidation : ActivityValidator
{
#region"SendMailActivityParameterValidation"
//
// Method used to validate TO and From Email address
//

//
//
public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
{
ValidationErrorCollection ValidationErrors = new ValidationErrorCollection(base.ValidateProperties(manager, obj));
SendMailActivity SendMailActivityTobeValidated = new SendMailActivity();
if (SendMailActivityTobeValidated == null)
{
throw new InvalidOperationException("Parameter obj is not of type SendMailActivity");
}
if (!IsValidEmailAddress(SendMailActivityTobeValidated.To))
{
ValidationError CustomActivityValidationError = new ValidationError(string.Format("\'{0}\' is an Invalid destination e-mail address", SendMailActivityTobeValidated.To), 1);
ValidationErrors.Add(CustomActivityValidationError);
}
if (!IsValidEmailAddress(SendMailActivityTobeValidated.From))
{
ValidationError CustomActivityValidationError = new ValidationError(string.Format("\'{0}\' is an Invalid destination e-mail address", SendMailActivityTobeValidated.From), 1);
ValidationErrors.Add(CustomActivityValidationError);
}

return ValidationErrors;
}
public Boolean IsValidEmailAddress(String address)
{
//
// Method used to check the length and formate of Email address
//

//
//
// must only proceed with validation if we have data
// to validate
if (address == null address.Length == 0)
return true;
Regex rx = new Regex(@"[^A-Za-z0-9@\-_.]", RegexOptions.Compiled);
MatchCollection matches = rx.Matches(address);
if (matches.Count > 0)
return false;
// Must have an '@' character
int i = address.IndexOf('@');
// Must be at least three chars after the @
if (i <= 0 i >= address.Length - 3)
return false;
// Must only be one '@' character
if (address.IndexOf('@', i + 1) >= 0)
return false;
// Find the last . in the address
int j = address.LastIndexOf('.');
// The dot can't be before or immediately after the @ char
if (j >= 0 && j <= i + 1)
return false;
return true;
}
#endregion
}

Thursday, November 20, 2008

setting Icons to Code activity and designer theme

First To set the Icon to Activity set the property to "EmbededResourse" . Code comes here.
#region look n feel
internal sealed class ApproveRequestCustomActivityDesignerTheme : ActivityDesignerTheme { public ApproveRequestCustomActivityDesignerTheme(WorkflowTheme theme) : base(theme) { this.BorderColor = Color.Chocolate ;
this.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid;//DashStyle.Solid;
this.BackColorStart = Color.BurlyWood ;
this.BackColorEnd = Color.CornflowerBlue;
this.BackgroundStyle = System.Drawing.Drawing2D.LinearGradientMode.Vertical; //LinearGradientMode.Vertical; } } [ActivityDesignerThemeAttribute(typeof(ApproveRequestCustomActivityDesignerTheme))] public class ApproveRequestCustomActivityDesigner : ActivityDesigner { } #endregion [ToolboxItemAttribute(typeof(ActivityToolboxItem))] [Designer(typeof(ApproveRequestCustomActivityDesigner), typeof(IDesigner))] [ToolboxBitmap(typeof(ApproveRequestActivity), "Resources.ApprovalReq.bmp")]

Wednesday, November 19, 2008

F11 Debugging is not working in .Net

Hi,
In visual studio while debugging the workflows its not going inside the workflow...

Wednesday, October 22, 2008

WPF And XAML

Windows Presentation Foundation (WPF) is the code-name of the presentation (user-interfaces) sub system in Windows Vista programming model and is used to create user interfaces. This blog talks about WPF.
What is WPF?
WPF is the engine that is responsible for creating, displaying, and manipulating user-interfaces, documents, images, movies, and media in Windows Vista.
Physically, WPF is a set of libraries that have all functionalty you need to build, run, execute, and manage Windows Vista applications.
What is XAML?
XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next generation managed applications.
How XAML is related to WPF?
XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next generation managed applications. XAML is used in WPF to represent the controls and code with the help of C#, Visual Basic, and other .NET Framework languages.

XAML can be think as ASP.NET and/or Windows Forms in Windows Vista. For example, to write a Web application in .NET 1.0, 1.1, or 2.0, you use ASP.NET and to write Windows Applications, you use Windows Forms. Now in Windows Vista and .NET 3.0, you will use XAML instead of Windows Forms and ASP.NET.

Does that mean XAML will replace ASP.NET and Windows Forms? YES and NO. Both ASP.NET and Windows Forms will also be supported on .NET 3.0 but you don't have to use them if you don't want.
What Operating Systems does WPF support?
Windows Vista, Windows XP, and Windows 2003 Server.
How do I build WPF Applicaitons?
To build WPF application, you must install .NET 3.0 SDK. It can be found on MSDN downloads sites.
What do I need to run WPF Applications?
To run WPF applications, you must install .NET 3.0 SDK redistributable. It can be found on MSDN downloads sites.

WCF Contracts

The WCF way to generate an XML schema from a CLR type is with a data contract. Data contracts describe how a CLR type maps to schema with an opt-in approach. The XmlFormatter uses the information provided in a data contract to handle serialization and deserialization. This allows developers to work with familiar objects at runtime, while the WCF runtime hides the XML goo. The XmlFormatter is the successor of the XmlSerializer for WCF services - with the exception that currently, the XmlSerializer still provides more granular control over object serialization to XML. As such there will still be cases where you will still want to use the XmlSerializer, for now.
Creating a Data Contract
First you decorate the type with the DataContractAttribute, then you select members to include in serialization with the DataMemberAttribute. Listing 3 illustrates the LinkItem type mentioned earlier, as a data contract.


Service Contracts
In the WCF, service contracts describe the operations supported by a service, the message exchange pattern they use, and the format of each message. The service contract is the driver for generating a service description – so a service must implement at least one service contract. To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface with the ServiceContractAttribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the OperationContractAttribute. Listing 1 illustrates the use of these attributes

Wednesday, September 24, 2008

Constructors in C#

The call to the constructors is completely governed by the rules of the overloading here.
Calling Constructor from another Constructor:
You can always make the call to one constructor from within the other. Say for example :


public class mySampleClass
{
public mySampleClass(): this(10)
{// This is the no parameter constructor method.// First Constructor}
public mySampleClass(int Age)
{// This is the constructor with one parameter.// Second Constructor}}
Very first of all let us see what is this syntax :
public mySampleClass(): this(10)


Static Constroctor:
This is a new concept introduced in C#. By new here I mean that it was not available for the C++ developers. This is a special constructor and gets called before the first object is created of the class. The time of execution cannot be determined, but it is definitely before the first object creation - could be at the time of loading the assembly.Static Constructors :


public class myClass
{
static myClass()
{// Initialization code goes here.// Can only access static members here.}// Other class methods goes here}

Notes for Static Constructors :
1. There can be only one static constructor in the class.
2. The static constructor should be without parameters.
3. It can only access the static members of the class.
4. There should be no access modifier in static constructor definition

Firstly, the call to the static method is made by the CLR and not by the object, so we do not need to have the access modifier to it.

Secondly, it is going to be called by CLR, who can pass the parameters to it, if required, No one, so we cannot have parameterized static constructor.

Thirdly, Non-static members in the class are specific to the object instance so static constructor, if allowed to work on non-static members, will reflect the changes in all the object instances, which is impractical. So static constructor can access only static members of the class.

Fourthly, Overloading needs the two methods to be different in terms to methods definition, which you cannot do with Static Constructors, so you can have at the most one static constructor in the class.

4. Can we access static members from the non-static ( normal ) constructors ?
Yes, We can. There is no such restriction on non-static constructors. But there is one on static constructors that it can access only static members.

3. What if I have the constructor public myDerivedClass() but not the public myBaseClass() ?
It will raise an error. If either the no parameter constructor is absent or it is in-accessible ( say it is private ), it will raise an error. You will have to take the precaution here.

Friday, September 19, 2008

Windows Process has been Shut down..(Blue screen error)

Hello,
My System has not shutting down. when ever i try ... it s showing Windows process has been shut down with blue screen..I think winlogon file has corrupted in registry.
I don t know the solution for this...

Tuesday, September 16, 2008

Difference between Webservice ,Remoting , WCF.Net 3.5

Web Services..
1.It Can be accessed only over HTTP
2.It works in stateless environment
3.It support only the datatypes defined in the XSD type system, limiting the number of objects that can be serialized.
4.It support interoperability across platforms, and are ideal for heterogeneous environments.

.Net Remoting..
1.It Can be accessed over any protocol
2.Provide support for both stateful and stateless environments through Singleton and SingleCall objects
3.Using binary communication, .NET Remoting can provide support for rich type system
4.It requires the client be built using .NET, enforcing homogenous environment.

WCF is the Windows Communication Foundation which is shipped along with Dot Net 3.0/3.5. User's having 2.0 framework can make use of WCF by installing the MS add-in component for WCF. WCF comes up as a replacement for Remoting and Web service in dotnet.
The main feature of WCF is it's security. It can use the protocols like basice,wsHttp,tcp...wsHttp comes with default windows based security feature. WRT web services WCF works with the industry standard Contract based protocols.
The componets WCF are data contract, Service Contract and the Service programme. WCF also supports many of the advanced WS-* Web service standards, which can provide rich Web service communication across platforms. WCF can be extended to use protocols other than SOAP to communicate with Web services, for example, Rich Site Summary (RSS). It is interoperable with WSE 3.0, System.Messaging, .NET Enterprise Services, and ASMX Web services.This means that, with little or no change to code, existing applications that are built with these technologies can interoperate with WCF services. WCF contracts define the behavior of WCF services. They are created in code by service developers, and are exposed to clients in the service metadata.

The five types of contracts:
Service Contracts
Operation Contracts
Data Contracts
Message Contracts
Fault Contracts

WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services:IISWASSelf-hostingManaged Windows Service