Ejemplo n.º 1
0
        private bool CanUserApproveHelper(WorkflowActor actor, WorkflowProcess process, int workflowLevelId = -1)
        {
            //var actor = _actors.Table.FirstOrDefault(x => x.ActorRefId == userRefId.ToString());
            //var process = _processes.Table.FirstOrDefault(x => x.ProcessRefId == processRefId.ToString());
            if (actor == null || process == null) return false;
            if (process.Closed)
                return false;

            var currentLevel = process.CurrentLevel ?? GetWorkflowLevel(process.CurrentLevelId);
            if (currentLevel == null) return false;
            var actorInLevel = _actorsInLevels.Table.FirstOrDefault(x => x.WorkflowLevelId == currentLevel.Id
                                                                         && x.ActorId == actor.Id);
            if (actorInLevel == null) return false;
            var hasUserApproved = HasUserApproved(actor, process, workflowLevelId: currentLevel.Id);

            if (hasUserApproved) return false; //not approved before

            // var _Xpression = _levelParameters.Table.Where(x => x.WorkflowLevelId == currentLevel.Id).FirstOrDefault();
            var approvalHistory = _histories.Table.Where(x => x.Approved && x.LevelId == currentLevel.Id
                                                              && x.ProcessId == process.Id);

            //TO DO . . .
            //one of the actors in this current level must hv approved, just for confirmation, they may hv changed the workflow . . .

            //var _actorsInLevel = GetUsersInLevel(currentLevel.Id).Select(x=>x.Id);
            // approvalHistory = approvalHistory.Where(x => _actorsInLevel.Contains(x.ActorId));

            //We may need to uncomment this later . . .
            if (currentLevel.MaximumApprovalRequired > 0)
                return approvalHistory.Count() != currentLevel.MaximumApprovalRequired;
            //var actorsInLevel = GetUsersInLevel(currentLevel.Id);
            //if (actorsInLevel.Count() < currentLevel.MaximumApprovalRequired)
            //    throw new WorkflowConfigurationError("The Maximum Allowable Approval for Workflow Level: " + currentLevel.Name + " is " + currentLevel.MaximumApprovalRequired + ". Only a total number of " + actorsInLevel.Count() + " Actors, which is less, can be found.");
            return true; //approvalHistory.Count() != currentLevel.MaximumApprovalRequired;
        }
Ejemplo n.º 2
0
 public Activity(WorkflowProcess workflowProcess, String name)
     : base(workflowProcess, name)
 {
     this.TaskRefs = new List<TaskRef>();
     this.InlineTasks = new List<Task>();
     this.CompletionStrategy = FormTaskEnum.ALL;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Загружает процесс по идентификатору
        /// </summary>
        /// <param name="processId">Идентификатор процесса</param>
        /// <returns>Загруженный процесс</returns>
        //[SmartCache(TimeOutSeconds = 600)]
        public WorkflowProcess LoadProcessById(Guid processId)
        {
            ProcessCacheLock.AcquireReaderLock(LockTimeout);
            try
            {
                var cached = ProcessCache.Find(processId);
                if (cached != null)
                {
                    return(cached.CachedObject);
                }

                var lc = ProcessCacheLock.UpgradeToWriterLock(LockTimeout);
                try
                {
                    cached = ProcessCache.Find(processId);
                    if (cached != null)
                    {
                        return(cached.CachedObject);
                    }

                    var process =
                        DataContext.GetEntityDataContext()
                        .Entities.Object_Defs.OfType <Workflow_Process>()
                        .FirstOrDefault(p => p.Id == processId);

                    var startActivityId = GetProcessStartActivity(processId);

                    if (process != null)
                    {
                        var returnProcess = new WorkflowProcess(process, startActivityId);

                        ProcessCache.Add(returnProcess, processId);

                        return(returnProcess);
                    }
                }
                finally
                {
                    ProcessCacheLock.DowngradeFromWriterLock(ref lc);
                }
                return(null);
            }
            finally
            {
                ProcessCacheLock.ReleaseReaderLock();
            }
        }
Ejemplo n.º 4
0
        protected Synchronizer createSynchronizer(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return(null);
            }

            Synchronizer synchronizer = new Synchronizer(wp, GetAttributeValue(xElement, NAME));

            synchronizer.Sn          = Guid.NewGuid().ToString();
            synchronizer.DisplayName = GetAttributeValue(xElement, DISPLAY_NAME);

            synchronizer.Description = GetElementValue(xElement, "{" + FPDL_URI + "}" + DESCRIPTION);
            loadExtendedAttributes(synchronizer.ExtendedAttributes, xElement.Element("{" + FPDL_URI + "}" + EXTENDED_ATTRIBUTES));

            return(synchronizer);
        }
 /// <summary>获取业务流程对象</summary>
 public static WorkflowProcess getWorkflowProcess(IWorkflowDefinition wdf)// throws RuntimeException
 {
     if (!dic_wp.ContainsKey(wdf.Id))
     {
         if (wdf.ProcessContent != null && !String.IsNullOrEmpty(wdf.ProcessContent.Trim()))
         {
             Dom4JFPDLParser parser          = new Dom4JFPDLParser();
             WorkflowProcess workflowProcess = parser.parse(wdf.ProcessContent);
             if (workflowProcess != null)
             {
                 dic_wp[wdf.Id] = workflowProcess;
             }
         }
     }
     dic_wp[wdf.Id].Sn = wdf.Id;
     return(dic_wp[wdf.Id]);
 }
Ejemplo n.º 6
0
        protected EndNode createEndNode(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return(null);
            }

            EndNode endNode = new EndNode(wp, GetAttributeValue(xElement, NAME));

            endNode.Sn          = Guid.NewGuid().ToString();
            endNode.DisplayName = GetAttributeValue(xElement, DISPLAY_NAME);

            endNode.Description = GetElementValue(xElement, "{" + FPDL_URI + "}" + DESCRIPTION);
            loadExtendedAttributes(endNode.ExtendedAttributes, xElement.Element("{" + FPDL_URI + "}" + EXTENDED_ATTRIBUTES));

            return(endNode);
        }
Ejemplo n.º 7
0
        public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext, IProcessInstance processInstance, ITaskInstance taskInstance)// throws EngineException, KernelException
        {
            if (taskInstance.TaskType != TaskTypeEnum.TOOL)
            {
                throw new EngineException(processInstance, taskInstance.Activity,
                                          "DefaultToolTaskInstanceRunner:TaskInstance的任务类型错误,只能为TOOL类型");
            }
            Task task = taskInstance.Task;

            if (task == null)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                                          "The Task is null,can NOT start the taskinstance,");
            }
            if (((ToolTask)task).Application == null || ((ToolTask)task).Application.Handler == null)
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                                          "The task.Application is null or task.Application.Handler is null,can NOT start the taskinstance,");
            }

            Object obj = runtimeContext.getBeanByName(((ToolTask)task).Application.Handler);

            if (obj == null || !(obj is IApplicationHandler))
            {
                WorkflowProcess process = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, process, taskInstance.TaskId,
                                          "Run tool task instance error! Not found the instance of " + ((ToolTask)task).Application.Handler + " or the instance not implements IApplicationHandler");
            }

            try
            {
                ((IApplicationHandler)obj).execute(taskInstance);
            }
            catch (Exception)
            {//TODO wmj2003 对tool类型的task抛出的错误应该怎么处理? 这个时候引擎会如何?整个流程是否还可以继续?
                throw new EngineException(processInstance, taskInstance.Activity,
                                          "DefaultToolTaskInstanceRunner:TaskInstance的任务执行失败!");
            }

            ITaskInstanceManager taskInstanceManager = runtimeContext.TaskInstanceManager;

            taskInstanceManager.completeTaskInstance(currentSession, processInstance, taskInstance, null);
        }
Ejemplo n.º 8
0
        protected void loadStartNode(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return;
            }

            StartNode startNode = new StartNode(wp);

            startNode.Name        = GetAttributeValue(xElement, NAME);
            startNode.Sn          = Guid.NewGuid().ToString();
            startNode.DisplayName = GetAttributeValue(xElement, DISPLAY_NAME);

            startNode.Description = GetElementValue(xElement, "{" + FPDL_URI + "}" + DESCRIPTION);
            loadExtendedAttributes(startNode.ExtendedAttributes, xElement.Element("{" + FPDL_URI + "}" + EXTENDED_ATTRIBUTES));

            wp.StartNode = startNode;
        }
Ejemplo n.º 9
0
        protected void loadActivities(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return;
            }
            wp.Activities = new List <Activity>();

            var partNos = GetXElements(xElement, ACTIVITY);

            foreach (XElement node in partNos)
            {
                Activity a = createActivitie(wp, node);
                if (a != null)
                {
                    wp.Activities.Add(a);
                }
            }
        }
Ejemplo n.º 10
0
        void dsc_GetWorkflowProcessXmlCompleted(object sender, GetWorkflowProcessXmlCompletedEventArgs e)
        {
            if (String.IsNullOrEmpty(e.Result))
            {
                return;
            }
            //流程图初始化
            MemoryStream    msin = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));
            Dom4JFPDLParser djp  = new Dom4JFPDLParser();

            this.WorkflowProcessCurrent = djp.parse(msin);
            loadWorkflow.LoadWorkflowProcessToFrom(this.WorkflowProcessCurrent);

            //流程跟踪
            if (queryString.ContainsKey("ProcessInstanceId"))
            {
                GetProcessInstanceTraceXml(queryString["ProcessInstanceId"]);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="processInstanceId">发生异常的流程实例Id</param>
        /// <param name="process">发生异常的流程</param>
        /// <param name="workflowElementId">发生异常的环节或者Task的Id</param>
        /// <param name="errMsg">错误信息</param>
        public EngineException(String processInstanceId, WorkflowProcess process, String workflowElementId, String errMsg)
            : base(null, null, errMsg)
        {
            this.ProcessInstanceId = processInstanceId;
            if (process != null)
            {
                this.ProcessId          = process.Id;
                this.ProcessName        = process.Name;
                this.ProcessDisplayName = process.DisplayName;

                IWFElement workflowElement = process.findWFElementById(workflowElementId);
                if (workflowElement != null)
                {
                    this.WorkflowElementId          = workflowElement.Id;
                    this.WorkflowElementName        = workflowElement.Name;
                    this.WorkflowElementDisplayName = workflowElement.DisplayName;
                }
            }
        }
Ejemplo n.º 12
0
        public IHttpActionResult RejectWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess process     = instance.GetProcess();
                IUser           currentUser = _utility.GetCurrentUser();

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Reject,
                    currentUser.Id,
                    model.Comment
                    );

                string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate);

                Log.Info($"{typeDescription} request for {instance.Node.Name} [{instance.NodeId}] was rejected by {currentUser.Name}");

                _hubContext.Clients.All.TaskRejected(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance));

                if (model.Offline)
                {
                    UmbracoContext.Security.ClearCurrentLogin();
                }

                return(Json(new
                {
                    message = typeDescription + " request has been rejected.",
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred rejecting the workflow on {instance.Node.Name} [{instance.NodeId}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Ejemplo n.º 13
0
        public void Update(Guid processID, WorkflowProcess _WorkflowProcess)
        {
            List <sysBpmsLane> Lanes = this.GetList(processID);
            var CurrentWorkflowLane  = WorkflowLane.GetAllLanes(_WorkflowProcess.LaneSet);

            foreach (sysBpmsLane item in Lanes.Where(c => !CurrentWorkflowLane.Any(d => d.ID == c.ElementID)))
            {
                this.Delete(item.ID);
            }

            //StartEvents
            foreach (WorkflowLane item in CurrentWorkflowLane)
            {
                sysBpmsLane lane = Lanes.FirstOrDefault(c => c.ElementID == item.ID);
                if (lane != null)
                {
                    this.Update(lane);
                    //Element
                    lane.Element.Name = item.Name;
                    new ElementService(this.UnitOfWork).Update(lane.Element);
                }
                else
                {
                    lane = new sysBpmsLane()
                    {
                        ID        = Guid.NewGuid(),
                        ElementID = item.ID,
                        ProcessID = processID,
                        //Element
                        Element = new sysBpmsElement()
                        {
                            ID        = item.ID,
                            Name      = item.Name,
                            ProcessID = processID,
                            TypeLU    = (int)sysBpmsElement.e_TypeLU.Lane,
                        }
                    };
                    this.Add(lane);
                    new ElementService(this.UnitOfWork).Update(lane.Element);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>触发process instance相关的事件</summary>
        /// <param name="e"></param>
        protected void fireProcessInstanceEvent(ProcessInstanceEvent e)
        {
            WorkflowProcess workflowProcess = this.WorkflowProcess;

            if (workflowProcess == null)
            {
                return;
            }

            List <EventListener> listeners = workflowProcess.EventListeners;

            for (int i = 0; i < listeners.Count; i++)
            {
                EventListener listener = (EventListener)listeners[i];
                Object        obj      = this.RuntimeContext.getBeanByName(listener.ClassName);
                if (obj != null)
                {
                    ((IProcessInstanceEventListener)obj).onProcessInstanceEventFired(e);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 将WorkflowProcess对象序列化到一个输出流。
        /// </summary>
        /// <param name="workflowProcess">工作流定义</param>
        /// <param name="swout">输出流</param>
        public override void serialize(WorkflowProcess workflowProcess, Stream swout)
        {
            if (swout == null)
            {
                return;
            }

            XDocument inventoryDoc =
                new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    workflowProcessToDom(workflowProcess)
                    );
            XmlWriter writer = XmlWriter.Create(swout);

            if (writer != null)
            {
                inventoryDoc.Save(writer);
                writer.Close();
            }
            swout.Position = 0;
        }
Ejemplo n.º 16
0
        protected void loadTaskRefs(WorkflowProcess workflowProcess, IWFElement parent, List <TaskRef> taskRefs, XElement xElement)
        {
            if (xElement == null)
            {
                return;
            }
            taskRefs.Clear();

            var partNos = GetXElements(xElement, TASKREF);

            foreach (XElement node in partNos)
            {
                String taskId = GetAttributeValue(node, REFERENCE);
                Task   task   = (Task)workflowProcess.findWFElementById(taskId);
                if (task != null)
                {
                    TaskRef taskRef = new TaskRef(parent, task);
                    taskRef.Sn = Guid.NewGuid().ToString();
                    taskRefs.Add(taskRef);
                }
            }
        }
Ejemplo n.º 17
0
        protected Activity createActivitie(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return(null);
            }

            Activity activity = new Activity(wp, GetAttributeValue(xElement, NAME));

            activity.Sn                 = Guid.NewGuid().ToString();
            activity.DisplayName        = GetAttributeValue(xElement, DISPLAY_NAME);
            activity.CompletionStrategy = (FormTaskEnum)Enum.Parse(typeof(FormTaskEnum), GetAttributeValue(xElement, COMPLETION_STRATEGY), true);


            activity.Description = GetElementValue(xElement, "{" + FPDL_URI + "}" + DESCRIPTION);

            loadEventListeners(activity.EventListeners, xElement.Element("{" + FPDL_URI + "}" + EVENT_LISTENERS));
            loadExtendedAttributes(activity.ExtendedAttributes, xElement.Element("{" + FPDL_URI + "}" + EXTENDED_ATTRIBUTES));
            loadTasks(activity, activity.InlineTasks, xElement.Element("{" + FPDL_URI + "}" + TASKS));
            loadTaskRefs((WorkflowProcess)activity.ParentElement, activity, activity.TaskRefs, xElement.Element("{" + FPDL_URI + "}" + TASKREFS));

            return(activity);
        }
Ejemplo n.º 18
0
        protected Transition createTransition(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return(null);
            }
            String fromNodeId = GetAttributeValue(xElement, FROM);
            String toNodeId   = GetAttributeValue(xElement, TO);
            Node   fromNode   = (Node)wp.findWFElementById(fromNodeId);
            Node   toNode     = (Node)wp.findWFElementById(toNodeId);

            Transition transition = new Transition(wp, GetAttributeValue(xElement, NAME), fromNode, toNode);

            transition.Sn = Guid.NewGuid().ToString();

            transition.DisplayName = GetAttributeValue(xElement, DISPLAY_NAME);

            transition.Description = GetElementValue(xElement, "{" + FPDL_URI + "}" + DESCRIPTION);
            loadExtendedAttributes(transition.ExtendedAttributes, xElement.Element("{" + FPDL_URI + "}" + EXTENDED_ATTRIBUTES));
            transition.Condition = GetElementValue(xElement, "{" + FPDL_URI + "}" + CONDITION);

            return(transition);
        }
Ejemplo n.º 19
0
        public IHttpActionResult CancelWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess process     = instance.GetProcess();
                IUser           currentUser = _utility.GetCurrentUser();

                instance = process.CancelWorkflow(
                    instance,
                    currentUser.Id,
                    model.Comment
                    );

                string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate);

                Log.Info($"{typeDescription} request for {instance.Node.Name} [{instance.NodeId}] was cancelled by {currentUser.Name}");

                _hubContext.Clients.All.TaskCancelled(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance)
                    .LastOrDefault());

                return(Json(new
                {
                    status = 200,
                    message = typeDescription + " workflow cancelled"
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred cancelling the workflow on {instance.Node.Name} [{instance.NodeId}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 保存流程定义,如果同一个ProcessId的流程定义已经存在,则版本号自动加1。
        /// </summary>
        /// <param name="workflowProcessXml">保存的WorkflowProcess XML 文本.</param>
        /// <param name="version">保存的版本,当版本为小于等于0时,添加新流程,如存在相同ProcessId则版本号加1</param>
        /// <param name="isState">是否发布</param>
        public bool SaveOrUpdateWorkflowProcess(string workflowProcessXml, int version, bool isState)
        {
            Dom4JFPDLParser parser          = new Dom4JFPDLParser();
            MemoryStream    msin            = new MemoryStream(Encoding.UTF8.GetBytes(workflowProcessXml));
            WorkflowProcess workflowProcess = parser.parse(msin);

            if (workflowProcess == null)
            {
                return(false);
            }

            WorkflowDefinition wd = RuntimeContextFactory.getRuntimeContext().PersistenceService.FindWorkflowDefinitionByProcessIdAndVersionNumber(workflowProcess.Id, version);

            if (wd == null)
            {
                wd             = new WorkflowDefinition();
                wd.PublishTime = DateTime.Now;
                wd.PublishUser = "******";
            }

            wd.UploadTime = DateTime.Now;
            wd.UploadUser = "******";
            wd.State      = isState;


            wd.Name        = workflowProcess.Name;
            wd.DisplayName = workflowProcess.DisplayName;
            wd.Description = workflowProcess.Description;
            wd.setWorkflowProcess(workflowProcess);

            if (RuntimeContextFactory.getRuntimeContext().PersistenceService.SaveOrUpdateWorkflowDefinition(wd))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 21
0
        public IHttpActionResult ResubmitWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess process     = instance.GetProcess();
                IUser           currentUser = _utility.GetCurrentUser();

                instance = process.ResubmitWorkflow(
                    instance,
                    currentUser.Id,
                    model.Comment
                    );

                string typeDescription     = instance.WorkflowType.Description(instance.ScheduledDate);
                string typeDescriptionPast = instance.WorkflowType.DescriptionPastTense(instance.ScheduledDate);

                Log.Info($"{typeDescription} request for {instance.Node.Name} [{instance.NodeId}] was resubmitted by {currentUser.Name}");

                _hubContext.Clients.All.TaskResubmitted(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance));

                return(Json(new
                {
                    message = $"Changes resubmitted successfully. Page will be {typeDescriptionPast.ToLower()} following workflow completion.",
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred processing the approval on {instance.Node.Name} [{instance.NodeId}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Ejemplo n.º 22
0
        protected void loadTransitions(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return;
            }
            List <Transition> transitions = wp.Transitions;

            transitions.Clear();
            var partNos = GetXElements(xElement, TRANSITION);

            foreach (XElement node in partNos)
            {
                Transition transition = createTransition(wp, node);
                transitions.Add(transition);

                Node fromNode = transition.FromNode;
                Node toNode   = transition.ToNode;
                if (fromNode != null && (fromNode is Activity))
                {
                    ((Activity)fromNode).LeavingTransition = transition;
                }
                else if (fromNode != null && (fromNode is Synchronizer))
                {
                    ((Synchronizer)fromNode).LeavingTransitions.Add(
                        transition);
                }
                if (toNode != null && (toNode is Activity))
                {
                    ((Activity)toNode).EnteringTransition = transition;
                }
                else if (toNode != null && (toNode is Synchronizer))
                {
                    ((Synchronizer)toNode).EnteringTransitions.Add(transition);
                }
            }
        }
Ejemplo n.º 23
0
        protected void loadLoops(WorkflowProcess wp, XElement xElement)
        {
            if (xElement == null)
            {
                return;
            }

            List <Loop> loops = wp.Loops;

            loops.Clear();
            var partNos = GetXElements(xElement, LOOP);

            foreach (XElement node in partNos)
            {
                Loop loop = createLoop(wp, node);
                loops.Add(loop);

                Synchronizer fromNode = (Synchronizer)loop.FromNode;
                Synchronizer toNode   = (Synchronizer)loop.ToNode;

                fromNode.LeavingLoops.Add(loop);
                toNode.EnteringLoops.Add(loop);
            }
        }
Ejemplo n.º 24
0
 public Edge(WorkflowProcess workflowProcess, String name)
     : base(workflowProcess, name)
 {
 }
Ejemplo n.º 25
0
 public EndNode(WorkflowProcess workflowProcess, String name)
     : base(workflowProcess, name)
 {
     // TODO Auto-generated constructor stub
 }
Ejemplo n.º 26
0
        public ResultOperation Update(Guid processID, WorkflowProcess _WorkflowProcess)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                List <Guid>         listDeleted    = new List <Guid>();
                ElementService      elementService = new ElementService(this.UnitOfWork);
                List <sysBpmsEvent> events         = this.GetList(null, processID, string.Empty, null);
                foreach (sysBpmsEvent item in events.Where(c => c.TypeLU == (int)sysBpmsEvent.e_TypeLU.StartEvent && !_WorkflowProcess.StartEvents.Any(d => d.ID == c.ElementID)))
                {
                    resultOperation = this.Delete(item.ID);
                    listDeleted.Add(item.ID);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                }

                foreach (sysBpmsEvent item in events.Where(c => c.TypeLU == (int)sysBpmsEvent.e_TypeLU.EndEvent && !_WorkflowProcess.EndEvents.Any(d => d.ID == c.ElementID)))
                {
                    resultOperation = this.Delete(item.ID);
                    listDeleted.Add(item.ID);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                }

                foreach (sysBpmsEvent item in events.Where(c => c.TypeLU == (int)sysBpmsEvent.e_TypeLU.IntermediateThrow && !_WorkflowProcess.IntermediateThrowEvents.Any(d => d.ID == c.ElementID)))
                {
                    resultOperation = this.Delete(item.ID);
                    listDeleted.Add(item.ID);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                }

                foreach (sysBpmsEvent item in events.Where(c => c.TypeLU == (int)sysBpmsEvent.e_TypeLU.IntermediateCatch && !_WorkflowProcess.IntermediateCatchEvents.Any(d => d.ID == c.ElementID)))
                {
                    resultOperation = this.Delete(item.ID);
                    listDeleted.Add(item.ID);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                }

                foreach (sysBpmsEvent item in events.Where(c => c.TypeLU == (int)sysBpmsEvent.e_TypeLU.boundary && !_WorkflowProcess.BoundaryEvents.Any(d => d.ID == c.ElementID)))
                {
                    resultOperation = this.Delete(item.ID);
                    listDeleted.Add(item.ID);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                }
                events = events.Where(c => !listDeleted.Contains(c.ID)).ToList();
                //StartEvents
                foreach (WorkflowStartEvent item in _WorkflowProcess.StartEvents)
                {
                    sysBpmsEvent _event = events.FirstOrDefault(c => c.ElementID == item.ID);
                    if (_event != null)
                    {
                        //If _event.SubType was changed, It updates _event.
                        if (_event.SubType != (int)item.StartEventType)
                        {
                            _event.SubType  = (int)item.StartEventType;
                            resultOperation = this.Update(_event);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                        //Element
                        _event.Element.Name = item.Name;
                        resultOperation     = elementService.Update(_event.Element);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                    else
                    {
                        _event = new sysBpmsEvent()
                        {
                            TypeLU    = (int)sysBpmsEvent.e_TypeLU.StartEvent,
                            ElementID = item.ID,
                            ID        = Guid.NewGuid(),
                            ProcessID = processID,
                            SubType   = (int)item.StartEventType,
                            //Element
                            Element = new sysBpmsElement()
                            {
                                ID        = item.ID,
                                Name      = item.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Event,
                            }
                        };
                        resultOperation = this.Add(_event);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }

                        resultOperation = elementService.Update(_event.Element);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                }
                //EndEvents
                foreach (WorkflowEndEvent item in _WorkflowProcess.EndEvents)
                {
                    sysBpmsEvent _event = events.FirstOrDefault(c => c.ElementID == item.ID);
                    if (_event != null)
                    {
                        //If _event.SubType was changed, It updates _event.
                        if (_event.SubType != (int)item.EndEventType)
                        {
                            _event.SubType  = (int)item.EndEventType;
                            resultOperation = this.Update(_event);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                        //If _event.Element was changed, It updates Element.
                        if (_event.Element.Name != item.Name)
                        {
                            _event.Element.Name = item.Name;
                            resultOperation     = elementService.Update(_event.Element);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                    }
                    else
                    {
                        _event = new sysBpmsEvent()
                        {
                            TypeLU    = (int)sysBpmsEvent.e_TypeLU.EndEvent,
                            ElementID = item.ID,
                            ID        = Guid.NewGuid(),
                            ProcessID = processID,
                            SubType   = (int)item.EndEventType,
                            //Element
                            Element = new sysBpmsElement()
                            {
                                ID        = item.ID,
                                Name      = item.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Event,
                            }
                        };
                        resultOperation = this.Add(_event);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                }
                //IntermediateThrow
                foreach (WorkflowIntermediateThrowEvent item in _WorkflowProcess.IntermediateThrowEvents)
                {
                    sysBpmsEvent _event = events.FirstOrDefault(c => c.ElementID == item.ID);
                    if (_event != null)
                    {
                        //If _event.SubType was changed, It updates _event.
                        if (_event.SubType != (int)item.IntermediateThrowType)
                        {
                            _event.SubType  = (int)item.IntermediateThrowType;
                            resultOperation = this.Update(_event);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                        //If _event.Element was changed, It updates Element.
                        if (_event.Element.Name != item.Name)
                        {
                            _event.Element.Name = item.Name;
                            resultOperation     = elementService.Update(_event.Element);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                    }
                    else
                    {
                        _event = new sysBpmsEvent()
                        {
                            TypeLU    = (int)sysBpmsEvent.e_TypeLU.IntermediateThrow,
                            ElementID = item.ID,
                            ID        = Guid.NewGuid(),
                            ProcessID = processID,
                            SubType   = (int)item.IntermediateThrowType,
                            //Element
                            Element = new sysBpmsElement()
                            {
                                ID        = item.ID,
                                Name      = item.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Event,
                            }
                        };
                        resultOperation = this.Add(_event);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                }

                //IntermediateCatch
                foreach (WorkflowIntermediateCatchEvent item in _WorkflowProcess.IntermediateCatchEvents)
                {
                    sysBpmsEvent _event = events.FirstOrDefault(c => c.ElementID == item.ID);
                    if (_event != null)
                    {
                        //If _event.SubType was changed, It updates _event.
                        if (_event.SubType != (int)item.IntermediateCatchType)
                        {
                            _event.SubType  = (int)item.IntermediateCatchType;
                            resultOperation = this.Update(_event);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                        //If _event.Element was changed, It updates Element.
                        if (_event.Element.Name != item.Name)
                        {
                            _event.Element.Name = item.Name;
                            resultOperation     = elementService.Update(_event.Element);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                    }
                    else
                    {
                        _event = new sysBpmsEvent()
                        {
                            TypeLU    = (int)sysBpmsEvent.e_TypeLU.IntermediateCatch,
                            ElementID = item.ID,
                            ID        = Guid.NewGuid(),
                            ProcessID = processID,
                            SubType   = (int)item.IntermediateCatchType,
                            //Element
                            Element = new sysBpmsElement()
                            {
                                ID        = item.ID,
                                Name      = item.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Event,
                            }
                        };
                        resultOperation = this.Add(_event);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                }

                //Boundary
                foreach (WorkflowBoundaryEvent item in _WorkflowProcess.BoundaryEvents)
                {
                    sysBpmsEvent _event = events.FirstOrDefault(c => c.ElementID == item.ID);
                    if (_event != null)
                    {
                        //If _event's properties were changed, It updates _event.
                        if (_event.SubType != (int)item.BoundaryType ||
                            _event.RefElementID != item.AttachedToRef ||
                            _event.CancelActivity != item.CancelActivity)
                        {
                            _event.SubType        = (int)item.BoundaryType;
                            _event.RefElementID   = item.AttachedToRef;
                            _event.CancelActivity = item.CancelActivity;
                            resultOperation       = this.Update(_event);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                        //If _event.Element was changed, It updates Element.
                        if (_event.Element.Name != item.Name)
                        {
                            _event.Element.Name = item.Name;
                            resultOperation     = elementService.Update(_event.Element);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                    }
                    else
                    {
                        _event = new sysBpmsEvent()
                        {
                            TypeLU         = (int)sysBpmsEvent.e_TypeLU.boundary,
                            ElementID      = item.ID,
                            ID             = Guid.NewGuid(),
                            ProcessID      = processID,
                            SubType        = (int)item.BoundaryType,
                            RefElementID   = item.AttachedToRef,
                            CancelActivity = item.CancelActivity,
                            //Element
                            Element = new sysBpmsElement()
                            {
                                ID        = item.ID,
                                Name      = item.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Event,
                            }
                        };
                        resultOperation = this.Add(_event);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            if (resultOperation.IsSuccess)
            {
                this.UnitOfWork.Save();
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
Ejemplo n.º 27
0
 public Transition(WorkflowProcess workflowProcess, String name)
     : base(workflowProcess, name)
 {
 }
Ejemplo n.º 28
0
        /// <summary>wangmj  初始化一个工作流网实例,将引擎的扩展属性,注入到对应的工作流元素中</summary>
        /// <param name="process"></param>
        /// <param name="kenelExtensions"></param>
        public NetInstance(WorkflowProcess process, Dictionary <String, List <IKernelExtension> > kenelExtensions)
        {
            this.workflowProcess = process;

            //开始节点
            StartNode startNode = workflowProcess.StartNode;

            StartNodeInstance = new StartNodeInstance(startNode);
            List <IKernelExtension> extensionList = kenelExtensions[StartNodeInstance.ExtensionTargetName];

            for (int i = 0; extensionList != null && i < extensionList.Count; i++)
            {
                IKernelExtension extension = extensionList[i];
                StartNodeInstance.registExtension(extension);
            }
            //this.StartNodeInstance = StartNodeInstance; 自身赋值自身没用。
            wfElementInstanceMap.Add(startNode.Id, StartNodeInstance);

            //活动节点activity
            List <Activity> activities = workflowProcess.Activities;

            for (int i = 0; i < activities.Count; i++)
            {
                Activity         activity         = (Activity)activities[i];
                ActivityInstance activityInstance = new ActivityInstance(activity);
                extensionList = kenelExtensions[activityInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    activityInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(activity.Id, activityInstance);
            }

            //同步器节点
            List <Synchronizer> synchronizers = workflowProcess.Synchronizers;

            for (int i = 0; i < synchronizers.Count; i++)
            {
                Synchronizer         synchronizer         = (Synchronizer)synchronizers[i];
                SynchronizerInstance synchronizerInstance = new SynchronizerInstance(synchronizer);
                extensionList = kenelExtensions[synchronizerInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    synchronizerInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(synchronizer.Id, synchronizerInstance);
            }

            //结束节点
            List <EndNode> endNodes = workflowProcess.EndNodes;

            //        List<EndNodeInstance> endNodeInstances = netInstance.getEndNodeInstances();
            for (int i = 0; i < endNodes.Count; i++)
            {
                EndNode         endNode         = endNodes[i];
                EndNodeInstance endNodeInstance = new EndNodeInstance(endNode);
                //            endNodeInstances.add(endNodeInstance);
                extensionList = kenelExtensions[endNodeInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    endNodeInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(endNode.Id, endNodeInstance);
            }

            //转移线
            List <Transition> transitions = workflowProcess.Transitions;

            for (int i = 0; i < transitions.Count; i++)
            {
                Transition         transition         = (Transition)transitions[i];
                TransitionInstance transitionInstance = new TransitionInstance(transition);

                String fromNodeId = transition.FromNode.Id;
                if (fromNodeId != null)
                {
                    INodeInstance enteringNodeInstance = (INodeInstance)wfElementInstanceMap[fromNodeId];
                    if (enteringNodeInstance != null)
                    {
                        enteringNodeInstance.AddLeavingTransitionInstance(transitionInstance);
                        transitionInstance.EnteringNodeInstance = enteringNodeInstance;
                    }
                }

                String toNodeId = transition.ToNode.Id;
                if (toNodeId != null)
                {
                    INodeInstance leavingNodeInstance = (INodeInstance)wfElementInstanceMap[toNodeId];
                    if (leavingNodeInstance != null)
                    {
                        leavingNodeInstance.AddEnteringTransitionInstance(transitionInstance);
                        transitionInstance.LeavingNodeInstance = leavingNodeInstance;
                    }
                }
                extensionList = kenelExtensions[transitionInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    transitionInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(transitionInstance.Id, transitionInstance);
            }

            //循环线
            List <Loop> loops = workflowProcess.Loops;

            for (int i = 0; i < loops.Count; i++)
            {
                Loop         loop         = (Loop)loops[i];
                LoopInstance loopInstance = new LoopInstance(loop);

                String fromNodeId = loop.FromNode.Id;
                if (fromNodeId != null)
                {
                    INodeInstance enteringNodeInstance = (INodeInstance)wfElementInstanceMap[fromNodeId];
                    if (enteringNodeInstance != null)
                    {
                        enteringNodeInstance.AddLeavingLoopInstance(loopInstance);
                        loopInstance.EnteringNodeInstance = enteringNodeInstance;
                    }
                }

                String toNodeId = loop.ToNode.Id;
                if (toNodeId != null)
                {
                    INodeInstance leavingNodeInstance = (INodeInstance)wfElementInstanceMap[toNodeId];
                    if (leavingNodeInstance != null)
                    {
                        leavingNodeInstance.AddEnteringLoopInstance(loopInstance);
                        loopInstance.LeavingNodeInstance = leavingNodeInstance;
                    }
                }
                extensionList = kenelExtensions[loopInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    loopInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(loopInstance.Id, loopInstance);
            }
        }
Ejemplo n.º 29
0
        void wpw_Closed(object sender, EventArgs e)
        {
            WorkflowProcessWindow wpw = (WorkflowProcessWindow)sender;
            if (wpw.DialogResult==true)
            {
                this.WorkflowProcessCurrent = wpw.WorkflowProcess;
                btnLocalSave.IsEnabled = true;
                btnSave.IsEnabled = true;  //临时屏蔽
                listBox.IsEnabled = true;

                canvas.Width = EventViewer.ActualWidth - 28;
                canvas.Height = EventViewer.ActualHeight - 10;

                canvas.Children.Clear();
                UserControls.Clear();
                selectionControls.Clear();
            }
        }
Ejemplo n.º 30
0
 public Edge(WorkflowProcess workflowProcess, String name)
     : base(workflowProcess, name)
 {
 }
Ejemplo n.º 31
0
 public Loop(WorkflowProcess workflowProcess, String name, Synchronizer fromNode, Synchronizer toNode)
     : base(workflowProcess, name)
 {
     this.FromNode = fromNode;
     this.ToNode = toNode;
 }
Ejemplo n.º 32
0
 public StartNode(WorkflowProcess workflowProcess)
     : base(workflowProcess, name)
 {
     // TODO Auto-generated constructor stub
 }
Ejemplo n.º 33
0
        public IHttpActionResult ApproveWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid);
            WorkflowProcess      process  = instance.GetProcess();

            try
            {
                IUser currentUser = _utility.GetCurrentUser();

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Approve,
                    currentUser.Id,
                    model.Comment
                    );

                string msg    = string.Empty;
                string logMsg = string.Empty;

                string typeDescription     = instance.WorkflowType.Description(instance.ScheduledDate);
                string typeDescriptionPast = instance.WorkflowType.DescriptionPastTense(instance.ScheduledDate);

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg    = $"Approval completed successfully. Page will be {typeDescriptionPast.ToLower()} following workflow completion.";
                    logMsg = $"Workflow {typeDescription} task on {instance.Node.Name} [{instance.NodeId}] approved by {currentUser.Name}";
                    break;

                case WorkflowStatus.Approved:
                    msg    = "Workflow approved successfully.";
                    logMsg = $"Workflow approved by {currentUser.Name} on {instance.Node.Name} [{instance.NodeId}]";

                    if (instance.ScheduledDate.HasValue)
                    {
                        string scheduled = $" Page scheduled for {typeDescription} at {instance.ScheduledDate.Value.ToString("dd MMM yyyy", CultureInfo.CurrentCulture)}";
                        msg    += scheduled;
                        logMsg += scheduled;
                    }
                    else
                    {
                        msg += $" Page has been {typeDescriptionPast.ToLower()}";
                    }
                    break;
                }

                Log.Info(logMsg);

                _hubContext.Clients.All.TaskApproved(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance));

                if (model.Offline)
                {
                    UmbracoContext.Security.ClearCurrentLogin();
                }

                return(Json(new
                {
                    message = msg,
                    status = 200,
                    notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages)
                }, ViewHelpers.CamelCase));
            }
            catch (UmbracoOperationFailedException e)
            {
                string msg = $"A Publishing failure occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]";
                Log.Error(msg, e);

                return(Json(new
                {
                    message = msg,
                    status = 200,
                    isUmbracoOperationError = true,
                    notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages)
                }
                            , ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Ejemplo n.º 34
0
 /// <summary>
 /// 将WorkflowProcess对象序列化到一个输出流。
 /// </summary>
 /// <param name="workflowProcess">工作流定义</param>
 /// <param name="swout">输出流</param>
 public abstract void serialize(WorkflowProcess workflowProcess, Stream swout);
Ejemplo n.º 35
0
        private XElement workflowProcessToDom(WorkflowProcess workflowProcess)
        {
            XNamespace aw = FPDL_URI;
            XElement root = new XElement(
                xN + WORKFLOW_PROCESS,
                new XAttribute(XNamespace.Xmlns + FPDL_NS_PREFIX, FPDL_URI),
                new XAttribute(ID, workflowProcess.Id),
                new XAttribute(NAME, workflowProcess.Name),
                new XAttribute(DISPLAY_NAME, workflowProcess.DisplayName),
                new XAttribute(RESOURCE_FILE, workflowProcess.ResourceFile),
                new XAttribute(RESOURCE_MANAGER, workflowProcess.ResourceManager),
                new XElement(xN + DESCRIPTION, workflowProcess.Description)
                );

            if (!String.IsNullOrEmpty(workflowProcess.TaskInstanceCreator))
            {
                root.Add(new XAttribute(TASK_INSTANCE_CREATOR, workflowProcess.TaskInstanceCreator));
            }
            if (!String.IsNullOrEmpty(workflowProcess.FormTaskInstanceRunner))
            {
                root.Add(new XAttribute(FORM_TASK_INSTANCE_RUNNER, workflowProcess.FormTaskInstanceRunner));
            }
            if (!String.IsNullOrEmpty(workflowProcess.ToolTaskInstanceRunner))
            {
                root.Add(new XAttribute(TOOL_TASK_INSTANCE_RUNNER, workflowProcess.ToolTaskInstanceRunner));
            }
            if (!String.IsNullOrEmpty(workflowProcess.SubflowTaskInstanceRunner))
            {
                root.Add(new XAttribute(SUBFLOW_TASK_INSTANCE_RUNNER, workflowProcess.SubflowTaskInstanceRunner));
            }
            if (!String.IsNullOrEmpty(workflowProcess.FormTaskInstanceCompletionEvaluator))
            {
                root.Add(new XAttribute(FORM_TASK_INSTANCE_COMPLETION_EVALUATOR, workflowProcess.FormTaskInstanceCompletionEvaluator));
            }
            if (!String.IsNullOrEmpty(workflowProcess.ToolTaskInstanceCompletionEvaluator))
            {
                root.Add(new XAttribute(TOOL_TASK_INSTANCE_COMPLETION_EVALUATOR, workflowProcess.ToolTaskInstanceCompletionEvaluator));
            }
            if (!String.IsNullOrEmpty(workflowProcess.SubflowTaskInstanceCompletionEvaluator))
            {
                root.Add(new XAttribute(SUBFLOW_TASK_INSTANCE_COMPLETION_EVALUATOR, workflowProcess.SubflowTaskInstanceCompletionEvaluator));
            }
            root.Add(writeDataFields(workflowProcess.DataFields));
            root.Add(writeStartNode(workflowProcess.StartNode));
            root.Add(writeTasks(workflowProcess.Tasks));
            root.Add(writeActivities(workflowProcess.Activities));
            root.Add(writeSynchronizers(workflowProcess.Synchronizers));
            root.Add(writeEndNodes(workflowProcess.EndNodes));
            root.Add(writeTransitions(workflowProcess.Transitions));
            root.Add(writeLoops(workflowProcess.Loops));
            root.Add(writeEventListeners(workflowProcess.EventListeners));
            root.Add(writeExtendedAttributes(workflowProcess.ExtendedAttributes));

            return root;
        }
Ejemplo n.º 36
0
        /// <summary>
        /// 将WorkflowProcess对象序列化到一个输出流。
        /// </summary>
        /// <param name="workflowProcess">工作流定义</param>
        /// <param name="swout">输出流</param>
        public override void serialize(WorkflowProcess workflowProcess, Stream swout)
        {
            if (swout == null) return;

            XDocument inventoryDoc =
                new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    workflowProcessToDom(workflowProcess)
                    );
            XmlWriter writer = XmlWriter.Create(swout);
            if (writer != null)
            {
                inventoryDoc.Save(writer);
                writer.Close();
            }
            swout.Position = 0;
        }
Ejemplo n.º 37
0
        public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext,
                        IProcessInstance processInstance, ITaskInstance taskInstance)// throws EngineException, KernelException
        {
            if (taskInstance.TaskType != TaskTypeEnum.SUBFLOW)
            {
                throw new EngineException(processInstance, taskInstance.Activity,
                                          "DefaultSubflowTaskInstanceRunner:TaskInstance的任务类型错误,只能为SUBFLOW类型");
            }
            Task task = taskInstance.Task;
            SubWorkflowProcess Subflow = ((SubflowTask)task).SubWorkflowProcess;

            WorkflowDefinition subWorkflowDef = runtimeContext.DefinitionService.GetTheLatestVersionOfWorkflowDefinition(Subflow.WorkflowProcessId);

            if (subWorkflowDef == null)
            {
                WorkflowProcess parentWorkflowProcess = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, parentWorkflowProcess, taskInstance.TaskId,
                                          "系统中没有Id为" + Subflow.WorkflowProcessId + "的流程定义");
            }
            WorkflowProcess subWorkflowProcess = subWorkflowDef.getWorkflowProcess();

            if (subWorkflowProcess == null)
            {
                WorkflowProcess parentWorkflowProcess = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, parentWorkflowProcess, taskInstance.TaskId,
                                          "系统中没有Id为" + Subflow.WorkflowProcessId + "的流程定义");
            }

            IPersistenceService persistenceService = runtimeContext.PersistenceService;

            //更改任务的状态和开始时间
            ((TaskInstance)taskInstance).State       = TaskInstanceStateEnum.RUNNING;
            ((TaskInstance)taskInstance).StartedTime = runtimeContext.CalendarService.getSysDate();
            persistenceService.SaveOrUpdateTaskInstance(taskInstance);

            IProcessInstance subProcessInstance = currentSession.createProcessInstance(subWorkflowProcess.Name, taskInstance);

            //初始化流程变量,从父实例获得初始值
            Dictionary <String, Object> processVars = ((TaskInstance)taskInstance).AliveProcessInstance.ProcessInstanceVariables;
            List <DataField>            datafields  = subWorkflowProcess.DataFields;

            for (int i = 0; datafields != null && i < datafields.Count; i++)
            {
                DataField df = (DataField)datafields[i];
                if (df.DataType == DataTypeEnum.STRING)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is String))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, df.InitialValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, "");
                    }
                }
                else if (df.DataType == DataTypeEnum.INTEGER)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is Int32))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        try
                        {
                            Int32 intValue = Int32.Parse(df.InitialValue);
                            subProcessInstance.setProcessInstanceVariable(df.Name, intValue);
                        }
                        catch { }
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, (Int32)0);
                    }
                }
                else if (df.DataType == DataTypeEnum.FLOAT)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is float))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        float floatValue = float.Parse(df.InitialValue);
                        subProcessInstance.setProcessInstanceVariable(df.Name, floatValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, (float)0);
                    }
                }
                else if (df.DataType == DataTypeEnum.BOOLEAN)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is Boolean))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        Boolean booleanValue = Boolean.Parse(df.InitialValue);
                        subProcessInstance.setProcessInstanceVariable(df.Name, booleanValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, false);
                    }
                }
                else if (df.DataType == DataTypeEnum.DATETIME)
                {
                    //TODO 需要完善一下 ( 父子流程数据传递——时间类型的数据还未做传递-不知道为什么?)
                    //wmj2003 20090925 补充上了
                    if (processVars[df.Name] != null && (processVars[df.Name] is DateTime))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        try
                        {
                            DateTime dateTmp = DateTime.Parse(df.InitialValue);
                            subProcessInstance.setProcessInstanceVariable(df.Name, dateTmp);
                        }
                        catch
                        {
                            subProcessInstance.setProcessInstanceVariable(df.Name, null);
                        }
                    }
                }
                //TODO 应将下面这句删除!这里还需要吗?应该直接subProcessInstance.run()就可以了。
                runtimeContext.PersistenceService.SaveOrUpdateProcessInstance(subProcessInstance);
                subProcessInstance.run();
            }
        }
Ejemplo n.º 38
0
        public IHttpActionResult InitiateWorkflow(InitiateWorkflowModel model)
        {
            WorkflowProcess process = null;

            try
            {
                if (model.Publish)
                {
                    process = new DocumentPublishProcess();
                }
                else
                {
                    process = new DocumentUnpublishProcess();
                }

                IUser currentUser             = _utility.GetCurrentUser();
                WorkflowInstancePoco instance = process.InitiateWorkflow(int.Parse(model.NodeId), currentUser.Id, model.Comment);

                string msg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg = $"Page submitted for {(model.Publish ? "publish" : "unpublish")} approval.";
                    break;

                case WorkflowStatus.Approved:
                    msg = (model.Publish ? "Publish" : "Unpublish") + " workflow complete.";

                    if (instance.ScheduledDate.HasValue)
                    {
                        msg += $" Page scheduled for publishing at {instance.ScheduledDate.Value.ToString("dd MMM yyyy", CultureInfo.CurrentCulture)}";
                    }

                    break;
                }

                Log.Info(msg);

                // broadcast the new task back to the client to update dashboards etc
                // needs to be converted from a poco to remove unused properties and force camelCase
                _hubContext.Clients.All.WorkflowStarted(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance)
                    .FirstOrDefault());

                return(Json(new
                {
                    message = msg,
                    status = 200,
                    notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages)
                }, ViewHelpers.CamelCase));
            }
            catch (UmbracoOperationFailedException e)
            {
                const string msg = "A Publishing failure occurred initiating the workflow";
                Log.Error(msg, e);

                return(Json(new {
                    message = msg,
                    status = 200,
                    isUmbracoOperationError = true,
                    notifications = NotificationHelpers.MapEventMessagesToNotifications(process?.EventMessages)
                }
                            , ViewHelpers.CamelCase));
            }
            catch (Exception e)
            {
                const string msg = "An error occurred initiating the workflow";
                Log.Error(msg, e);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(e, msg)));
            }
        }
Ejemplo n.º 39
0
        public bool HasUserApproved(WorkflowActor actor, WorkflowProcess process, 
            int workflowId = -1, string workflowName = "", int workflowLevelId = -1)
        {
            //_actors.Table.FirstOrDefault(x => x.ActorRefId == userRefId.ToString());
            //var process = _processes.Table.FirstOrDefault(x => x.ProcessRefId == processRefId.ToString());
            if (actor == null || process == null) return false;
            var userRefId = actor.ActorRefId;
            var processRefId = process.ProcessRefId;
            if (workflowLevelId > 0)
            {
                var hst = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved && x.LevelId == workflowLevelId);
                return hst.Any();
            }
            if (workflowId > 0)
            {
                var hst = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved && x.WorkflowLevel.WorkflowId == workflowId);

                return hst.Any();
            }
            if (!string.IsNullOrEmpty(workflowName))
            {
                var hst = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved && x.WorkflowLevel.Workflow.Name.ToLower() == workflowName.ToLower());

                return hst.Any();
            }
            var hstory = GetAllUserApprovals(userRefId, processRefId).Where(x => x.Approved);

            return hstory.Any();
        }
Ejemplo n.º 40
0
 public EndNode(WorkflowProcess workflowProcess, String name)
     : base(workflowProcess, name)
 {
     // TODO Auto-generated constructor stub
 }
Ejemplo n.º 41
0
 private void btnNew_Checked(object sender, RoutedEventArgs e)
 {
     //新建
     SelectWorkflowDefinition = null;
     WorkflowProcess wp= new WorkflowProcess("NewWorkflowProcess");
     WorkflowProcessWindow wpw = new WorkflowProcessWindow(wp);
     wpw.Closed += new EventHandler(wpw_Closed);
     wpw.Show();
 }
Ejemplo n.º 42
0
        void dsc_GetWorkflowProcessXmlProcessIdOrVersionCompleted(object sender, GetWorkflowProcessXmlProcessIdOrVersionCompletedEventArgs e)
        {
            if (String.IsNullOrEmpty(e.Result)) return;
            //流程图初始化
            MemoryStream msin = new MemoryStream(Encoding.UTF8.GetBytes(e.Result));
            Dom4JFPDLParser djp = new Dom4JFPDLParser();
            this.WorkflowProcessCurrent = djp.parse(msin);
            loadWorkflow.LoadWorkflowProcessToFrom(this.WorkflowProcessCurrent);

            //流程跟踪
            if (queryString.ContainsKey("ProcessInstanceId"))
            {
                GetProcessInstanceTraceXml(queryString["ProcessInstanceId"]);
            }
        }
Ejemplo n.º 43
0
 /// <summary>
 /// 将WorkflowProcess对象序列化到一个输出流。
 /// </summary>
 /// <param name="workflowProcess">工作流定义</param>
 /// <param name="swout">输出流</param>
 public abstract void serialize(WorkflowProcess workflowProcess, Stream swout);
Ejemplo n.º 44
0
        public IHttpActionResult ApproveWorkflowTask(TaskData model)
        {
            WorkflowInstancePoco instance = GetInstance(model.InstanceGuid);

            try
            {
                WorkflowProcess process     = GetProcess(instance.Type);
                IUser           currentUser = _utility.GetCurrentUser();

                instance = process.ActionWorkflow(
                    instance,
                    WorkflowAction.Approve,
                    currentUser.Id,
                    model.Comment
                    );

                string msg    = string.Empty;
                string logMsg = string.Empty;

                switch (instance.WorkflowStatus)
                {
                case WorkflowStatus.PendingApproval:
                    msg    = $"Approval completed successfully. Page will be {instance.TypeDescriptionPastTense.ToLower()} following workflow completion.";
                    logMsg = $"Workflow {instance.TypeDescription} task on {instance.Node.Name} [{instance.NodeId}] approved by {currentUser.Name}";
                    break;

                case WorkflowStatus.Approved:
                    msg    = "Workflow approved successfully.";
                    logMsg = $"Workflow approved by {currentUser.Name} on {instance.Node.Name} [{instance.NodeId}]";

                    if (instance.ScheduledDate.HasValue)
                    {
                        string scheduled = $" Page scheduled for {instance.TypeDescription} at {instance.ScheduledDate.Value.ToString("dd MMM YYYY", CultureInfo.CurrentCulture)}";
                        msg    += scheduled;
                        logMsg += scheduled;
                    }
                    else
                    {
                        msg += $" Page has been {instance.TypeDescriptionPastTense.ToLower()}";
                    }
                    break;
                }

                Log.Info(logMsg);

                _hubContext.Clients.All.TaskApproved(
                    _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance));

                return(Json(new
                {
                    message = msg,
                    status = 200
                }, ViewHelpers.CamelCase));
            }
            catch (Exception ex)
            {
                string msg = $"An error occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]";
                Log.Error(msg, ex);

                return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg)));
            }
        }
Ejemplo n.º 45
0
        private void btnLocalOpen_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog myOpenDialog = new OpenFileDialog();
                myOpenDialog.Filter = "流程文件*.xml | *.xml";
                //myOpenDialog.DefaultExt = "xml";

                bool? ret = myOpenDialog.ShowDialog();
                if (ret == true)
                {
                    using (StreamReader fs = (StreamReader)myOpenDialog.File.OpenText())
                    {
                        string xmlWorkflow = fs.ReadToEnd();
                        fs.Close();

                        MemoryStream msin = new MemoryStream(Encoding.UTF8.GetBytes(xmlWorkflow));
                        Dom4JFPDLParser djp = new Dom4JFPDLParser();

                        SelectWorkflowDefinition = null;
                        this.WorkflowProcessCurrent = djp.parse(msin);

                        btnLocalSave.IsEnabled = true;
                        btnSave.IsEnabled = true; //临时屏蔽
                        listBox.IsEnabled = true;

                        canvas.Width = EventViewer.ActualWidth - 28;
                        canvas.Height = EventViewer.ActualHeight - 10;

                        canvas.Children.Clear();
                        UserControls.Clear();
                        selectionControls.Clear();

                        loadWorkflow.LoadWorkflowProcessToFrom(this.WorkflowProcessCurrent);
                    }
                }

            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 46
0
 public Transition(WorkflowProcess workflowProcess, String name, Node fromNode, Node toNode)
     : base(workflowProcess, name)
 {
     this.FromNode = fromNode;
     this.ToNode = toNode;
 }