/// <summary> /// Loads the file library acl. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> private bool LoadFileLibraryAcl(WorkflowInstanceEntity entity, out FileStorage fs, out AccessControlList acl) { acl = null; fs = null; // Resolve ContainerKey string containerName = "FileLibrary"; string containerKey = string.Empty; if (entity.OwnerDocumentId.HasValue) { containerKey = UserRoleHelper.CreateDocumentContainerKey(entity.OwnerDocumentId.Value); } //else // TODO: Extend Owner Processing // Check ContainerKey if (string.IsNullOrEmpty(containerKey)) { return(false); } // Open ACL BaseIbnContainer bic = BaseIbnContainer.Create(containerName, containerKey); fs = (FileStorage)bic.LoadControl("FileStorage"); acl = AccessControlList.GetACL(fs.Root.Id); return(true); }
public void Invoke(object Sender, object Element) { NameValueCollection qs = ((Control)Sender).Page.Request.QueryString; if (!String.IsNullOrEmpty(qs["ObjectId"])) { WorkflowInstanceEntity entity = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, PrimaryKeyId.Parse(qs["ObjectId"])); if (entity != null) { if (entity.OwnerDocumentId.HasValue) { ((Control)Sender).Page.Response.Redirect(CHelper.GetLinkObjectViewByOwnerName("ownerdocumentid", entity.OwnerDocumentId.ToString())); } } } if (!String.IsNullOrEmpty(qs["Id"])) { WorkflowInstanceEntity entity = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, PrimaryKeyId.Parse(qs["Id"])); if (entity != null) { if (entity.OwnerDocumentId.HasValue) { ((Control)Sender).Page.Response.Redirect(CHelper.GetLinkObjectViewByOwnerName("ownerdocumentid", entity.OwnerDocumentId.ToString())); } } } }
public async Task <WorkflowInstanceEntity> Add(WorkflowInstanceEntity entity) { entity.Id = Guid.NewGuid(); foreach (var item in entity.Activities) { item.WorkflowInstance = entity.Id; } foreach (var item in entity.BlockingActivities) { item.WorkflowInstance = entity.Id; } using var uow = _elsaDbContext.NewUnitOfWork(); if (!await _repository.AddAsync(entity, uow)) { throw new Exception("Ìí¼Óʧ°Ü"); } if (entity.Activities.Any()) { if (!await _activityInstanceRepository.BatchInsertAsync(entity.Activities.ToList(), uow)) { throw new Exception("Ìí¼Óʧ°Ü"); } } if (entity.BlockingActivities.Any()) { if (!await _blockingActivityRepository.BatchInsertAsync(entity.BlockingActivities.ToList(), uow)) { throw new Exception("Ìí¼Óʧ°Ü"); } } uow.Commit(); return(entity); }
protected void Page_Load(object sender, EventArgs e) { if (ObjectId != PrimaryKeyId.Empty) { instance = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, ObjectId); } else if (FromId != PrimaryKeyId.Empty) { instance = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, FromId); } if (!IsPostBack) { BindInfo(); BindData(); // disable Save button for completed business-process if (ObjectId != PrimaryKeyId.Empty && instance.State == (int)BusinessProcessState.Closed) { SaveButton.Disabled = true; } } LoadControlToPlaceHolder(!IsPostBack); BindToolbar(); }
private void Insert(IWorkflowInstance workflowInstance, DbContext dbContext) { var wfInstanceMapper = new WorkflowInstanceEntityMapper(dbContext); var instanceEntity = new WorkflowInstanceEntity { CREATED_ON = DateTime.Now, LAST_UPDATED_ON = DateTime.Now, FORM_TYPE = workflowInstance.Form.FormType, FORM_ID = workflowInstance.Form.FormId, OWNER_ID = workflowInstance.Owner.ApproverId, INSTANCE_VERSION = DateTime.Now, STATUS = 1, WORKFLOW_INSTANCE_ID = workflowInstance.WorkflowInstanceId, WORKFLOW_TEMPLATE_ID = workflowInstance.WorkflowTemplate.TemplateUuid }; wfInstanceMapper.Insert(instanceEntity); var bookmark = CreateBookMark(workflowInstance); SetBookMark(bookmark, dbContext); //新创建的workflow instance没有previous节点需要持久化 SaveActivityInstance(workflowInstance.Current, workflowInstance.WorkflowInstanceId, dbContext); workflowInstance.MarkOld(); }
/// <summary> /// Creates the workflow participiant. /// </summary> /// <param name="workflowInstanceId">The workflow instance id.</param> /// <param name="userId">The user id.</param> /// <param name="entity">The entity.</param> private void CreateWorkflowParticipiant(Guid workflowInstanceId, int userId, WorkflowInstanceEntity entity) { WorkflowParticipantRow row = new WorkflowParticipantRow(); row.UserId = userId; row.WorkflowInstanceId = workflowInstanceId; // TODO: Extend Owner Processing row.ObjectId = entity.OwnerDocumentId.Value; row.ObjectType = (int)ObjectTypes.Document; row.Update(); }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute(BusinessContext context) { WorkflowInstanceEntity entityObject = (WorkflowInstanceEntity)BusinessManager.Load(context.GetTargetMetaClassName(), context.GetTargetPrimaryKeyId().Value); if (entityObject.OwnerDocumentId.HasValue) { Document.SetReadOnly( entityObject.OwnerDocumentId.Value, false); } // TODO: Add New Owner Here }
public override void DataBind() { DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add("AssignmentId", typeof(string)); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("User", typeof(string)); dt.Columns.Add("State", typeof(string)); dt.Columns.Add("Result", typeof(int)); dt.Columns.Add("FinishDate", typeof(string)); dt.Columns.Add("Comment", typeof(string)); dt.Columns.Add("Indent", typeof(int)); dt.Columns.Add("ClosedBy", typeof(string)); WorkflowInstanceEntity wfEntity = (WorkflowInstanceEntity)DataItem; // Filter: // 1: WorkflowInstanceId = wfEntity.PrimaryKeyId, // 2: ParentAssignmentId IS NULL (other elements we'll get via the recursion) FilterElementCollection fec = new FilterElementCollection(); fec.Add(FilterElement.EqualElement(AssignmentEntity.FieldWorkflowInstanceId, wfEntity.PrimaryKeyId.Value)); fec.Add(FilterElement.IsNullElement(AssignmentEntity.FieldParentAssignmentId)); // Sorting SortingElementCollection sec = new SortingElementCollection(); sec.Add(new SortingElement(AssignmentEntity.FieldCreated, SortingElementType.Asc)); EntityObject[] assignments = BusinessManager.List(AssignmentEntity.ClassName, fec.ToArray(), sec.ToArray()); ProcessCollection(dt, assignments, wfEntity, 0); AssignmentList.DataSource = dt; AssignmentList.DataBind(); if (dt.Rows.Count > 0) { AssignmentList.Visible = true; NoAssignmentsLabel.Visible = false; } else { AssignmentList.Visible = false; NoAssignmentsLabel.Visible = true; NoAssignmentsLabel.Text = GetGlobalResourceObject("IbnFramework.BusinessProcess", "NoAssignments").ToString(); } }
protected void Page_Load(object sender, EventArgs e) { if (ObjectId != PrimaryKeyId.Empty) { instance = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, ObjectId); } if (!IsPostBack) { BindData(); } BindCommands(); BindToolbar(); }
/// <summary> /// When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source. /// </summary> /// <param name="dataSource">An <see cref="T:System.Collections.IEnumerable"/> that contains the values to bind to the control.</param> /// <param name="dataBinding">true to indicate that the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"/> is called during data binding; otherwise, false.</param> /// <returns> /// The number of items created by the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"/>. /// </returns> protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { if (this.CurrentRootActivity == null) { //EntityObject[] arr = BusinessManager.List(WorkflowDefinitionEntity.ClassName, new Mediachase.Ibn.Data.FilterElement[] { new Mediachase.Ibn.Data.FilterElement("WorkflowDefinitionId", FilterElementType.Equal, this.WorkflowId) }); EntityObject obj = null; try { obj = BusinessManager.Load(WorkflowDefinitionEntity.ClassName, this.WorkflowId); } catch { } if (obj == null) { obj = BusinessManager.Load(WorkflowInstanceEntity.ClassName, this.WorkflowId); if (obj == null) { throw new ArgumentNullException(String.Format("Cant find workflow with id: {0}", this.WorkflowId)); } else { WorkflowInstanceEntity wfe = (WorkflowInstanceEntity)obj; this.CurrentRootActivity = McWorkflowSerializer.GetObject<SequentialWorkflowActivity>(wfe.Xaml); } } else { WorkflowDefinitionEntity wf = (WorkflowDefinitionEntity)obj; this.CurrentRootActivity = McWorkflowSerializer.GetObject<SequentialWorkflowActivity>(wf.Xaml); } } divContainer = new Panel(); divContainer.CssClass = "wfMainContainer"; divContainer.ID = this.ID + "_wfMainContainerId"; _counter = 0; if (this.CurrentRootActivity != null) ProcessNodeCollection(this.CurrentRootActivity, divContainer); this.Controls.Add(divContainer); return 1; }
private void ProcessCollection(DataTable dt, EntityObject[] assignments, WorkflowInstanceEntity wfEntity, int level) { level++; foreach (AssignmentEntity assignment in assignments) { DataRow row = dt.NewRow(); row["AssignmentId"] = assignment.PrimaryKeyId.ToString(); row["Subject"] = assignment.Subject; if (assignment.UserId.HasValue) { row["User"] = CommonHelper.GetUserStatus(assignment.UserId.Value); } row["State"] = CHelper.GetResFileString(MetaEnum.GetFriendlyName(MetaDataWrapper.GetEnumByName("AssignmentState"), assignment.State)); if (assignment.ExecutionResult.HasValue) { row["Result"] = assignment.ExecutionResult.Value; } if (assignment.ActualFinishDate.HasValue) { row["FinishDate"] = String.Concat(assignment.ActualFinishDate.Value.ToShortDateString(), " ", assignment.ActualFinishDate.Value.ToShortTimeString()); } row["Comment"] = CHelper.ParseText(assignment.Comment, true, true, false); row["Indent"] = (level - 1) * indentSize; if (assignment.ClosedBy.HasValue) { row["ClosedBy"] = CommonHelper.GetUserStatus(assignment.ClosedBy.Value); } dt.Rows.Add(row); // Filter: // 1: WorkflowInstanceId = wfEntity.PrimaryKeyId, // 2: ParentAssignmentId = assignment.PrimaryKeyId FilterElementCollection fec = new FilterElementCollection(); fec.Add(FilterElement.EqualElement(AssignmentEntity.FieldWorkflowInstanceId, wfEntity.PrimaryKeyId.Value)); fec.Add(FilterElement.EqualElement(AssignmentEntity.FieldParentAssignmentId, assignment.PrimaryKeyId.Value)); // Sorting SortingElementCollection sec = new SortingElementCollection(); sec.Add(new SortingElement(AssignmentEntity.FieldCreated, SortingElementType.Asc)); EntityObject[] children = BusinessManager.List(AssignmentEntity.ClassName, fec.ToArray(), sec.ToArray()); ProcessCollection(dt, children, wfEntity, level); } }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute(BusinessContext context) { WorkflowInstanceEntity entityObject = (WorkflowInstanceEntity)BusinessManager.Load(context.GetTargetMetaClassName(), context.GetTargetPrimaryKeyId().Value); if (entityObject.State == (int)BusinessProcessState.Closed && entityObject.ExecutionResult == (int)BusinessProcessExecutionResult.Accepted) { if (entityObject.OwnerDocumentId.HasValue) { Document.SetReadOnly( entityObject.OwnerDocumentId.Value, WorkflowParameters.GetOwnerReadOnly(entityObject)); } // TODO: Add New Owner Here } }
public async Task <WorkflowInstanceEntity> Update(WorkflowInstanceEntity instance) { var entity = await GetById(instance.InstanceId); var id = entity.Id; using var uow = _elsaDbContext.NewUnitOfWork(); if (!await _activityInstanceRepository.BatchDeleteByWorkflowInstanceAsync(id, uow)) { throw new Exception("¸üÐÂʧ°Ü"); } if (!await _blockingActivityRepository.BatchDeleteByWorkflowInstanceAsync(id, uow)) { throw new Exception("¸üÐÂʧ°Ü"); } entity = _mapper.Map(instance, entity); entity.Id = id; foreach (var item in entity.Activities) { item.WorkflowInstance = id; } foreach (var item in entity.BlockingActivities) { item.WorkflowInstance = id; } if (!await _repository.UpdateAsync(entity, uow)) { throw new Exception("¸üÐÂʧ°Ü"); } if (entity.Activities.Any()) { if (!await _activityInstanceRepository.BatchInsertAsync(entity.Activities.ToList(), uow)) { throw new Exception("¸üÐÂʧ°Ü"); } } if (entity.BlockingActivities.Any()) { if (!await _blockingActivityRepository.BatchInsertAsync(entity.BlockingActivities.ToList(), uow)) { throw new Exception("¸üÐÂʧ°Ü"); } } uow.Commit(); return(entity); }
public bool IsEnable(object Sender, object Element) { bool retval = false; if (HttpContext.Current.Items.Contains("OwnerTypeId") && HttpContext.Current.Items.Contains("OwnerId")) { int ownerTypeId = (int)HttpContext.Current.Items["OwnerTypeId"]; int ownerId = (int)HttpContext.Current.Items["OwnerId"]; bool canUpdate = false; if (ownerTypeId == (int)ObjectTypes.Document) { canUpdate = Document.CanUpdate(ownerId); } else if (ownerTypeId == (int)ObjectTypes.Task) { canUpdate = Task.CanUpdate(ownerId); } else if (ownerTypeId == (int)ObjectTypes.ToDo) { canUpdate = ToDo.CanUpdate(ownerId); } else if (ownerTypeId == (int)ObjectTypes.Issue) { canUpdate = Incident.CanUpdate(ownerId); } if (canUpdate && Element is CommandParameters) { CommandParameters cp = (CommandParameters)Element; if (cp.CommandArguments["primaryKeyId"] == null) { throw new ArgumentException("PrimaryKeyId is null for WFInstanceStartEnableHandler"); } PrimaryKeyId pk = PrimaryKeyId.Parse(cp.CommandArguments["primaryKeyId"]); WorkflowInstanceEntity entity = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, pk); retval = (entity.State == (int)BusinessProcessState.Pending); } } return(retval); }
protected void SaveButton_ServerClick(object sender, EventArgs e) { WorkflowDefinitionEntity definition = (WorkflowDefinitionEntity)BusinessManager.Load(WorkflowDefinitionEntity.ClassName, PrimaryKeyId.Parse(TemplateList.SelectedValue)); WorkflowInstanceEntity instance = BusinessManager.InitializeEntity <WorkflowInstanceEntity>(WorkflowInstanceEntity.ClassName); instance.Name = definition.Name; instance.Description = definition.Description; if (!String.IsNullOrEmpty(OwnerName) && OwnerId > 0) { instance[OwnerName] = OwnerId; } instance.SchemaId = definition.SchemaId; instance.Xaml = definition.Xaml; if (definition.PlanFinishTimeType == (int)TimeType.Duration) { instance.PlanFinishTimeType = (int)TimeType.Duration; instance.PlanDuration = definition.PlanDuration; } else if (definition.PlanFinishTimeType == (int)TimeType.DateTime) { instance.PlanFinishTimeType = (int)TimeType.DateTime; instance.PlanFinishDate = definition.PlanFinishDate; } //instance.PlanDuration = definition.PlanDuration; //if (instance.PlanDuration.HasValue) // instance.PlanFinishTimeType = (int)TimeType.Duration; // Lock Library WorkflowParameters.SetOwnerReadOnly(instance, WorkflowParameters.GetOwnerReadOnly(definition)); // Overdue Action WorkflowParameters.SetAssignmentOverdueAction(instance, WorkflowParameters.GetAssignmentOverdueAction(definition)); BusinessManager.Create(instance); Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, string.Empty); }
protected void Page_Load(object sender, EventArgs e) { if (InstanceId != PrimaryKeyId.Empty) { instance = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, InstanceId); shemaMaster = SchemaManager.GetShemaMaster(instance.SchemaId); rootActivity = McWorkflowSerializer.GetObject(instance.Xaml); if (!String.IsNullOrEmpty(ActivityName)) { activity = WorkflowActivityWrapper.GetActivityByName(rootActivity, ActivityName); } } if (!IsPostBack) { BindInfo(); BindData(); } LoadControlToPlaceHolder(!IsPostBack); }
protected void Page_Load(object sender, EventArgs e) { if (ObjectId != PrimaryKeyId.Empty) { template = (WorkflowDefinitionEntity)BusinessManager.Load(WorkflowDefinitionEntity.ClassName, ObjectId); } else if (FromInstanceId != PrimaryKeyId.Empty) { instance = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, FromInstanceId); } if (!IsPostBack) { BindInfo(); // texts, icons BindData(); BindToolbar(); } LoadControlToPlaceHolder(!IsPostBack); if (!this.Page.ClientScript.IsStartupScriptRegistered(this.Page.GetType(), "EnumEdit")) { this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "EnumEdit", @"function enumEdit_OpenWindow(query, w, h, resize){ var l = (screen.width - w) / 2; var t = (screen.height - h) / 2; winprops = 'height='+h+',width='+w+',top='+t+',left='+l; if (scroll) winprops+=',scrollbars=1'; if (resize) winprops+=',resizable=1'; else winprops+=',resizable=0'; var f = window.open(query, '_blank', winprops); }" , true); } }
public void Invoke(object Sender, object Element) { if (Element is CommandParameters) { CommandParameters cp = (CommandParameters)Element; if (cp.CommandArguments["primaryKeyId"] == null) { throw new ArgumentException("PrimaryKeyId is null for WFInstanceStartHandler"); } PrimaryKeyId pk = PrimaryKeyId.Parse(cp.CommandArguments["primaryKeyId"]); WorkflowInstanceEntity entity = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, pk); if (entity.PlanFinishDate.HasValue && entity.PlanFinishDate.Value <= Mediachase.IBN.Business.UserDateTime.UserNow) { CommandManager cm = Sender as CommandManager; cm.InfoMessage = CHelper.GetResFileString("{IbnFramework.BusinessProcess:StartInstanceWarning}"); } else { BusinessManager.Execute(new StartWorkflowInstanceRequest(pk)); } } }
/// <summary> /// Gets the user list. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> private int[] GetUserList(WorkflowInstanceEntity entity) { object workflowRoot = McWorkflowSerializer.GetObject(entity.Xaml); return(WorkflowActivityWrapper.GetActivityUserList(workflowRoot)); }
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(); }
private WorkflowInstance Map(WorkflowInstanceEntity source) => mapper.Map <WorkflowInstance>(source);
/// <summary> /// Processes this instance. /// </summary> public static void Process() { // Step 1. Process WorkflowInstanceEntity // Step 1-1. Set Overdue foreach (WorkflowInstanceEntity entity in BusinessManager.List(WorkflowInstanceEntity.ClassName, new FilterElement[] { FilterElement.EqualElement(WorkflowInstanceEntity.FieldState, (int)BusinessProcessState.Active), FilterElement.IsNullElement(WorkflowInstanceEntity.FieldTimeStatus), new FilterElement(WorkflowInstanceEntity.FieldPlanFinishDate, FilterElementType.LessOrEqual, DateTime.UtcNow) })) { BusinessManager.Update(entity); } // Step 1-2. Reset Overdue foreach (WorkflowInstanceEntity entity in BusinessManager.List(WorkflowInstanceEntity.ClassName, new FilterElement[] { FilterElement.EqualElement(WorkflowInstanceEntity.FieldState, (int)BusinessProcessState.Active), FilterElement.EqualElement(WorkflowInstanceEntity.FieldTimeStatus, (int)WorkflowInstanceTimeStatus.OverDue), new FilterElement(WorkflowInstanceEntity.FieldPlanFinishDate, FilterElementType.Greater, DateTime.UtcNow) })) { BusinessManager.Update(entity); } // Step 2. Process AssignmentEntity // Step 2-1. Set Overdue foreach (AssignmentEntity entity in BusinessManager.List(AssignmentEntity.ClassName, new FilterElement[] { FilterElement.EqualElement(AssignmentEntity.FieldState, (int)AssignmentState.Active), FilterElement.IsNullElement(AssignmentEntity.FieldTimeStatus), new FilterElement(AssignmentEntity.FieldPlanFinishDate, FilterElementType.LessOrEqual, DateTime.UtcNow) })) { // Process Auto Complete if (entity.WorkflowInstanceId.HasValue) { WorkflowInstanceEntity wfInstance = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, entity.WorkflowInstanceId.Value); switch (WorkflowParameters.GetAssignmentOverdueAction(wfInstance)) { case AssignmentOverdueAction.NoAction: BusinessManager.Update(entity); break; case AssignmentOverdueAction.AutoCompleteWithDecline: CloseAssignmentRequest declineRequet = new CloseAssignmentRequest(entity.PrimaryKeyId.Value, (int)AssignmentExecutionResult.Declined); declineRequet.Comment = WorkflowParameters.GetAutoCompleteComment(wfInstance); if (string.IsNullOrEmpty(declineRequet.Comment)) { declineRequet.Comment = GetAutoCompleteDefaultComment(); } BusinessManager.Execute(declineRequet); break; case AssignmentOverdueAction.AutoCompleteWithAccept: CloseAssignmentRequest acceptRequet = new CloseAssignmentRequest(entity.PrimaryKeyId.Value, (int)AssignmentExecutionResult.Accepted); acceptRequet.Comment = WorkflowParameters.GetAutoCompleteComment(wfInstance); if (string.IsNullOrEmpty(acceptRequet.Comment)) { acceptRequet.Comment = GetAutoCompleteDefaultComment(); } BusinessManager.Execute(acceptRequet); break; } } else { BusinessManager.Update(entity); } } // Step 2-1. Reset Overdue foreach (AssignmentEntity entity in BusinessManager.List(AssignmentEntity.ClassName, new FilterElement[] { FilterElement.EqualElement(AssignmentEntity.FieldState, (int)AssignmentState.Active), FilterElement.EqualElement(AssignmentEntity.FieldTimeStatus, (int)AssignmentTimeStatus.OverDue), new FilterElement(AssignmentEntity.FieldPlanFinishDate, FilterElementType.Greater, DateTime.UtcNow) })) { BusinessManager.Update(entity); } }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute(BusinessContext context) { // Load ACL FileStorage fs; AccessControlList acl; switch (context.GetMethod()) { case RequestMethod.Create: WorkflowInstanceEntity newEntity = this.Context.Request.Target as WorkflowInstanceEntity; Guid newWorkflowInstanceId = (Guid)((CreateResponse)context.Response).PrimaryKeyId; if (LoadFileLibraryAcl(newEntity, out fs, out acl)) { // Read Users From Activity And Create ACE foreach (int userId in GetUserList(newEntity)) { // Modify ACL acl.Add(new AccessControlEntry(userId, "Read", true, newWorkflowInstanceId)); // Create WorkflowParticipant CreateWorkflowParticipiant(newWorkflowInstanceId, userId, newEntity); } // Save ACL AccessControlList.SetACL(fs, acl, false); } break; case RequestMethod.Update: WorkflowInstanceEntity entity = this.Context.Request.Target as WorkflowInstanceEntity; Guid workflowInstanceId = (Guid)context.GetTargetPrimaryKeyId().Value; if (LoadFileLibraryAcl(entity, out fs, out acl)) { // Remove All Workflow ACE for (int index = acl.Count - 1; index >= 0; index--) { if (acl[index].OwnerKey == workflowInstanceId) { acl.RemoveAt(index); } } // Remove WorkflowParticipantRow RemoveAllWorkflowParticipants(workflowInstanceId); // Read Users From Activity And Create ACE foreach (int userId in GetUserList(entity)) { acl.Add(new AccessControlEntry(userId, "Read", true, workflowInstanceId)); // Create WorkflowParticipant CreateWorkflowParticipiant(workflowInstanceId, userId, entity); } // Save ACL AccessControlList.SetACL(fs, acl, false); } break; case RequestMethod.Delete: WorkflowInstanceEntity delEntity = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, context.GetTargetPrimaryKeyId().Value); Guid delWorkflowInstanceId = (Guid)context.GetTargetPrimaryKeyId().Value; if (LoadFileLibraryAcl(delEntity, out fs, out acl)) { // Remove All Workflow ACE for (int index = acl.Count - 1; index >= 0; index--) { if (acl[index].OwnerKey == delWorkflowInstanceId) { acl.RemoveAt(index); } } // Remove WorkflowParticipantRow RemoveAllWorkflowParticipants(delWorkflowInstanceId); // Save ACL AccessControlList.SetACL(fs, acl, false); } break; } }