Exemplo n.º 1
0
 public void ActionExecute(ExecutingContext executeContext)
 {
     if (executeContext.Instance.State == WorkflowInstanceState.Reject || executeContext.Instance.State == WorkflowInstanceState.Kill)
     {
         CommandBus.Dispatch <string>(new DeletePending(),
                                      executeContext.Instance.InstanceID);
     }
     else
     {
         var current = executeContext.To;
         if (current.NodeType == WorkflowNodeCategory.Decision)
         {
             DecisionJump(executeContext);
         }
         else
         {
             if (!executeContext.Result && !String.IsNullOrEmpty(executeContext.From.Cooperation))
             {
                 CooperationPending.Execute(executeContext);
             }
             else
             {
                 string instanceID = executeContext.Instance.InstanceID;
                 if (current.NodeType == WorkflowNodeCategory.End)
                 {
                     CommandBus.Dispatch <string>(new DeletePending(), instanceID);
                 }
                 else
                 {
                     AssignToPendingUser(executeContext, current);
                 }
             }
         }
     }
 }
        public void Reboot(string instanceID, string categoryCode, string id)
        {
            WorkflowInstance wfInstance  = WorkflowInstance.GetInstance(instanceID);
            string           resourceXml = wfInstance.Resource;

            CommandBus.Dispatch(new DeleteWFRecord(), instanceID);
            string newInstanceID = WorkflowEngine.Instance.Start(resourceXml);

            Bridge bridge = _bridgeService.GetBridge(id);

            bridge.InstanceID = newInstanceID;
            CommandBus.Dispatch(new UpdateBridge(), bridge);

            var user = _actorService.GetUserByID(bridge.Creator);
            WorkflowInstance instance = WorkflowInstance.GetInstance(newInstanceID);
            var current = GetCurrent(instance, bridge.Creator);

            string serialObject = GetAuditNext(current, categoryCode, bridge.Creator, user.Name, out string selectTransitionID);

            WorkflowEngine.Instance.Jump(new WorkflowContext()
            {
                Instance     = instance,
                ActorID      = bridge.Creator,
                Message      = String.Empty,
                TransitionID = selectTransitionID,
                Current      = GetCurrent(instance, bridge.Creator),
                Data         = Newtonsoft.Json.JsonConvert.DeserializeObject(serialObject)
            });
        }
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 写待办信息
        /// </summary>
        /// <param name="actorID">参与者</param>
        /// <param name="executeContext"></param>
        public void WritePending(string actorID, ExecutingContext executeContext)
        {
            var      node       = GetCurrentNode(executeContext.Instance.InstanceID);
            string   cateCode   = (String)executeContext.Data.CateCode;
            string   instanceID = (String)executeContext.Instance.InstanceID;
            Category model      = new CategoryQueryService().Query()
                                  .FirstOrDefault(cate => cate.NID == cateCode);
            string json = (String)executeContext.Data.Json;

            Pending entry = new Pending
            {
                NID            = Guid.NewGuid().ToString(),
                ActorID        = actorID,
                InstanceID     = instanceID,
                NodeID         = node.NID,
                Url            = model.Url,
                CreateDateTime = DateTime.Now,
                NodeName       = node.Name,
                CateCode       = cateCode,
                CateName       = model.Name,
                Title          = Parse(json, model.Expression)
            };

            CommandBus.Dispatch <Pending>(new CreatePending(), entry);
        }
        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 void DispatchesProperly()
    {
        var handler = new IncrementHandler(counter: 0);
        var bus     = new CommandBus((IHandler <ICommand>)handler);

        bus.Dispatch(new Increment(5));
    }
Exemplo n.º 7
0
 public void CreateOrder(CreateOrderCommand command)
 {
     EventBus.Subscribe <OrderCreatedEvent>(e =>
     {
         CommandBus.Dispatch(new UpdateScoreCommand(command.CustomerId, e.CustomerScore));
     });
     CommandBus.Dispatch(command);
 }
        public async Task <IActionResult> Index(string id, [FromBody] dynamic body)
        {
            body = JsonConvert.DeserializeObject(Convert.ToString(body));

            await _bus.Dispatch(new CreateCourseCommand(id, body["name"].ToString(), body["duration"].ToString()));

            return(StatusCode(201));
        }
 public void Delete(string instanceID, string categoryCode, string id)
 {
     CommandBus.Dispatch(new DeleteAllRecord(), new Script
     {
         CategoryCode = categoryCode,
         InstanceID   = instanceID,
         Key          = id
     });
 }
        public void Post(Bridge model)
        {
            if (queryService.Query(model.InstanceID) == null)
            {
                CommandBus.Dispatch <Bridge>(new CreateBridge(), model);
            }

            FormService.Execute(model.CategoryID, model.InstanceID);
        }
Exemplo n.º 11
0
 /// <summary>
 /// 抄送
 /// </summary>
 /// <param name="actorID">参与者</param>
 /// <param name="executeContext"></param>
 public void WriteCarbon(string actorID, string nodeID, string instanceID)
 {
     CommandBus.Dispatch(new CreateCarbonCopy(), new CarbonCopy
     {
         ActorID    = actorID,
         InstanceID = instanceID,
         NodeID     = nodeID,
         CreateTime = DateTime.Now
     });
 }
Exemplo n.º 12
0
        public async Task should_call_handle_method_on_commandHandler()
        {
            var command        = new TestCommand();
            var commandHandler = CreateHandler();
            var commandBus     = new CommandBus(CreateCommandHandlerFactory(commandHandler));

            await commandBus.Dispatch(command);

            await commandHandler.Received(Once).Handle(command);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 抄送
 /// </summary>
 /// <param name="actorID">参与者</param>
 /// <param name="executeContext"></param>
 public void WriteCarbon(string actorID, string nodeID, string instanceID)
 {
     CommandBus.Dispatch <CarbonCopy>(new CreateCarbonCopy(), new CarbonCopy
     {
         NID            = Guid.NewGuid().ToString(),
         ActorID        = actorID,
         InstanceID     = instanceID,
         NodeID         = nodeID,
         CreateDateTime = DateTime.Now
     });
 }
Exemplo n.º 14
0
        /// <summary>
        /// 多条件跳转
        /// </summary>
        /// <param name="executeContext">执行上下文</param>
        private void DecisionJump(ExecutingContext executeContext)
        {
            string instanceID = executeContext.Instance.InstanceID;
            string NID        = executeContext.From.NID;
            Dictionary <string, object> deleteArg = new Dictionary <string, object>()
            {
                { "instanceID", instanceID },
                { "nodeID", NID }
            };

            CommandBus.Dispatch <Dictionary <string, Object> >(new DeletePending(), deleteArg);
        }
 public ActionResult <string> PayAlteraion(PayAlteraionCommand command)
 {
     try
     {
         CommandBus.Dispatch(command);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
 public ActionResult <string> CheckOut(CheckSuitOutToTailorCommand command)
 {
     try
     {
         CommandBus.Dispatch(command);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
        public async Task <IActionResult> Index(CoursesPostWebModel model, int coursesCounter)
        {
            if (ModelState.IsValid)
            {
                await _bus.Dispatch(new CreateCourseCommand(model.Id, model.Name, model.Duration));

                return(RedirectToAction("Index", "CoursesGetWeb"));
            }

            ViewBag.CoursesCounter = coursesCounter;
            ViewBag.UUID           = model.Id;

            return(View(VIEW));
        }
Exemplo n.º 18
0
        public static void Execute(ExecutingContext executeContext)
        {
            string instanceID = executeContext.Instance.InstanceID;
            string nodeID     = executeContext.Instance.Current.NID;
            string actorID    = (String)executeContext.Data.UUID;

            Dictionary <string, object> deleteArg = new Dictionary <string, object>()
            {
                { "instanceID", instanceID },
                { "nodeID", nodeID },
                { "actorID", actorID }
            };

            CommandBus.Dispatch <Dictionary <string, Object> >(new DeletePendingByActor(), deleteArg);
        }
Exemplo n.º 19
0
        public static void Execute(ExecutingContext executeContext)
        {
            string instanceID = executeContext.Instance.InstanceID;
            string nodeID     = executeContext.Direction == WorkflowOpertaion.Back ? executeContext.From.NID
                : executeContext.To.NID;

            string actorID = (String)executeContext.Data.UUID;
            Dictionary <string, object> deleteArg = new Dictionary <string, object>()
            {
                { "instanceID", instanceID },
                { "nodeID", nodeID },
                { "actorID", actorID }
            };

            CommandBus.Dispatch(new DeletePendingByActor(), deleteArg);
        }
Exemplo n.º 20
0
        public void ActionExecute(ExecutingContext executeContext)
        {
            if (executeContext.Instance.State == WorkflowInstanceState.Reject)
            {
                CommandBus.Dispatch <string>(new DeletePending(),
                                             executeContext.Instance.InstanceID);
            }
            else
            {
                if (executeContext.Instance.Current.NodeType == WorkflowNodeCategory.Decision)
                {
                    DecisionJump(executeContext);
                }

                if (!executeContext.Result && executeContext.Instance.Current.Cooperation == 1)
                {
                    CooperationPending.Execute(executeContext);
                }
                else
                {
                    string instanceID = executeContext.Instance.InstanceID;
                    var    current    = GetCurrentNode(instanceID);
                    if (current.NodeType == WorkflowNodeCategory.End)
                    {
                        CommandBus.Dispatch <string>(new DeletePending(), instanceID);
                    }
                    else
                    {
                        List <User> userList = GetUserByGroup(current.Groups, current.Actors);
                        foreach (User user in userList)
                        {
                            WritePending(user.UniqueId, executeContext);
                        }

                        string NID = executeContext.Instance.Current.NID;

                        Dictionary <string, object> deleteArg = new Dictionary <string, object>()
                        {
                            { "instanceID", instanceID },
                            { "nodeID", NID }
                        };

                        CommandBus.Dispatch <Dictionary <string, Object> >(new DeletePending(), deleteArg);
                    }
                }
            }
        }
 public void Delete(PendingDeleteBody dto)
 {
     string[] ids = dto.ActorIDs.Split(',');
     if (ids.Length > 0)
     {
         WorkflowInstance instance = WorkflowInstance.GetInstance(dto.ID);
         var node = instance.Current.FirstOrDefault(e => e.ID == dto.NodeID);
         foreach (string actor in ids)
         {
             CommandBus.Dispatch(new DeletePendingByActor(), new Dictionary <string, object>
             {
                 { "instanceID", dto.ID },
                 { "nodeID", node.NID },
                 { "actorID", actor }
             });
         }
     }
 }
Exemplo n.º 22
0
 public void ActionExecute(ExecutingContext executeContext)
 {
     if (executeContext.Instance.Current.NodeType != WorkflowNodeCategory.Decision)
     {
         string UUID          = (String)executeContext.Data.UUID;
         string auditUserName = (String)executeContext.Data.Name;
         string sign          = string.Empty;
         CommandBus.Dispatch <Record>(new CreateRecord(), new Record
         {
             InstanceID     = executeContext.Instance.InstanceID,
             Name           = executeContext.From.Name,
             Comment        = executeContext.Data.Message,
             CreateDateTime = DateTime.Now,
             AuditUserID    = UUID,
             Url            = sign,
             AuditUserName  = auditUserName,
             NID            = Guid.NewGuid().ToString()
         });
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// 写待办信息
        /// </summary>
        /// <param name="actorID">参与者</param>
        /// <param name="executeContext">执行上下文</param>
        public void WritePending(string actorID, ExecutingContext executeContext)
        {
            var    node         = executeContext.To;
            string CategoryCode = (String)executeContext.Data.CategoryCode;
            string instanceID   = (String)executeContext.Instance.InstanceID;

            Category model = new CategoryService().Query()
                             .FirstOrDefault(cate => cate.NID == CategoryCode);

            CommandBus.Dispatch(new CreatePending(), new Pending
            {
                NID          = Guid.NewGuid().ToString(),
                ActorID      = actorID,
                InstanceID   = instanceID,
                NodeID       = node.NID,
                Url          = model.Url,
                CreateTime   = DateTime.Now,
                NodeName     = node.Name,
                CategoryCode = CategoryCode,
                CategoryName = model.Name
            });
        }
Exemplo n.º 24
0
        /// <summary>
        /// 分派到人
        /// </summary>
        private void AssignToPendingUser(ExecutingContext executeContext, Node current)
        {
            string instanceID = executeContext.Instance.InstanceID;
            //会签或分支节点取默认参与人者;非会签取用户选择的参与者
            bool        result   = (!String.IsNullOrEmpty(executeContext.From.Cooperation) || executeContext.From.NodeType == WorkflowNodeCategory.Decision || executeContext.From.NodeType == WorkflowNodeCategory.Fork || executeContext.From.NodeType == WorkflowNodeCategory.Merge);
            List <User> userList = result ?
                                   bridgeService.GetActorByGroup(current, executeContext.Direction) :
                                   bridgeService.GetActorByGroup((String)executeContext.Data.Actor, (String)executeContext.Data.Group, (String)executeContext.Data.Organization, current, executeContext.Direction);

            CommandBus.Dispatch <Dictionary <string, Object> >(new DeletePending(), new Dictionary <string, object>()
            {
                { "instanceID", instanceID },
                { "nodeID", executeContext.From.NID }
            });

            foreach (User user in userList)
            {
                WritePending(user.ID, executeContext);
            }

            CommandBus.Dispatch(new CreateAssistant(), instanceID);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 多条件跳转
        /// </summary>
        /// <param name="executeContext">执行上下文</param>
        private void DecisionJump(ExecutingContext executeContext)
        {
            string instanceID = executeContext.Instance.InstanceID;
            string NID        = executeContext.Instance.Current.NID;
            var    current    = GetCurrentNode(executeContext.Instance.InstanceID);

            if (current.NodeType != WorkflowNodeCategory.Decision)
            {
                List <User> userList = bridgeService.GetActorByGroup(current, executeContext.Direction);
                foreach (var user in userList)
                {
                    WritePending(user.UniqueId, executeContext);
                }
            }

            Dictionary <string, object> deleteArg = new Dictionary <string, object>()
            {
                { "instanceID", instanceID },
                { "nodeID", NID }
            };

            CommandBus.Dispatch <Dictionary <string, Object> >(new DeletePending(), deleteArg);
        }
Exemplo n.º 26
0
        public void ActionExecute(ExecutingContext executeContext)
        {
            var current = executeContext.From;

            if (executeContext.Instance.State != WorkflowInstanceState.Kill && current.NodeType != WorkflowNodeCategory.Decision && current.NodeType != WorkflowNodeCategory.Fork && current.NodeType != WorkflowNodeCategory.Merge)
            {
                string UUID          = (String)executeContext.Data.UUID;
                string auditUserName = (String)executeContext.Data.Name;

                CommandBus.Dispatch(new CreateRecord(), new Record
                {
                    InstanceID    = executeContext.Instance.InstanceID,
                    Name          = executeContext.From.Name,
                    NodeID        = executeContext.From.NID,
                    Comment       = executeContext.Message,
                    CreateTime    = DateTime.Now,
                    AuditUserID   = UUID,
                    Url           = string.Empty,
                    AuditUserName = auditUserName,
                    NID           = Guid.NewGuid().ToString(),
                });
            }
        }
        public void Persistent(PendingBody dto)
        {
            WorkflowInstance instance = WorkflowInstance.GetInstance(dto.ID);
            var      node             = instance.Current.FirstOrDefault(e => e.ID == dto.NodeID);
            Category model            = _categoryService.Query().FirstOrDefault(cate => cate.NID == dto.CategoryCode);

            string[] ids = dto.ActorIDs.Split(',');
            foreach (string id in ids)
            {
                CommandBus.Dispatch(new CreatePending(), new Pending
                {
                    NID          = Guid.NewGuid().ToString(),
                    ActorID      = id,
                    InstanceID   = instance.InstanceID,
                    NodeID       = node.NID,
                    Url          = model.Url,
                    CreateTime   = DateTime.Now,
                    NodeName     = node.Name,
                    CategoryCode = dto.CategoryCode,
                    CategoryName = model.Name
                });
            }
        }
 public void ShiftSegmentUpdate(ShiftSegmentUpdateCommand command)
 {
     CommandBus.Dispatch(command);
 }
 public void ShiftSegmentRemove(ShiftSegmentRemoveCommand command)
 {
     CommandBus.Dispatch(command);
 }
 public void ShiftSegmentAdd(ShiftSegmentAddCommand command)
 {
     CommandBus.Dispatch(command);
 }