Exemplo n.º 1
0
        public PreviewResult PreviewChanges(XDocument document, WorkflowModel model)
        {
            var oldTasks = this.pools.Values.SelectMany(p => p.GetAllActivities()).Select(a => a.Entity);
            var oldIntermediateEvents = this.pools.Values.SelectMany(p => p.GetLanes().SelectMany(l => l.GetEvents().Where(e => e.Entity.Type == WorkflowEventType.IntermediateTimer))).Select(a => a.Entity);
            var oldNodes = oldTasks.Cast <IWorkflowNodeEntity>().Concat(oldIntermediateEvents.Cast <IWorkflowNodeEntity>()).ToDictionary(node => node.BpmnElementId);

            var newNodes = document.Descendants().Where(a => LaneBuilder.WorkflowActivityTypes.Values.Contains(a.Name.LocalName) || a.Name.LocalName == LaneBuilder.WorkflowEventTypes[WorkflowEventType.IntermediateTimer])
                           .ToDictionary(a => a.Attribute("id").Value);

            var entities = model.Entities.ToDictionaryEx(a => a.BpmnElementId);

            return(new PreviewResult
            {
                Model = new WorkflowReplacementModel
                {
                    Replacements = oldNodes.Where(kvp => !newNodes.ContainsKey(kvp.Key) && kvp.Value.CaseActivities().Any())
                                   .Select(a => new WorkflowReplacementItemEmbedded
                    {
                        OldNode = a.Value.ToLite(),
                        SubWorkflow = (a.Value as WorkflowActivityEntity)?.SubWorkflow?.Workflow.ToLite()
                    })
                                   .ToMList(),
                },
                NewTasks = newNodes.Select(kvp => new PreviewTask
                {
                    BpmnId = kvp.Key,
                    Name = kvp.Value.Attribute("name")?.Value !,
                    SubWorkflow = (entities.GetOrThrow(kvp.Key).Model as WorkflowActivityModel)?.SubWorkflow?.Workflow.ToLite()
                }).ToList(),
Exemplo n.º 2
0
        /// <summary>
        /// Returns the full path of incoming activities.
        /// </summary>
        public static IEnumerable <string> GetInboundActivityPath(this WorkflowModel workflowModel, string activityId)
        {
            var inspectedActivityIds = new HashSet <string>();

            return(workflowModel.GetInboundActivityPathInternal(activityId, inspectedActivityIds)
                   .Distinct().ToList());
        }
Exemplo n.º 3
0
        private WorkflowModel GetWorkflowFactory(Guid id)
        {
            var credentials = new Credentials
            {
                UserName = _configuration.SourceUserName,
                Password = _configuration.SourcePassword
            };

            Sitecore.Diagnostics.Log.Debug(string.Format("[FieldMigrator] GetWorkflowFactory id:{0}", id), this);
            var results = _service.GetXML(id.ToString().ToUpper(), true, _configuration.SourceDatabase, credentials);

            var stateItemElement = results.Descendants("item")
                                   .FirstOrDefault(x => x.Attribute("template").Value == "state" && x.Descendants("field").Where(f => f.Attribute("key").Value == "final").Descendants("content").Any(c => c.Value == "1"));

            if (stateItemElement == null)
            {
                return(null);
            }

            var workflowModel = new WorkflowModel
            {
                FinalState = Guid.Parse(stateItemElement.Attribute("id").Value),
                Id         = id
            };

            return(workflowModel);
        }
Exemplo n.º 4
0
        public override async Task <WorkflowModel> Consultar(BaseRequest request, ServerCallContext context)
        {
            Guid          id     = new Guid(request.Id);
            WorkflowModel result = _mapper.Map <WorkflowModel>(_workflowAppService.Consultar(id));

            return(await Task.FromResult(result));
        }
Exemplo n.º 5
0
 public override async Task <BaseReply> Alterar(WorkflowModel request, ServerCallContext context)
 {
     return(await Task.FromResult(new BaseReply
     {
         Sucesso = _workflowAppService.Alterar(_mapper.Map <WorkflowViewModel>(request))
     }));
 }
Exemplo n.º 6
0
 public override async Task <BaseReply> Incluir(WorkflowModel request, ServerCallContext context)
 {
     return(await Task.FromResult(new BaseReply
     {
         Id = _workflowAppService.Incluir(_mapper.Map <WorkflowViewModel>(request)).ToString()
     }));
 }
Exemplo n.º 7
0
        public bool FinanceConfirmAction(string projectid, string userid)
        {
            ISqlMapper mapper = Common.GetMapperFromSession();
            //处理流程
            WorkflowModel model = WorkflowModel.LoadByProcessID(projectid);

            model.ProcessActivity(new Approval {
                Status = (int)ApprovalStatus.None
            }, userid, new WorkflowAuthority());
            TaskDao taskdao = new TaskDao(mapper);

            taskdao.Update(new TaskUpdateForm
            {
                Entity = new Task
                {
                    Status      = (int)TaskProcessStatus.Processed,
                    LastUpdator = userid,
                },
                TaskQueryForm = new TaskQueryForm
                {
                    WorkflowID = model.Value.ID,
                    Status     = (int)TaskProcessStatus.Started,
                }
            });
            return(true);
        }
        //
        // GET: /Workflow/Edit/5
        public ActionResult Edit(int?id)
        {
            var selectedType = WorkflowType.None.ToString();

            WorkflowModel model = null;

            if (!id.HasValue || id.Value < 1) //新增
            {
                model = new WorkflowModel()
                {
                    Status        = WorkflowStatus.Enabled,
                    WorkflowSteps = new List <WorkflowStepModel>()
                };
            }
            else //修改
            {
                model = WorkflowService.GetWorkflowDetail(id.Value);

                //流程类型
                selectedType = model.Type == WorkflowType.None? WorkflowType.AskLeave.ToString() :  model.Type.ToString();
            }

            ViewData["WorkflowStep"] = model.WorkflowSteps;
            InitWorkflowTypes(selectedType);
            ViewData["WorkflowId"] = model.Id;

            return(View(model));
        }
Exemplo n.º 9
0
        private void button14_Click(object sender, EventArgs e)
        {
            string id       = textBox1.Text;
            string userid   = "9";
            var    workflow = WorkflowModel.Load(id);
            //如果流程当前处理人等于申请人,就直接审批通过,进入下一个流程
            var task = workflow.CurrentActivity.Tasks.Find(t => t.UserID == userid && t.Status == (int)TaskProcessStatus.Started);

            if (task != null)
            {
                workflow.ProcessActivity(new Approval
                {
                    Creator     = userid,
                    LastUpdator = userid,
                    Remark      = "111",
                    Status      = (int)ApprovalStatus.Agree,
                    ActivityID  = workflow.CurrentActivity.Value.ID,
                    WorkflowID  = workflow.Value.ID,
                }, userid, new WorkflowAuthority());
                task = workflow.CurrentActivity.Tasks.Find(t => t.UserID == userid && t.Status == (int)TaskProcessStatus.Started);
                if (task != null)
                {
                    workflow.ProcessActivity(new Approval
                    {
                        Creator     = userid,
                        LastUpdator = userid,
                        Remark      = "1222",
                        Status      = (int)ApprovalStatus.Agree,
                        ActivityID  = workflow.CurrentActivity.Value.ID,
                        WorkflowID  = workflow.Value.ID,
                    }, userid, new WorkflowAuthority());
                }
            }
        }
Exemplo n.º 10
0
        public void DeserializeModel_StartWorkflowCommand_CorrelationId()
        {
            IdentityModel   identityModel   = new IdentityModel(accountName, AuthorizationType.NTLM);
            IdentityContext identityContext = new IdentityContext(identityModel);
            RoleModel       roleModel       = new RoleModel(AuthorizationType.DocSuiteSecurity, Guid.NewGuid());

            identityContext.Roles.Add(roleModel);
            WorkflowModel          workflowModel           = new WorkflowModel("DSW_StartCollaboration");
            SignerModel            singner1                = new SignerModel(1, true, SignerType.AD, identityModel);
            WorkflowParameterModel workflowParameterModel1 = new WorkflowParameterModel(singner1, WorkflowParameterNames.CollaborationNames.SIGNER);

            workflowModel.WorkflowParameters.Add(workflowParameterModel1);
            SignerModel            singner2 = new SignerModel(2, true, SignerType.DSWRole, role: roleModel);
            WorkflowParameterModel workflowParameterModel2 = new WorkflowParameterModel(singner2, WorkflowParameterNames.CollaborationNames.SIGNER);

            workflowModel.WorkflowParameters.Add(workflowParameterModel2);
            StartWorkflowContentType startWorkflowContentType = new StartWorkflowContentType(workflowModel, accountName, Guid.NewGuid());
            StartWorkflowCommand     startWorkflowCommand     = new StartWorkflowCommand(Guid.NewGuid(), tenantName, tenantId, Guid.NewGuid(), identityContext, startWorkflowContentType)
            {
                CorrelationId = Guid.NewGuid()
            };
            string json = ManagerHelper.SerializeModel(startWorkflowCommand);
            StartWorkflowCommand deJson = ManagerHelper.DeserializeModel <StartWorkflowCommand>(json);

            Assert.AreEqual <Guid>(startWorkflowCommand.CorrelationId.Value, deJson.CorrelationId.Value);
        }
Exemplo n.º 11
0
        public PreviewResult PreviewChanges(string workflowId, [Required, FromBody] WorkflowModel model)
        {
            var id = PrimaryKey.Parse(workflowId, typeof(WorkflowEntity));
            var wf = Database.Retrieve <WorkflowEntity>(id);

            return(WorkflowLogic.PreviewChanges(wf, model));
        }
        public async Task <IActionResult> Details(string id, string returnUrl, CancellationToken cancellationToken)
        {
            var instance = await workflowInstanceStore.GetByIdAsync(id, cancellationToken);


            if (instance == null)
            {
                return(NotFound());
            }

            var definition = await workflowDefinitionStore.GetByIdAsync(
                instance.DefinitionId,
                VersionOptions.SpecificVersion(instance.Version),
                cancellationToken
                );

            var workflow = new WorkflowModel
            {
                Activities  = definition.Activities.Select(x => CreateActivityModel(x, instance)).ToList(),
                Connections = definition.Connections.Select(x => new ConnectionModel(x)).ToList()
            };

            var model = new WorkflowInstanceDetailsModel(
                instance,
                definition,
                workflow,
                options.Value.ActivityDefinitions,
                returnUrl);

            return(View("Details", model));
        }
Exemplo n.º 13
0
        public bool StopWorkflow(string workflowid, string userid)
        {
            WorkflowModel workflow = WorkflowModel.Load(workflowid);

            workflow.Stop(userid);
            return(true);
        }
Exemplo n.º 14
0
        public List <WorkflowModel> GetWorkflow(int id)
        {
            List <WorkflowModel> output = new List <WorkflowModel>();
            string query = $"SELECT * FROM dbo.Workflow where workflowID = {id} and IsActive=1";

            SqlCommand command = new SqlCommand(query, sqlConnection);

            sqlConnection.Open();
            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                var WorkflowModel_ = new WorkflowModel
                {
                    WorkflowId  = reader.GetInt32(0),
                    Name        = reader.GetString(1),
                    Description = reader.GetString(2),
                    Workflow    = reader.GetString(3)
                };
                output.Add(WorkflowModel_);
            }
            sqlConnection.Close();
            // Console.WriteLine(output.Count());
            return(output);
        }
Exemplo n.º 15
0
        public static IEnumerable <ActivityModel> GetLeafActivities(this WorkflowModel workflowModel)
        {
            var sourceIds = workflowModel.Connections.Select(x => x.SourceId).Distinct().ToLookup(x => x);
            var leaves    = workflowModel.Activities.Where(x => !sourceIds.Contains(x.ActivityId)).ToList();

            return(leaves);
        }
Exemplo n.º 16
0
        public PreviewResult PreviewChanges(XDocument document, WorkflowModel model)
        {
            var oldTasks = this.pools.Values.SelectMany(p => p.GetAllActivities())
                           .ToDictionary(a => a.bpmnElementId);

            var newElements = document.Descendants().Where(a => LaneBuilder.WorkflowActivityTypes.Values.Contains(a.Name.LocalName))
                              .ToDictionary(a => a.Attribute("id").Value);

            var entities = model.Entities.ToDictionaryEx(a => a.BpmnElementId);

            return(new PreviewResult
            {
                Model = new WorkflowReplacementModel
                {
                    Replacements = oldTasks.Where(kvp => !newElements.ContainsKey(kvp.Key) && kvp.Value.Entity.CaseActivities().Any())
                                   .Select(a => new WorkflowReplacementItemEmbedded
                    {
                        OldTask = a.Value.Entity.ToLite(),
                        SubWorkflow = a.Value.Entity.SubWorkflow?.Workflow.ToLite()
                    })
                                   .ToMList(),
                },
                NewTasks = newElements.Select(kvp => new PreviewTask
                {
                    BpmnId = kvp.Key,
                    Name = kvp.Value.Attribute("name")?.Value,
                    SubWorkflow = ((WorkflowActivityModel)entities.GetOrThrow(kvp.Key).Model).SubWorkflow?.Workflow.ToLite()
                }).ToList(),
            });
        }
Exemplo n.º 17
0
        public async Task <AWFDefinitionDetailResponse> GetDetailDefinitionAsync(string id, CancellationToken cancellationToken)
        {
            var workflowDefinition = await _publisher.GetDraftAsync(id, cancellationToken);

            if (workflowDefinition == null)
            {
                throw new ErrorException(StatusCodes.Status404NotFound, $"Can't not found workflow definition with {id}");
            }

            var workflowModel = new WorkflowModel
            {
                Activities  = workflowDefinition.Activities.Select(x => new ActivityModel(x)).ToList(),
                Connections = workflowDefinition.Connections.Select(x => new ConnectionModel(x)).ToList()
            };

            var model = new WorkflowDefinitionEditModel
            {
                Id                  = workflowDefinition.DefinitionId,
                Name                = workflowDefinition.Name,
                Json                = _serializer.Serialize(workflowModel, JsonTokenFormatter.FormatName),
                Description         = workflowDefinition.Description,
                IsSingleton         = workflowDefinition.IsSingleton,
                IsDisabled          = workflowDefinition.IsDisabled,
                ActivityDefinitions = _options.Value.ActivityDefinitions.ToArray(),
                WorkflowModel       = workflowModel
            };

            return(_mapper.Map <AWFDefinitionDetailResponse>(model));
        }
        /// <summary>
        /// 流程当前步骤
        /// </summary>
        /// <param name="order"></param>
        /// <param name="workflow"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private WorkflowStepModel GetCurrentStep(OrderModel order, WorkflowModel workflow, OperateOrderModel operation)
        {
            WorkflowStepModel curStep = null;

            if (operation.Operation == WorkflowOperation.Apply)
            {
                curStep = workflow.GetUserApplyStep(); //当前步骤为[申请]步骤
            }
            else
            {
                if (order.NextStep.HasValue)
                {
                    curStep = (order.NextStep.Value == Constant.WORKFLOW_DIRECT_SUPERVISOR_APPROVE_NODE
                        ? workflow.GetDirectSupervisorApproveStep() //当前步骤为[直接领导审批]步骤
                        : workflow.WorkflowSteps.FirstOrDefault(it => it.Id == order.NextStep.Value));
                }
            }

            if (curStep == null)
            {
                Log.Error("当前流程步骤无效。");
                throw new KeyNotFoundException("当前流程步骤无效。");
            }

            return(curStep);
        }
Exemplo n.º 19
0
        public bool SaveWorkflow(WorkflowModel model)
        {
            bool   bValid = false;
            string sSQL   = string.Empty;
            string data   = string.Empty;
            string query  = string.Empty;

            /**
             * Console.WriteLine(model.Description);
             * Console.WriteLine(model.Name);
             * Console.WriteLine(model.JSON);
             **/
            if (model.WorkflowId > 0)
            {   // update an existing workflow
                //sSQL = "UPDATE dbo.tusharWorkflow SET JSON = '" + model.JSON + "' WHERE WorkflowId = " + model.WorkflowId.ToString() + "";
                sSQL = $"UPDATE dbo.Workflow SET Name= '{model.Name}' , Description= '{model.Description}', JSON='{model.Workflow}', UpdatedOn='{DateTime.Now}' WHERE WorkflowId= {model.WorkflowId} AND IsActive=1";
            }
            else
            {   // create a new workflow
                //sSQL = "INSERT INTO dbo.tusharWorkflow (workflowID,data) VALUES ('" + model + "')";
                data  = model.Workflow.ToString();
                query = "INSERT INTO dbo.Workflow (Name, Description, JSON, CreatedOn, IsActive)";
                sSQL  = query + $"VALUES( '{model.Name}', '{model.Description}','{model.Workflow}', '{DateTime.Now}', 1)";
            }
            sqlConnection.Open();
            SqlCommand command = new SqlCommand(sSQL, sqlConnection);

            command.ExecuteNonQuery();
            sqlConnection.Close();

            bValid = true;
            return(bValid);
        }
        /// <summary>
        /// 获取审批步骤,将[直接领导]审批步骤转换为有效审批步骤
        /// </summary>
        /// <param name="approver"></param>
        /// <param name="curStep"></param>
        /// <param name="workflow"></param>
        /// <returns></returns>
        private WorkflowStepModel GetApproveStepForApprover(UserModel approver, WorkflowStepModel curStep,
                                                            WorkflowModel workflow)
        {
            if (curStep.Id == Constant.WORKFLOW_DIRECT_SUPERVISOR_APPROVE_NODE) //当前步骤是[直接领导审批]
            {
                //按[角色]查找
                curStep =
                    workflow.WorkflowSteps.FirstOrDefault(
                        it =>
                        it.Type == WorkflowStepType.LeaderApprove &&
                        it.OperatorType == WorkflowOperator.Role && it.Operator == approver.Role);

                //按[用户]查找
                curStep = curStep ?? workflow.WorkflowSteps.FirstOrDefault(
                    it =>
                    it.Type == WorkflowStepType.LeaderApprove &&
                    it.OperatorType == WorkflowOperator.User && it.Operator == approver.Id);

                if (curStep == null)
                {
                    Log.Error("直接领导无法审批流程。");
                    throw new InvalidOperationException("直接领导无法审批流程。");
                }
            }

            return(curStep);
        }
        /// <summary>
        /// 获取用户申请的下一审批步骤
        /// </summary>
        /// <param name="director"></param>
        /// <param name="workflow"></param>
        /// <returns></returns>
        private WorkflowStepModel GetNextStepForUserApply(UserModel director, WorkflowModel workflow)
        {
            WorkflowStepModel nextStep = null;

            //无直接领导人, 则到[行政财务]审批
            if (director == null)
            {
                //行政审批
                nextStep = workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.AdminReview);
                //财务审批
                nextStep = nextStep ?? workflow.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.FinanceReview);
            }
            //[直接领导]审批
            else
            {
                nextStep = workflow.GetDirectSupervisorApproveStep();
                nextStep.OperatorType = WorkflowOperator.User;
                nextStep.Operator     = director.Id; //设置审批人
            }

            if (nextStep == null)
            {
                Log.Error("无效的申请流程。");
                throw new InvalidOperationException("无效的申请流程。");
            }

            return(nextStep);
        }
        public async Task <IActionResult> Edit(string id, CancellationToken cancellationToken)
        {
            var workflowDefinition = await publisher.GetDraftAsync(id, cancellationToken);

            if (workflowDefinition == null)
            {
                return(NotFound());
            }

            var workflowModel = new WorkflowModel
            {
                Activities  = workflowDefinition.Activities.Select(x => new ActivityModel(x)).ToList(),
                Connections = workflowDefinition.Connections.Select(x => new ConnectionModel(x)).ToList()
            };

            var model = new WorkflowDefinitionEditModel
            {
                Id                  = workflowDefinition.DefinitionId,
                Name                = workflowDefinition.Name,
                Json                = serializer.Serialize(workflowModel, JsonTokenFormatter.FormatName),
                Description         = workflowDefinition.Description,
                IsSingleton         = workflowDefinition.IsSingleton,
                IsDisabled          = workflowDefinition.IsDisabled,
                ActivityDefinitions = options.Value.ActivityDefinitions.ToArray(),
                WorkflowModel       = workflowModel
            };

            return(View(model));
        }
Exemplo n.º 23
0
        public void ApplyChanges(WorkflowModel model, WorkflowReplacementModel replacements)
        {
            var document = XDocument.Parse(model.DiagramXml);

            var participants    = document.Descendants(bpmn + "collaboration").Elements(bpmn + "participant").ToDictionaryEx(a => a.Attribute("id").Value);
            var processElements = document.Descendants(bpmn + "process").ToDictionaryEx(a => a.Attribute("id").Value);
            var diagramElements = document.Descendants(bpmndi + "BPMNPlane").Elements().ToDictionaryEx(a => a.Attribute("bpmnElement").Value, "bpmnElement");

            if (participants.Count != processElements.Count)
            {
                throw new InvalidOperationException(WorkflowValidationMessage.ParticipantsAndProcessesAreNotSynchronized.NiceToString());
            }

            Locator locator  = new Workflow.Locator(this, diagramElements, model, replacements);
            var     oldPools = this.pools.Values.ToDictionaryEx(a => a.pool.bpmnElementId, "pools");

            Synchronizer.Synchronize(participants, oldPools,
                                     (id, pa) =>
            {
                var wp = new WorkflowPoolEntity {
                    Xml = new WorkflowXmlEmbedded(), Workflow = this.workflow
                }.ApplyXml(pa, locator);
                var pb = new PoolBuilder(wp, Enumerable.Empty <LaneBuilder>(), Enumerable.Empty <XmlEntity <WorkflowConnectionEntity> >());
                this.pools.Add(wp.ToLite(), pb);
                pb.ApplyChanges(processElements.GetOrThrow(pa.Attribute("processRef").Value), locator);
            },
                                     (id, pb) =>
            {
                this.pools.Remove(pb.pool.Entity.ToLite());
                pb.DeleteAll(locator);
            },
                                     (id, pa, pb) =>
            {
                var wp = pb.pool.Entity.ApplyXml(pa, locator);
                pb.ApplyChanges(processElements.GetOrThrow(pa.Attribute("processRef").Value), locator);
            });

            var messageFlows    = document.Descendants(bpmn + "collaboration").Elements(bpmn + "messageFlow").ToDictionaryEx(a => a.Attribute("id").Value);
            var oldMessageFlows = this.messageFlows.ToDictionaryEx(a => a.bpmnElementId, "messageFlows");

            Synchronizer.Synchronize(messageFlows, oldMessageFlows,
                                     (id, mf) =>
            {
                var wc = new WorkflowConnectionEntity {
                    Xml = new WorkflowXmlEmbedded()
                }.ApplyXml(mf, locator);
                this.messageFlows.Add(new XmlEntity <WorkflowConnectionEntity>(wc));
            },
                                     (id, omf) =>
            {
                this.messageFlows.Remove(omf);
                omf.Entity.Delete(WorkflowConnectionOperation.Delete);
            },
                                     (id, mf, omf) =>
            {
                omf.Entity.ApplyXml(mf, locator);
            });
        }
Exemplo n.º 24
0
        /// <summary>
        /// 更新工作流
        /// </summary>
        /// <param name="model">工作流信息</param>
        /// <returns>true or false</returns>
        public bool UpdateWorkflow(WorkflowModel model)
        {
            if (model == null)
            {
                Log.Error("工作流无效。");
                throw new InvalidOperationException("工作流无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                ValidWorkflow(dbContext, model);

                var oldFlow = dbContext.Workflows.FirstOrDefault(it => it.Id == model.Id);
                if (oldFlow == null)
                {
                    Log.Error(string.Format("找不到工作流, Id: {0}", model.Id));
                    throw new InvalidOperationException(string.Format("找不到工作流, Id: {0}", model.Id));
                }

                //更新工作流
                if (oldFlow.Name == null || !oldFlow.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    oldFlow.Name = model.Name;
                }

                if (oldFlow.Desc == null || !oldFlow.Desc.Equals(model.Desc, StringComparison.InvariantCultureIgnoreCase))
                {
                    oldFlow.Desc = model.Desc;
                }

                if (oldFlow.Type != Convert.ToInt32(model.Type))
                {
                    oldFlow.Type = (int)model.Type;
                }

                if (oldFlow.Status != Convert.ToBoolean(model.Status))
                {
                    oldFlow.Status = Convert.ToBoolean((int)model.Status);
                }

                if (oldFlow.Condition == null || !oldFlow.Condition.Equals(model.Condition, StringComparison.InvariantCultureIgnoreCase))
                {
                    oldFlow.Condition = model.Condition;
                }

                if (oldFlow.ConditionDesc == null || !oldFlow.ConditionDesc.Equals(model.ConditionDesc, StringComparison.InvariantCultureIgnoreCase))
                {
                    oldFlow.ConditionDesc = model.ConditionDesc;
                }

                //更新工作流
                dbContext.SaveChanges();

                return(true);
            }
        }
Exemplo n.º 25
0
        private void button1_Click(object sender, EventArgs e)
        {
            WorkflowDao dao = new WorkflowDao();
            var         wf  = new WorkflowQueryForm();

            wf.ID = "1c74c3e0ce2d4c5f983fab3dc6063223";
            var list = dao.Query(wf);

            WorkflowModel model = WorkflowModel.Load("1c74c3e0ce2d4c5f983fab3dc6063223");
        }
Exemplo n.º 26
0
        /// <summary>
        /// 流程是否需要财务审批
        /// </summary>
        /// <param name="model">流程</param>
        /// <returns>true or false</returns>
        public static bool NeedFinanceApprove(this WorkflowModel model)
        {
            if (model == null || model.WorkflowSteps == null || model.WorkflowSteps.Count < 1)
            {
                throw new KeyNotFoundException("Invalid order workflow.");
            }

            var step = model.WorkflowSteps.FirstOrDefault(it => it.Type == WorkflowStepType.FinanceReview);

            return(step != null);
        }
        public void WorkflowDefinitionStartNewTest()
        {
            model = WorkflowDefinitionModel.Load("unittest1");

            WorkflowModel workflow = model.StartNew("frank", "1", new GetUser());

            Assert.AreEqual(3, workflow.Root.Value.Status);
            Assert.AreEqual(2, workflow.Root.Children[0].Value.Status);
            Assert.AreEqual("title3", workflow.Root.Children[0].Children[0].Value.Title);
            workflow.Remove();
        }
Exemplo n.º 28
0
        public static PreviewResult PreviewChanges(WorkflowEntity workflow, WorkflowModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var document = XDocument.Parse(model.DiagramXml);
            var wb       = new WorkflowBuilder(workflow);

            return(wb.PreviewChanges(document, model));
        }
Exemplo n.º 29
0
        public StateMachineBuilderImpl(Expression <Func <TInstance, State> > currentStateExpression)
        {
            var states = new Dictionary <string, State <TInstance> >(GetStates().ToDictionary(x => x.Name));
            var events = new Dictionary <string, Event>(GetEvents(states.Values).ToDictionary(x => x.Name));

            var initialState = states[_initialStateName];
            var finalState   = states[_finalStateName];

            var currentState = new CurrentStateAccessor <TInstance>(currentStateExpression, initialState);

            _model = new WorkflowModelImpl <TWorkflow, TInstance>(states, events, currentState, initialState, finalState);
        }
Exemplo n.º 30
0
 public void LoadWorkflow()
 {
     WorkflowSource.Clear();
     DataTable dataTable = SystemService.GetDataTable("select WorkflowID, WorkflowName from Workflow");
     for (int i = 0; i < dataTable.Rows.Count; i++)
     {
         WorkflowModel workflowModel = new WorkflowModel();
         workflowModel.WorkflowID = Convert.ToInt32(dataTable.Rows[i]["WorkflowID"]);
         workflowModel.WorkflowName = dataTable.Rows[i]["WorkflowName"].ToString();
         WorkflowSource.Add(workflowModel);
     }
 }
Exemplo n.º 31
0
        public void CtorShouldCreateTracker()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);

                // Act
                var wi = new WorkflowInstance(model);

                // Assert
                Assert.IsNotNull(wi.StateTracker);
            }
        }
Exemplo n.º 32
0
        public void HostIsNotNull()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);
                var wi = new WorkflowInstance(model);

                // Act
                wi.New();

                // Assert
                Assert.IsNotNull(wi.Host);
            }
        }
Exemplo n.º 33
0
        public void IdIsLoadedTrackerId()
        {
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                // Arrange
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);

                // Create and run the workflow
                var id = model.New();

                // Act

                // Load the instances from the datbase
                model.LoadInstances(view);

                // Get the id from the state tracker
                var hostid = model.CurrentInstance.Id;

                // Assert
                Assert.AreEqual(hostid, id);
            }
        }
Exemplo n.º 34
0
        public void IdIsHostId()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);
                var wi = new WorkflowInstance(model);

                // Act
                wi.New();
                var hostid = wi.Host.Id;
                var id = wi.Id;

                // Assert
                Assert.AreEqual(hostid, id);
            }
        }
Exemplo n.º 35
0
        public void UnloadShouldUnloadWorkflowApp()
        {
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                // Arrange
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);

                // Create and run the workflow
                model.New();

                // Act
                // Load the instances from the datbase
                var workflowInstance = model.CurrentInstance;
                workflowInstance.Unload();
                var isLoaded = workflowInstance.IsLoaded;

                // Assert
                Assert.IsFalse(isLoaded);
            }
        }
Exemplo n.º 36
0
        public void ResumeShouldResume()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);
                var wi = new WorkflowInstance(model);
                wi.New();

                // Act
                wi.Resume(StateTrigger.T1);

                // Assert
                Assert.AreEqual(StateMachineExample.State2, wi.StateTracker.CurrentState);
            }
        }
Exemplo n.º 37
0
        public void IsLoadedReturnsTrueOnNew()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);
                var wi = new WorkflowInstance(model);
                wi.New();

                // Act
                var actual = wi.IsLoaded;

                // Assert
                Assert.IsTrue(actual);
            }
        }
Exemplo n.º 38
0
        public void IsLoadedFiresPropertyChanged()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);
                var wi = new WorkflowInstance(model);
                var propChanged = false;

                wi.PropertyChanged += (sender, args) =>
                    {
                        if (!propChanged)
                        {
                            propChanged = args.PropertyName == "IsLoaded";
                        }
                    };

                // Act
                wi.New();

                // Assert
                Assert.IsTrue(propChanged);
            }
        }
Exemplo n.º 39
0
        public void IdIsNotEmptyGuid()
        {
            // Arrange
            using (var testdb = new SqlWorkflowInstanceStoreTest())
            {
                var view = new TestWorkflowView(testdb.CreateInstanceStore());
                var model = new WorkflowModel(view);
                var wi = new WorkflowInstance(model);

                // Act
                var id = wi.Id;

                // Assert
                Assert.AreEqual(Guid.Empty, id);
            }
        }