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...