예제 #1
0
        /// <inheritdoc />
        public async Task UpdateWorkflow(long workflowid, WorkflowStructure data)
        {
            if (data.Transitions != null)
            {
                int nodecount = data.Nodes?.Length ?? 0;
                foreach (IndexTransition transition in data.Transitions)
                {
                    if (transition.OriginIndex < 0 || transition.OriginIndex >= nodecount)
                    {
                        throw new IndexOutOfRangeException("Transition origin index out of range");
                    }
                    if (transition.OriginIndex < 0 || transition.TargetIndex < 0 || transition.OriginIndex >= nodecount || transition.TargetIndex >= nodecount)
                    {
                        throw new IndexOutOfRangeException("Transition target index out of range");
                    }
                }
            }

            using Transaction transaction = database.Transaction();
            await ArchiveWorkflow(transaction, workflowid);

            await DeleteNodes(transaction, workflowid);
            await DeleteTransitions(transaction, workflowid);
            await UpdateWorkflow(transaction, workflowid, data.Name, data.Language);
            await CreateNodeAndTransitions(transaction, workflowid, data.Nodes, data.Transitions);

            transaction.Commit();
        }
        public string Start(BridgeBody dto)
        {
            Category          category          = new CategoryService().Query().FirstOrDefault(cate => cate.NID == dto.CategoryCode);
            WorkflowStructure workflowStructure =
                _abstractService.WorkflowStructureService.Query().FirstOrDefault(e => e.CategoryCode == category.NID && e.Status == 1);
            string instanceID = WorkflowEngine.Instance.Start(workflowStructure.Resource);

            Bridge model = _mapper.Map <Bridge>(dto);

            model.InstanceID = instanceID;
            model.Comment    = String.IsNullOrEmpty(model.Comment) ? category.Name : model.Comment;
            model.CreateTime = DateTime.Now;
            CommandBus.Dispatch(new CreateBridge(), model);
            var user = _actorService.GetUserByID(model.Creator);
            WorkflowInstance Instance = WorkflowInstance.GetInstance(instanceID);
            var    current            = GetCurrent(Instance, model.Creator);
            string serialObject       = GetAuditNext(current, model.CategoryCode, model.Creator, user.Name, out string selectTransitionID);

            WorkflowEngine.Instance.Jump(new WorkflowContext()
            {
                Instance     = Instance,
                ActorID      = model.Creator,
                Message      = category.Name,
                TransitionID = selectTransitionID,
                Data         = Newtonsoft.Json.JsonConvert.DeserializeObject(serialObject),
                Current      = current
            });

            LogProxy.Instance.Info(string.Format("启动{0}流程 实例ID{1}", model.CategoryCode, instanceID));
            return(instanceID);
        }
예제 #3
0
        /// <inheritdoc />
        public async Task <long> CreateWorkflow(WorkflowStructure data)
        {
            if (data.Transitions != null)
            {
                int nodecount = data.Nodes?.Length ?? 0;
                foreach (IndexTransition transition in data.Transitions)
                {
                    if (transition.OriginIndex < 0 || transition.OriginIndex >= nodecount)
                    {
                        throw new IndexOutOfRangeException("Transition origin index out of range");
                    }
                    if (transition.OriginIndex < 0 || transition.TargetIndex < 0 || transition.OriginIndex >= nodecount || transition.TargetIndex >= nodecount)
                    {
                        throw new IndexOutOfRangeException("Transition target index out of range");
                    }
                    if (transition.OriginIndex == transition.TargetIndex)
                    {
                        throw new InvalidOperationException("Transition target must not be the same node as origin");
                    }
                }
            }

            using Transaction transaction = database.Transaction();

            long workflowid = await insertworkflow.ExecuteAsync(1, data.Name, data.Language);

            await CreateNodeAndTransitions(transaction, workflowid, data.Nodes, data.Transitions);

            transaction.Commit();
            return(workflowid);
        }
        public async Task <WorkflowDetails> UpdateWorkflow(long workflowid, [FromBody] WorkflowStructure data)
        {
            logger.LogInformation("Updating workflow '{workflowid}'", workflowid);
            await workflowservice.UpdateWorkflow(workflowid, data);

            return(await workflowservice.GetWorkflow(workflowid));
        }
        public string Start(BridgeCommandDto dto)
        {
            Category category = new CategoryService().Query()
                                .FirstOrDefault(cate => cate.NID == dto.CategoryCode);

            WorkflowStructure workflowStructure =
                _abstractService.WorkflowStructureService.Query()
                .FirstOrDefault(e => e.CategoryCode == category.NID && e.Status == 1);

            var    model      = EmitCore.Convert <BridgeCommandDto, Bridge>(dto);
            string instanceID = WorkflowEngine.Instance.Start(workflowStructure.Resource);

            model.InstanceID = instanceID;
            model.Comment    = String.IsNullOrEmpty(model.Comment) ? category.Name : model.Comment;
            model.CreateTime = DateTime.Now;
            CommandBus.Dispatch(new CreateBridge(), model);

            var b = _bridgeService.Query(instanceID);
            WorkflowInstance Instance = WorkflowInstance.GetInstance(instanceID);
            var    current            = GetCurrent(Instance, model.Creator);
            string serialObject       = GetAuditNext(current, model.CategoryCode, b.Creator, b.Name, out string selectTransitionID);

            WorkflowEngine.Instance.Jump(new WorkflowContext()
            {
                Instance     = Instance,
                ActorID      = model.Creator,
                Message      = "提交",
                TransitionID = selectTransitionID,
                Data         = Newtonsoft.Json.JsonConvert.DeserializeObject(serialObject),
                Current      = current
            });

            return(instanceID);
        }
        public string Start(string id)
        {
            Category          category          = _categoryService.Query().FirstOrDefault(cate => cate.NID == id);
            WorkflowStructure workflowStructure =
                _abstractBridgeService.WorkflowStructureService.Query()
                .FirstOrDefault(e => e.CateCode == category.NID && e.Status == 1);

            return(WorkflowEngine.Instance.Start(workflowStructure.StructXml));
        }
        public JsonResult GetWorkflowStructure(string WFID)
        {
            WorkflowStructure workflowStructure = designService.GetWorkflowStructure(WFID);

            return(JsonToLowerWrapper(new
            {
                appellation = workflowStructure.APPELLATION,
                structure = GetNodeList(workflowStructure.STRUCTUREXML)
            }));
        }
        public JsonResult GetWorkflowStructure(string WFID)
        {
            WorkflowStructure workflowStructure = designService.GetWorkflowStructure(WFID);

            return(Json(new
            {
                appellation = workflowStructure.APPELLATION,
                structure = workflowStructure.STRUCTUREXML
            }));
        }
예제 #9
0
        public ActionResult StartWebPageView(string id)
        {
            WorkflowStructure structure = designService.GetWorkflowStructure(id);

            Smartflow.Elements.Form         webForm = workflowEngine.Ready(structure.STRUCTUREXML);
            Stack <Smartflow.Elements.Form> stack   = new Stack <Smartflow.Elements.Form>();

            stack.Push(webForm);
            ViewBag.Stack = stack;
            return(View());
        }
예제 #10
0
        public JsonResult SaveWebView(string relation, string form, string resourceID)
        {
            Relation          r         = JsonConvert.DeserializeObject <Relation>(relation);
            Object            proxy     = JsonConvert.DeserializeObject(form, DynamicRepository.BuildDynamicObjectType(r));
            WorkflowStructure structure = designService.GetWorkflowStructure(resourceID);
            IBase             entity    = (proxy as IBase);

            entity.INSTANCEID = workflowEngine.Start(structure.STRUCTUREXML);
            entity.RESOURCEID = resourceID;
            DynamicRepository.Persistent(entity, r);


            return(Json(true));
        }
 public JsonResult Save(WorkflowStructure model)
 {
     model.STRUCTUREXML = Uri.UnescapeDataString(model.STRUCTUREXML);
     if (String.IsNullOrEmpty(model.IDENTIFICATION))
     {
         model.IDENTIFICATION = Guid.NewGuid().ToString();
         designService.Persistent(model);
     }
     else
     {
         designService.Update(model);
     }
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
 public JsonResult Save(WorkflowStructure model)
 {
     model.STRUCTUREXML = System.Web.HttpContext.Current.Server.UrlDecode(model.STRUCTUREXML);
     if (String.IsNullOrEmpty(model.IDENTIFICATION))
     {
         model.IDENTIFICATION = Guid.NewGuid().ToString();
         designService.Persistent(model);
     }
     else
     {
         designService.Update(model);
     }
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
 public JsonResult Save(WorkflowStructure model)
 {
     if (String.IsNullOrEmpty(model.IDENTIFICATION))
     {
         model.IDENTIFICATION = Guid.NewGuid().ToString();
         model.FILESTRUCTURE  = HttpUtility.UrlDecode(model.FILESTRUCTURE);
         designService.Persistent(model);
     }
     else
     {
         model.FILESTRUCTURE = HttpUtility.UrlDecode(model.FILESTRUCTURE);
         designService.Update(model);
     }
     return(Json(true));
 }
        public void Post([FromBody] WorkflowStructure workflowStructure)
        {
            workflowStructure.StructXml      = Uri.UnescapeDataString(workflowStructure.StructXml);
            workflowStructure.CreateDateTime = DateTime.Now;
            WorkflowStructure model = this.Get(workflowStructure.NID);

            if (model != null)
            {
                if (workflowStructure.CateCode != model.CateCode)
                {
                    workflowStructure.Status = 0;
                }
            }

            _abstractBridgeService.WorkflowStructureService.Persistent(workflowStructure);
        }
        public void Persistent(WorkflowStructureBody commandDto)
        {
            commandDto.Resource = Uri.UnescapeDataString(commandDto.Resource);
            WorkflowStructure structure = _mapper.Map <WorkflowStructureBody, WorkflowStructure>(commandDto);

            structure.CreateTime = DateTime.Now;
            if (!String.IsNullOrEmpty(commandDto.NID))
            {
                WorkflowStructure model = _abstractService.WorkflowStructureService.Get(structure.NID);
                if (model != null)
                {
                    if (structure.CategoryCode != model.CategoryCode)
                    {
                        structure.Status = 0;
                    }
                }
            }
            _abstractService.WorkflowStructureService.Persistent(structure);
        }
        public void Update(string id, int status)
        {
            WorkflowStructure model = _abstractService.WorkflowStructureService.Get(id);

            model.Status = status;
            if (model.Status == 1)
            {
                IList <WorkflowStructure> wfList = _abstractService
                                                   .WorkflowStructureService.Query().Where(e => e.CategoryCode == model.CategoryCode && e.NID != model.NID && e.Status == 1)
                                                   .ToList <WorkflowStructure>();

                foreach (WorkflowStructure entry in wfList)
                {
                    entry.Status = 0;
                    _abstractService.WorkflowStructureService.Persistent(entry);
                }
            }
            _abstractService.WorkflowStructureService.Persistent(model);
        }
예제 #17
0
        public dynamic Start(string id)
        {
            Category category = new CategoryQueryService().Query()
                                .FirstOrDefault(cate => cate.NID == id);

            WorkflowStructure workflowStructure =
                baseBridgeService.WorkflowStructureService.Query()
                .FirstOrDefault(e => e.CateCode == category.NID && e.Status == 1);

            string instanceID = WorkflowEngine.Instance.Start(workflowStructure.StructXml);

            Node   current = WorkflowInstance.GetInstance(instanceID).Current;
            string to      = current.Transitions.FirstOrDefault().NID;

            return(new
            {
                InstanceID = instanceID,
                To = to
            });
        }
예제 #18
0
        public void Put([FromBody] WorkflowStructure workflowStructure)
        {
            WorkflowStructure model = this.Get(workflowStructure.NID);

            model.Status = workflowStructure.Status;

            if (model.Status == 1)
            {
                IList <WorkflowStructure> wfList = baseBridgeService
                                                   .WorkflowStructureService.Query().Where(e => e.CateCode == model.CateCode && e.NID != model.NID && e.Status == 1)
                                                   .ToList <WorkflowStructure>();

                foreach (WorkflowStructure entry in wfList)
                {
                    entry.Status = 0;
                    baseBridgeService.WorkflowStructureService.Persistent(entry);
                }
            }
            baseBridgeService.WorkflowStructureService.Persistent(model);
        }
        public void Update(WorkflowStructureRequstDto dto)
        {
            WorkflowStructure model = _abstractService
                                      .WorkflowStructureService.Query(dto.NID).FirstOrDefault();

            model.Status = dto.Status;

            if (model.Status == 1)
            {
                IList <WorkflowStructure> wfList = _abstractService
                                                   .WorkflowStructureService.Query().Where(e => e.CategoryCode == model.CategoryCode && e.NID != model.NID && e.Status == 1)
                                                   .ToList <WorkflowStructure>();

                foreach (WorkflowStructure entry in wfList)
                {
                    entry.Status = 0;
                    _abstractService.WorkflowStructureService.Persistent(entry);
                }
            }
            _abstractService.WorkflowStructureService.Persistent(model);
        }
        public void Post(WorkflowStructureCommandDto dto)
        {
            dto.Resource = Uri.UnescapeDataString(dto.Resource);
            if (!String.IsNullOrEmpty(dto.NID))
            {
                WorkflowStructure model = _abstractService.WorkflowStructureService
                                          .Query(dto.NID).FirstOrDefault();
                if (model != null)
                {
                    if (dto.CategoryCode != model.CategoryCode)
                    {
                        dto.Status = 0;
                    }
                }
            }

            var w = EmitCore.Convert <WorkflowStructureCommandDto, WorkflowStructure>(dto);

            w.CreateTime = DateTime.Now;
            _abstractService.WorkflowStructureService.Persistent(w);
        }
예제 #21
0
        /// <inheritdoc />
        public async Task <WorkflowInstance> BuildWorkflow(WorkflowStructure workflow)
        {
            logger.LogInformation("Building workflow '{name}'", workflow.Name);
            int startcount = workflow.Nodes.Count(n => n.Type == NodeType.Start);

            if (startcount == 0)
            {
                throw new ArgumentException("Workflow has no start node");
            }
            if (startcount > 1)
            {
                throw new ArgumentException("Workflow has more than one start node");
            }

            StartNode startnode = null;

            List <IInstanceNode> nodes = new List <IInstanceNode>();

            foreach (NodeData node in workflow.Nodes)
            {
                IInstanceNode nodeinstance = await BuildNode(workflow.Language, node);

                nodes.Add(nodeinstance);
                if (nodeinstance is StartNode startinstance)
                {
                    startnode = startinstance;
                }
            }

            foreach (IndexTransition transition in workflow.Transitions)
            {
                await BuildTransition(workflow, transition.OriginIndex, transition.TargetIndex, transition, i => nodes[i]);
            }

            return(new WorkflowInstance {
                Name = workflow.Name,
                StartNode = startnode,
                Language = workflow.Language
            });
        }
예제 #22
0
        public void Reboot(WorkflowDeleteDto dto)
        {
            CommandBus.Dispatch <string>(new DeleteWFRecord(), dto.InstanceID);
            WorkflowStructure workflowStructure =
                _abstractService.WorkflowStructureService.Query()
                .FirstOrDefault(e => e.CateCode == dto.CategoryID && e.Status == 1);

            string instanceID = WorkflowEngine.Instance.Start(workflowStructure.StructXml);
            Bridge bridge     = _bridgeService.GetBridge(dto.Key);

            bridge.InstanceID = instanceID;
            CommandBus.Dispatch <Bridge>(new UpdateBridge(), bridge);

            WorkflowInstance instance = WorkflowInstance.GetInstance(instanceID);
            var current = GetCurrent(instance, bridge.Creator);
            List <Transition> transitions      = NodeService.GetExecuteTransition(current);
            Transition        transitionSelect = transitions.FirstOrDefault();

            Node nextNode = NodeService.FindNodeByID(transitionSelect.Destination, instanceID);
            var  node     = NodeService.GetNode(nextNode);

            List <string> groupIDs        = new List <string>();
            List <string> actorIDs        = new List <string>();
            List <string> carbonIDs       = new List <string>();
            List <string> organizationIDs = new List <string>();

            foreach (Group g in node.Groups)
            {
                groupIDs.Add(g.ID.ToString());
            }
            foreach (Carbon c in node.Carbons)
            {
                carbonIDs.Add(c.ID.ToString());
            }
            foreach (Actor item in node.Actors)
            {
                actorIDs.Add(item.ID);
            }
            foreach (Smartflow.Elements.Organization item in node.Organizations)
            {
                organizationIDs.Add(item.ID);
            }

            var serialObject = Newtonsoft.Json.JsonConvert.SerializeObject(new
            {
                CateCode = dto.CategoryID,
                UUID     = bridge.Creator,
                bridge.Name,
                Group        = string.Join(",", groupIDs),
                Actor        = string.Join(",", actorIDs),
                Carbon       = string.Join(",", carbonIDs),
                Organization = string.Join(",", organizationIDs)
            });

            WorkflowEngine.Instance.Jump(new WorkflowContext()
            {
                Instance     = instance,
                ActorID      = bridge.Creator,
                Message      = String.Empty,
                TransitionID = transitionSelect.NID,
                Current      = GetCurrent(instance, bridge.Creator),
                Data         = Newtonsoft.Json.JsonConvert.DeserializeObject(serialObject)
            });
        }
        public JsonResult GetWorkflowStructure(string WFID)
        {
            WorkflowStructure model = designService.GetWorkflowStructure(WFID);

            return(Json(model));
        }
 public async Task <WorkflowDetails> CreateWorkflow([FromBody] WorkflowStructure data)
 {
     logger.LogInformation("Creating new workflow");
     return(await workflowservice.GetWorkflow(await workflowservice.CreateWorkflow(data)));
 }
예제 #25
0
 public void Post([FromBody] WorkflowStructure workflowStructure)
 {
     workflowStructure.StructXml      = Uri.UnescapeDataString(workflowStructure.StructXml);
     workflowStructure.CreateDateTime = DateTime.Now;
     baseBridgeService.WorkflowStructureService.Persistent(workflowStructure);
 }