private static void ProcessChildActivity(WorkflowDescription wfDescription, Activity activity, DataTable dt) { DataRow row = dt.NewRow(); row["Id"] = activity.QualifiedName; row["Number"] = dt.Rows.Count + 1; row["ReadOnlyLibraryAccess"] = false; if (activity is SequentialWorkflowActivity) { row["Subject"] = wfDescription.Name; row["IsBlock"] = true; } else if (activity is StateMachineWorkflowActivity) { row["Subject"] = wfDescription.Name; row["IsBlock"] = true; } else if (activity is BlockActivity) { if (((BlockActivity)activity).Type == BlockActivityType.All) { row["Subject"] = "{IbnFramework.BusinessProcess:BlockActivityTypeAll}"; } else { row["Subject"] = "{IbnFramework.BusinessProcess:BlockActivityTypeAny}"; } row["IsBlock"] = true; } else if (activity is CreateAssignmentAndWaitResultActivity) { PropertyValueCollection properties = ((CreateAssignmentAndWaitResultActivity)activity).AssignmentProperties; row["Subject"] = properties[AssignmentEntity.FieldSubject].ToString(); row["User"] = (int)properties[AssignmentEntity.FieldUserId]; if (properties[AssignmentEntity.FieldPlanFinishDate] != null) { row["DueDate"] = (DateTime)properties[AssignmentEntity.FieldPlanFinishDate]; } if (properties["ReadOnlyLibraryAccess"] != null) { row["ReadOnlyLibraryAccess"] = (bool)properties["ReadOnlyLibraryAccess"]; } row["IsBlock"] = false; } if (row["Subject"] == DBNull.Value) { row["Subject"] = "{IbnFramework.BusinessProcess:NoSubject}"; } row["State"] = GetActivityStatus(wfDescription, activity); dt.Rows.Add(row); }
/// <summary> /// Gets the activity list. /// </summary> /// <param name="activityRoot">The activity root.</param> /// <returns></returns> public static DataTable GetActivityList(WorkflowDescription wfDescription, object activityRoot) { DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add("Id", typeof(string)); dt.Columns.Add("Number", typeof(int)); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("User", typeof(int)); dt.Columns.Add("DueDate", typeof(DateTime)); dt.Columns.Add("State", typeof(ActivityStatus)); dt.Columns.Add("IsBlock", typeof(bool)); dt.Columns.Add("Level", typeof(int)); ProcessActivity(wfDescription, (Activity)activityRoot, dt, 0); return(dt); }
public static DataTable GetChildActivityList(WorkflowDescription wfDescription, object activity) { DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add("Id", typeof(string)); dt.Columns.Add("Number", typeof(int)); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("User", typeof(int)); dt.Columns.Add("DueDate", typeof(DateTime)); dt.Columns.Add("State", typeof(ActivityStatus)); dt.Columns.Add("IsBlock", typeof(bool)); dt.Columns.Add("ReadOnlyLibraryAccess", typeof(bool)); if (activity is SequentialWorkflowActivity) { SequentialWorkflowActivity block = (SequentialWorkflowActivity)activity; foreach (Activity child in block.Activities) { ProcessChildActivity(wfDescription, child, dt); } } else if (activity is StateMachineWorkflowActivity) { StateMachineWorkflowActivity block = (StateMachineWorkflowActivity)activity; foreach (Activity child in block.Activities) { ProcessChildActivity(wfDescription, child, dt); } } else if (activity is BlockActivity) { BlockActivity block = (BlockActivity)activity; foreach (Activity child in block.Activities) { ProcessChildActivity(wfDescription, child, dt); } } return(dt); }
/// <summary> /// Gets the activity status. /// </summary> /// <param name="workflowInstance">The workflow instance.</param> /// <param name="activity">The activity.</param> /// <returns></returns> private static ActivityStatus GetActivityStatus(WorkflowDescription wfDescription, Activity activity) { if (!wfDescription.InstanceId.HasValue) { return(ActivityStatus.Initialized); } if (IsWorkflowInstanceClosed(wfDescription.InstanceId.Value)) { return(ActivityStatus.Closed); } if (activity is BlockActivity) { if (((BlockActivity)activity).Activities.Count > 0) { ActivityStatus retVal = ActivityStatus.Initialized; foreach (Activity child in ((BlockActivity)activity).Activities) { ActivityStatus childStatus = GetActivityStatus(wfDescription, child); if (childStatus == ActivityStatus.Executing) { return(ActivityStatus.Executing); } if (childStatus == ActivityStatus.Closed) { retVal = ActivityStatus.Closed; } } return(retVal); } else { int index = activity.Parent.Activities.IndexOf(activity); if ((index > 0 && GetActivityStatus(wfDescription, activity.Parent.Activities[index - 1]) == ActivityStatus.Closed ) || ((index + 1) < activity.Parent.Activities.Count && GetActivityStatus(wfDescription, activity.Parent.Activities[index + 1]) == ActivityStatus.Closed)) { return(ActivityStatus.Closed); } return(ActivityStatus.Initialized); } } else { EntityObject[] assignments = BusinessManager.List(AssignmentEntity.ClassName, new FilterElement[] { FilterElement.EqualElement(AssignmentEntity.FieldWorkflowInstanceId, (PrimaryKeyId)wfDescription.InstanceId) }); foreach (AssignmentEntity assg in assignments) { if (assg.WorkflowActivityName == activity.Name) { return(assg.ExecutionResult.HasValue ? ActivityStatus.Closed : ActivityStatus.Executing); } } } //try //{ // WorkflowInstance innerInstance = GlobalWorkflowRuntime.WorkflowRuntime.GetWorkflow((Guid)workflowInstance.PrimaryKeyId.Value); // return (ActivityStatus)(int)innerInstance.GetWorkflowDefinition().GetActivityByName(activity.QualifiedName).ExecutionStatus; //} //catch (Exception ex) //{ // Trace.WriteLine(ex, "WfActivityWrapper"); //} return(ActivityStatus.Initialized); }
private static void ProcessChildActivity(WorkflowDescription wfDescription, Activity activity, DataTable dt) { DataRow row = dt.NewRow(); row["Id"] = activity.QualifiedName; row["Number"] = dt.Rows.Count + 1; row["ReadOnlyLibraryAccess"] = false; if (activity is SequentialWorkflowActivity) { row["Subject"] = wfDescription.Name; row["IsBlock"] = true; } else if (activity is StateMachineWorkflowActivity) { row["Subject"] = wfDescription.Name; row["IsBlock"] = true; } else if (activity is BlockActivity) { if (((BlockActivity)activity).Type == BlockActivityType.All) row["Subject"] = "{IbnFramework.BusinessProcess:BlockActivityTypeAll}"; else row["Subject"] = "{IbnFramework.BusinessProcess:BlockActivityTypeAny}"; row["IsBlock"] = true; } else if (activity is CreateAssignmentAndWaitResultActivity) { PropertyValueCollection properties = ((CreateAssignmentAndWaitResultActivity)activity).AssignmentProperties; row["Subject"] = properties[AssignmentEntity.FieldSubject].ToString(); row["User"] = (int)properties[AssignmentEntity.FieldUserId]; if (properties[AssignmentEntity.FieldPlanFinishDate] != null) row["DueDate"] = (DateTime)properties[AssignmentEntity.FieldPlanFinishDate]; if (properties["ReadOnlyLibraryAccess"] != null) row["ReadOnlyLibraryAccess"] = (bool)properties["ReadOnlyLibraryAccess"]; row["IsBlock"] = false; } if (row["Subject"] == DBNull.Value) row["Subject"] = "{IbnFramework.BusinessProcess:NoSubject}"; row["State"] = GetActivityStatus(wfDescription, activity); dt.Rows.Add(row); }
public static DataTable GetChildActivityList(WorkflowDescription wfDescription, object activity) { DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add("Id", typeof(string)); dt.Columns.Add("Number", typeof(int)); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("User", typeof(int)); dt.Columns.Add("DueDate", typeof(DateTime)); dt.Columns.Add("State", typeof(ActivityStatus)); dt.Columns.Add("IsBlock", typeof(bool)); dt.Columns.Add("ReadOnlyLibraryAccess", typeof(bool)); if (activity is SequentialWorkflowActivity) { SequentialWorkflowActivity block = (SequentialWorkflowActivity)activity; foreach (Activity child in block.Activities) ProcessChildActivity(wfDescription, child, dt); } else if (activity is StateMachineWorkflowActivity) { StateMachineWorkflowActivity block = (StateMachineWorkflowActivity)activity; foreach (Activity child in block.Activities) ProcessChildActivity(wfDescription, child, dt); } else if (activity is BlockActivity) { BlockActivity block = (BlockActivity)activity; foreach (Activity child in block.Activities) ProcessChildActivity(wfDescription, child, dt); } return dt; }
/// <summary> /// Gets the activity status. /// </summary> /// <param name="workflowInstance">The workflow instance.</param> /// <param name="activity">The activity.</param> /// <returns></returns> private static ActivityStatus GetActivityStatus(WorkflowDescription wfDescription, Activity activity) { if(!wfDescription.InstanceId.HasValue) return ActivityStatus.Initialized; if (IsWorkflowInstanceClosed(wfDescription.InstanceId.Value)) return ActivityStatus.Closed; if (activity is BlockActivity) { if (((BlockActivity)activity).Activities.Count > 0) { ActivityStatus retVal = ActivityStatus.Initialized; foreach (Activity child in ((BlockActivity)activity).Activities) { ActivityStatus childStatus = GetActivityStatus(wfDescription, child); if (childStatus == ActivityStatus.Executing) return ActivityStatus.Executing; if (childStatus == ActivityStatus.Closed) retVal = ActivityStatus.Closed; } return retVal; } else { int index = activity.Parent.Activities.IndexOf(activity); if ((index > 0 && GetActivityStatus(wfDescription, activity.Parent.Activities[index - 1]) == ActivityStatus.Closed )|| ((index + 1) < activity.Parent.Activities.Count && GetActivityStatus(wfDescription, activity.Parent.Activities[index + 1]) == ActivityStatus.Closed)) return ActivityStatus.Closed; return ActivityStatus.Initialized; } } else { EntityObject[] assignments = BusinessManager.List(AssignmentEntity.ClassName, new FilterElement[] { FilterElement.EqualElement(AssignmentEntity.FieldWorkflowInstanceId, (PrimaryKeyId)wfDescription.InstanceId) }); foreach (AssignmentEntity assg in assignments) { if (assg.WorkflowActivityName == activity.Name) { return assg.ExecutionResult.HasValue ? ActivityStatus.Closed : ActivityStatus.Executing; } } } //try //{ // WorkflowInstance innerInstance = GlobalWorkflowRuntime.WorkflowRuntime.GetWorkflow((Guid)workflowInstance.PrimaryKeyId.Value); // return (ActivityStatus)(int)innerInstance.GetWorkflowDefinition().GetActivityByName(activity.QualifiedName).ExecutionStatus; //} //catch (Exception ex) //{ // Trace.WriteLine(ex, "WfActivityWrapper"); //} return ActivityStatus.Initialized; }
/// <summary> /// Gets the activity list. /// </summary> /// <param name="activityRoot">The activity root.</param> /// <returns></returns> public static DataTable GetActivityList(WorkflowDescription wfDescription, object activityRoot) { DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add("Id", typeof(string)); dt.Columns.Add("Number", typeof(int)); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("User", typeof(int)); dt.Columns.Add("DueDate", typeof(DateTime)); dt.Columns.Add("State", typeof(ActivityStatus)); dt.Columns.Add("IsBlock", typeof(bool)); dt.Columns.Add("Level", typeof(int)); ProcessActivity(wfDescription, (Activity)activityRoot, dt, 0); return dt; }
private void BindData() { SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(instance.SchemaId); object rootActivity = McWorkflowSerializer.GetObject(instance.Xaml); WorkflowDescription wfDescription = new WorkflowDescription((Guid)instance.PrimaryKeyId.Value, instance.Name, currentShemaMaster, rootActivity); ActivityGrid.DataSource = WorkflowActivityWrapper.GetActivityList(wfDescription, rootActivity); ActivityGrid.DataBind(); }
private void LoadControlToPlaceHolder(bool bindData) { if (MainPlaceHolder.Controls.Count > 0) MainPlaceHolder.Controls.Clear(); if (!String.IsNullOrEmpty(ControlName)) { MCDataSavedControl control = (MCDataSavedControl)LoadControl(ControlName); control.ID = "MCControl"; MainPlaceHolder.Controls.Add(control); if (bindData) { if (instance != null) // create from instance { SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(instance.SchemaId); object rootActivity = McWorkflowSerializer.GetObject(instance.Xaml); WorkflowDescription wfDescription = new WorkflowDescription(Guid.NewGuid(), instance.Name, currentShemaMaster, rootActivity); wfDescription.PlanFinishTimeType = (TimeType)instance.PlanFinishTimeType; int duration = 60 * 24; // 1 day if (instance.PlanDuration.HasValue && instance.PlanDuration.Value > 0) duration = instance.PlanDuration.Value; wfDescription.PlanDuration = duration; wfDescription.PlanFinishDate = instance.PlanFinishDate; control.DataItem = wfDescription; } else if (template != null) // edit { SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(template.SchemaId); object rootActivity = McWorkflowSerializer.GetObject(template.Xaml); WorkflowDescription wfDescription = new WorkflowDescription((Guid)template.PrimaryKeyId.Value, template.Name, currentShemaMaster, rootActivity); wfDescription.PlanFinishTimeType = (TimeType)template.PlanFinishTimeType; int duration = 60 * 24; // 1 day if (template.PlanDuration.HasValue && template.PlanDuration.Value > 0) duration = template.PlanDuration.Value; wfDescription.PlanDuration = duration; wfDescription.PlanFinishDate = template.PlanFinishDate; control.DataItem = wfDescription; } else { control.DataItem = null; } control.DataBind(); } } }
protected void SaveButton_ServerClick(object sender, EventArgs e) { if (template != null) // edit { // Step 1. Modify template template.Name = NameText.Text.Trim(); template.Description = DescriptionText.Text; SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(template.SchemaId); object rootActivity = McWorkflowSerializer.GetObject(template.Xaml); if (ProjectControl.ObjectId > 0) template.ProjectId = ProjectControl.ObjectId; else template.ProjectId = null; // Object types List<int> selectedObjectTypes = new List<int>(); if (DocumentCheckBox.Enabled && DocumentCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.Document); if (TaskCheckBox.Enabled && TaskCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.Task); if (TodoCheckBox.Enabled && TodoCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.ToDo); if (IncidentCheckBox.Enabled && IncidentCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.Issue); template.SupportedIbnObjectTypes = selectedObjectTypes.ToArray(); // Step 2. Create WorkflowDescription WorkflowDescription wfDescription = new WorkflowDescription((Guid)template.PrimaryKeyId.Value, template.Name, currentShemaMaster, rootActivity); // Step 3. Apply Modifications if (MainPlaceHolder.Controls.Count > 0) { MCDataSavedControl control = (MCDataSavedControl)MainPlaceHolder.Controls[0]; control.Save(wfDescription); } template.PlanFinishTimeType = (int)wfDescription.PlanFinishTimeType; if (wfDescription.PlanFinishTimeType == TimeType.Duration) { template.PlanDuration = wfDescription.PlanDuration; template.PlanFinishDate = null; } else if (wfDescription.PlanFinishTimeType == TimeType.DateTime) { template.PlanFinishDate = wfDescription.PlanFinishDate; template.PlanDuration = null; } template.Xaml = McWorkflowSerializer.GetString(wfDescription.TransientWorkflow); // Template Group if (TemplateGroupValue != null) template.TemplateGroup = (int)TemplateGroupValue; // Lock Library WorkflowParameters.SetOwnerReadOnly(template, LockLibraryCheckBox.Checked); // Overdue Action WorkflowParameters.SetAssignmentOverdueAction(template, (AssignmentOverdueAction)int.Parse(AssignmentOverdueActionList.SelectedValue)); BusinessManager.Update(template); } else // new or create from instance { // Step 1. Initialize a new template template = BusinessManager.InitializeEntity<WorkflowDefinitionEntity>(WorkflowDefinitionEntity.ClassName); template.Name = NameText.Text.Trim(); template.Description = DescriptionText.Text; template.SchemaId = new Guid(SchemaMasterList.SelectedValue); SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(template.SchemaId); object rootActivity = currentShemaMaster.InstanceFactory.CreateInstance(); if (ProjectControl.ObjectId > 0) template.ProjectId = ProjectControl.ObjectId; // Object types List<int> selectedObjectTypes = new List<int>(); if (DocumentCheckBox.Enabled && DocumentCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.Document); if (TaskCheckBox.Enabled && TaskCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.Task); if (TodoCheckBox.Enabled && TodoCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.ToDo); if (IncidentCheckBox.Enabled && IncidentCheckBox.Checked) selectedObjectTypes.Add((int)ObjectTypes.Issue); template.SupportedIbnObjectTypes = selectedObjectTypes.ToArray(); // Step 2. Create WorkflowDescription WorkflowDescription wfDescription = new WorkflowDescription(template.Name, currentShemaMaster, rootActivity); // Step 3. Apply Modifications if (MainPlaceHolder.Controls.Count > 0) { MCDataSavedControl control = (MCDataSavedControl)MainPlaceHolder.Controls[0]; control.Save(wfDescription); } template.PlanFinishTimeType = (int)wfDescription.PlanFinishTimeType; if (wfDescription.PlanFinishTimeType == TimeType.Duration) { template.PlanDuration = wfDescription.PlanDuration; template.PlanFinishDate = null; } else if (wfDescription.PlanFinishTimeType == TimeType.DateTime) { template.PlanFinishDate = wfDescription.PlanFinishDate; template.PlanDuration = null; } template.Xaml = McWorkflowSerializer.GetString(wfDescription.TransientWorkflow); // Template Group if (TemplateGroupValue != null) template.TemplateGroup = (int)TemplateGroupValue; // Lock Library WorkflowParameters.SetOwnerReadOnly(template, LockLibraryCheckBox.Checked); // Overdue Action WorkflowParameters.SetAssignmentOverdueAction(template, (AssignmentOverdueAction)int.Parse(AssignmentOverdueActionList.SelectedValue)); BusinessManager.Create(template); } // Step Final. Redirect RedirectToList(); }
protected void SaveButton_ServerClick(object sender, EventArgs e) { if (ObjectId != PrimaryKeyId.Empty) // edit { // Step 1. Modify instance instance.Name = NameText.Text.Trim(); instance.Description = DescriptionText.Text; // Step 2. Create WorkflowChangesScope using (WorkflowChangesScope scope = WorkflowChangesScope.Create(instance)) { SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(instance.SchemaId); WorkflowDescription wfDescription = new WorkflowDescription((Guid)instance.PrimaryKeyId.Value, instance.Name, currentShemaMaster, scope.TransientWorkflow); // Step 3. Apply Modifications if (MainPlaceHolder.Controls.Count > 0) { MCDataSavedControl control = (MCDataSavedControl)MainPlaceHolder.Controls[0]; control.Save(wfDescription); } instance.PlanFinishTimeType = (int)wfDescription.PlanFinishTimeType; if (wfDescription.PlanFinishTimeType == TimeType.Duration) instance.PlanDuration = wfDescription.PlanDuration; else if (wfDescription.PlanFinishTimeType == TimeType.DateTime) instance.PlanFinishDate = wfDescription.PlanFinishDate; // Lock Library WorkflowParameters.SetOwnerReadOnly(instance, LockLibraryCheckBox.Checked); // Overdue Action WorkflowParameters.SetAssignmentOverdueAction(instance, (AssignmentOverdueAction)int.Parse(AssignmentOverdueActionList.SelectedValue)); // Step 4. Accept Changes scope.ApplyWorkflowChanges(); } } else // new or duplicate { // Step 1. Initialize a new instance instance = BusinessManager.InitializeEntity<WorkflowInstanceEntity>(WorkflowInstanceEntity.ClassName); instance.Name = NameText.Text.Trim(); instance.Description = DescriptionText.Text; if (!String.IsNullOrEmpty(OwnerName) && OwnerId > 0) instance[OwnerName] = OwnerId; instance.SchemaId = new Guid(SchemaMasterList.SelectedValue); SchemaMaster currentShemaMaster = SchemaManager.GetShemaMaster(instance.SchemaId); object rootActivity = currentShemaMaster.InstanceFactory.CreateInstance(); instance.Xaml = McWorkflowSerializer.GetString(rootActivity); // Step 2. Create WorkflowChangesScope WorkflowDescription wfDescription = new WorkflowDescription(instance.Name, currentShemaMaster, rootActivity); // Step 3. Apply Modifications if (MainPlaceHolder.Controls.Count > 0) { MCDataSavedControl control = (MCDataSavedControl)MainPlaceHolder.Controls[0]; control.Save(wfDescription); } instance.PlanFinishTimeType = (int)wfDescription.PlanFinishTimeType; if (wfDescription.PlanFinishTimeType == TimeType.Duration) instance.PlanDuration = wfDescription.PlanDuration; else if (wfDescription.PlanFinishTimeType == TimeType.DateTime) instance.PlanFinishDate = wfDescription.PlanFinishDate; // Lock Library WorkflowParameters.SetOwnerReadOnly(instance, LockLibraryCheckBox.Checked); // Overdue Action WorkflowParameters.SetAssignmentOverdueAction(instance, (AssignmentOverdueAction)int.Parse(AssignmentOverdueActionList.SelectedValue)); // Step 4. Accept Changes instance.Xaml = McWorkflowSerializer.GetString(wfDescription.TransientWorkflow); BusinessManager.Create(instance); } // Final Redirect RedirectToOwner(); }