Пример #1
0
        public ResultOperation Delete(Guid GatewayId)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                if (resultOperation.IsSuccess)
                {
                    sysBpmsGateway sysBpmsGateway = this.GetInfo(GatewayId);
                    this.BeginTransaction();
                    foreach (sysBpmsCondition Condition in new ConditionService(this.UnitOfWork).GetList(GatewayId, null, null))
                    {
                        resultOperation = new ConditionService(this.UnitOfWork).Delete(Condition.ID);
                        if (!resultOperation.IsSuccess)
                        {
                            break;
                        }
                    }
                    if (resultOperation.IsSuccess)
                    {
                        this.UnitOfWork.Repository <IGatewayRepository>().Delete(GatewayId);
                        resultOperation = new ElementService(this.UnitOfWork).Delete(sysBpmsGateway.ElementID, sysBpmsGateway.ProcessID);
                        this.UnitOfWork.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
 public GatewayDTO(sysBpmsGateway gateway)
 {
     this.ID                    = gateway.ID;
     this.ElementID             = gateway.ElementID;
     this.ProcessID             = gateway.ProcessID;
     this.DefaultSequenceFlowID = gateway.DefaultSequenceFlowID;
 }
        public object GetConditions(string ElementId, Guid ProcessId)
        {
            using (GatewayService gatewayService = new GatewayService())
            {
                sysBpmsGateway sysBpmsGateway = gatewayService.GetInfo(ElementId, ProcessId);

                using (SequenceFlowService sequenceFlowService = new SequenceFlowService())
                {
                    using (ElementService elementService = new ElementService())
                    {
                        using (ConditionService conditionService = new ConditionService())
                        {
                            List <sysBpmsSequenceFlow> SequenceFlows = sequenceFlowService.GetList(ProcessId, "", ElementId, "");
                            List <sysBpmsElement>      Elements      = elementService.GetList(SequenceFlows.Select(c => c.TargetElementID).ToArray(), ProcessId);

                            using (ProcessService processService = new ProcessService())
                                return new
                                       {
                                           SequenceFlows = SequenceFlows.Select(c => new
                                    {
                                        c.ID,
                                        Elements.FirstOrDefault(d => d.ID == c.TargetElementID).Name,
                                    }).ToList(),
                                           AllowEdit = processService.GetInfo(ProcessId).AllowEdit(),
                                           GatewayID = sysBpmsGateway.ID,
                                           GetList   = conditionService.GetList(sysBpmsGateway.ID, null, null).Select(c => new ConditionDTO(c)).ToList(),
                                       };
                        }
                    }
                }
            }
        }
Пример #4
0
        public void Delete(Guid id)
        {
            sysBpmsGateway Gateway = this.Context.sysBpmsGateways.FirstOrDefault(d => d.ID == id);

            if (Gateway != null)
            {
                this.Context.sysBpmsGateways.Remove(Gateway);
            }
        }
Пример #5
0
        public ResultOperation Update(sysBpmsGateway Gateway)
        {
            ResultOperation resultOperation = new ResultOperation();

            if (resultOperation.IsSuccess)
            {
                this.UnitOfWork.Repository <IGatewayRepository>().Update(Gateway);
                this.UnitOfWork.Save();
            }
            return(resultOperation);
        }
Пример #6
0
 public void Update(sysBpmsGateway gateway)
 {
     //SequenceFlow is new and must be added alongside Gateway update.
     //mostly in this situation gateway.DefaultSequenceFlowID is null.
     if (gateway.SequenceFlow != null && gateway.SequenceFlow.ID != gateway.DefaultSequenceFlowID)
     {
         gateway.DefaultSequenceFlowID     = gateway.SequenceFlow.ID;
         this.Context.Entry(gateway).State = EntityState.Modified;
         this.Context.Entry(gateway.SequenceFlow).State         = EntityState.Added;
         this.Context.Entry(gateway.SequenceFlow.Element).State = EntityState.Added;
     }
     else
     {
         this.Context.Entry(gateway).State = EntityState.Modified;
         if (gateway.SequenceFlow != null)
         {
             this.Context.Entry(gateway.SequenceFlow).State = EntityState.Detached;
         }
     }
 }
Пример #7
0
        public (List <sysBpmsSequenceFlow> flowsList, bool result) CheckGateway(sysBpmsGateway gateway, sysBpmsSequenceFlow joinFromSequenceFlow, Guid?threadTaskID)
        {
            SequenceFlowService        sequenceFlowService       = new SequenceFlowService(this.UnitOfWork);
            List <sysBpmsSequenceFlow> acceptedForkSequenceFlows = new List <sysBpmsSequenceFlow>();

            ConditionService conditionService = new ConditionService(this.UnitOfWork);

            switch ((sysBpmsGateway.e_TypeLU)gateway.TypeLU)
            {
            case sysBpmsGateway.e_TypeLU.ExclusiveGateWay:
            {
                List <sysBpmsCondition> listCondition = conditionService.GetList(gateway.ID, null, null);
                foreach (sysBpmsCondition condition in listCondition)
                {
                    if (new DynamicCodeEngine(base.EngineSharedModel, this.UnitOfWork).ExecuteBooleanCode(DesignCodeUtility.GetDesignCodeFromXml(condition.Code)))
                    {
                        acceptedForkSequenceFlows.Add(sequenceFlowService.GetInfo(condition.SequenceFlowID.Value));
                        break;
                    }
                }
            }
            break;

            case sysBpmsGateway.e_TypeLU.InclusiveGateWay:
            {
                List <sysBpmsThreadTask> listRunningThreadTask = new ThreadTaskService(base.UnitOfWork).GetListRunning(base.EngineSharedModel.CurrentThreadID.ToGuidObj());
                if (!listRunningThreadTask.Any(c => c.ID != threadTaskID && gateway.TraceToStart.ToStringObj().Split(',').Contains(c.Task.ElementID)))
                {
                    List <sysBpmsCondition> listCondition = conditionService.GetList(gateway.ID, null, null);
                    foreach (sysBpmsCondition condition in listCondition)
                    {
                        if (new DynamicCodeEngine(base.EngineSharedModel, this.UnitOfWork).ExecuteBooleanCode(DesignCodeUtility.GetDesignCodeFromXml(condition.Code)))
                        {
                            acceptedForkSequenceFlows.Add(sequenceFlowService.GetInfo(condition.SequenceFlowID.Value));
                        }
                    }
                }
                else
                {
                    return(new List <sysBpmsSequenceFlow>(), true);
                }
            }
            break;

            case sysBpmsGateway.e_TypeLU.ParallelGateWay:
            {
                List <sysBpmsSequenceFlow> listJoinSequenceFlow = sequenceFlowService.GetList(base.EngineSharedModel.CurrentProcessID.Value, gateway.ElementID, "", "");
                //if all sequence flow were executed, run condition code and clear gateway Status Xml List
                if (listJoinSequenceFlow.Where(c => c.ID != joinFromSequenceFlow.ID).All(c => base.EngineSharedModel.CurrentThread.GatewayStatus.Any(d => d.GatewayID == gateway.ID && d.List.Any(f => f.SequenceFlowID == c.ID && f.Done))) || base.EngineSharedModel.CurrentThread == null)
                {
                    acceptedForkSequenceFlows = sequenceFlowService.GetList(base.EngineSharedModel.CurrentProcessID.Value, "", gateway.ElementID, "");
                    new ThreadService(base.UnitOfWork).ClearGatewayStatusXml(base.EngineSharedModel.CurrentThread, gateway.ID);
                }
                else
                {
                    //add this sequence flow path to executed path in Thread.GatewayStatusXml
                    new ThreadService(base.UnitOfWork).AddGatewayStatusXml(base.EngineSharedModel.CurrentThread, gateway.ID, joinFromSequenceFlow.ID);
                    return(new List <sysBpmsSequenceFlow>(), true);
                }
            }
            break;
            }

            if (!acceptedForkSequenceFlows.Any() && gateway.DefaultSequenceFlowID.HasValue)
            {
                acceptedForkSequenceFlows.Add(sequenceFlowService.GetInfo(gateway.DefaultSequenceFlowID.Value));
            }

            return(acceptedForkSequenceFlows, acceptedForkSequenceFlows.Any());
        }
Пример #8
0
 public void Add(sysBpmsGateway gateway)
 {
     this.Context.sysBpmsGateways.Add(gateway);
 }
Пример #9
0
        public ResultOperation Update(Guid processID, WorkflowProcess _WorkflowProcess)
        {
            ResultOperation       resultOperation = new ResultOperation();
            List <sysBpmsGateway> listGateway     = this.GetList(processID);
            ElementService        elementService  = new ElementService(this.UnitOfWork);
            List <Guid>           listDeleted     = new List <Guid>();

            //Delete gateways that are not in diagram xml element.
            foreach (sysBpmsGateway item in listGateway.Where(c =>
                                                              !_WorkflowProcess.ExclusiveGateways.Any(d => d.ID == c.ElementID) &&
                                                              !_WorkflowProcess.InclusiveGateways.Any(d => d.ID == c.ElementID) &&
                                                              !_WorkflowProcess.ParallelGateways.Any(d => d.ID == c.ElementID)))
            {
                resultOperation = this.Delete(item.ID);
                listDeleted.Add(item.ID);
                if (!resultOperation.IsSuccess)
                {
                    return(resultOperation);
                }
            }
            listGateway = listGateway.Where(c => !listDeleted.Contains(c.ID)).ToList();
            //ExclusiveGateway
            foreach (WorkflowExclusiveGateway item in _WorkflowProcess.ExclusiveGateways)
            {
                sysBpmsGateway      gateway         = listGateway.FirstOrDefault(c => c.ElementID == item.ID);
                sysBpmsSequenceFlow newSequenceFlow = null;
                //if SequenceFlow did not add before and item.Default is not empty add it
                if (!string.IsNullOrWhiteSpace(item.Default))
                {
                    sysBpmsSequenceFlow currentDefualt = new SequenceFlowService(this.UnitOfWork).GetInfo(item.Default, processID);
                    if (currentDefualt == null)
                    {
                        WorkflowSequenceFlow _WorkflowSequenceFlow = _WorkflowProcess.SequenceFlows.FirstOrDefault(c => c.ID == item.Default);
                        newSequenceFlow = new sysBpmsSequenceFlow()
                        {
                            TargetElementID = _WorkflowSequenceFlow.TargetRef,
                            SourceElementID = _WorkflowSequenceFlow.SourceRef,
                            Name            = _WorkflowSequenceFlow.Name,
                            ElementID       = _WorkflowSequenceFlow.ID,
                            Element         = new sysBpmsElement()
                            {
                                ID        = _WorkflowSequenceFlow.ID,
                                Name      = _WorkflowSequenceFlow.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Sequence,
                            },
                            ID        = Guid.NewGuid(),
                            ProcessID = processID,
                        };
                    }
                    else if (gateway != null)
                    {
                        gateway.DefaultSequenceFlowID = currentDefualt.ID;
                    }
                }
                if (gateway != null)
                {
                    if (newSequenceFlow != null)
                    {
                        gateway.SequenceFlow = newSequenceFlow;
                    }
                    gateway.TypeLU  = (int)sysBpmsGateway.e_TypeLU.ExclusiveGateWay;
                    resultOperation = this.Update(gateway);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                    gateway.Element.Name = item.Name;
                    elementService.Update(gateway.Element);
                }
                else
                {
                    gateway = new sysBpmsGateway()
                    {
                        ID           = Guid.NewGuid(),
                        ElementID    = item.ID,
                        ProcessID    = processID,
                        SequenceFlow = newSequenceFlow,
                        TypeLU       = (int)sysBpmsGateway.e_TypeLU.ExclusiveGateWay,
                        Element      = new sysBpmsElement()
                        {
                            ID        = item.ID,
                            Name      = item.Name,
                            ProcessID = processID,
                            TypeLU    = (int)sysBpmsElement.e_TypeLU.Gateway,
                        }
                    };
                    resultOperation = this.Add(gateway);
                }
                if (!resultOperation.IsSuccess)
                {
                    return(resultOperation);
                }
            }

            //InclusiveGateway
            foreach (WorkflowInclusiveGateway item in _WorkflowProcess.InclusiveGateways)
            {
                sysBpmsGateway gateway = listGateway.FirstOrDefault(c => c.ElementID == item.ID);

                sysBpmsSequenceFlow newSequenceFlow = null;
                //if SequenceFlow did not add before and item.Default is not empty add it
                if (!string.IsNullOrWhiteSpace(item.Default))
                {
                    sysBpmsSequenceFlow currentDefualt = new SequenceFlowService(this.UnitOfWork).GetInfo(item.Default, processID);
                    if (currentDefualt == null)
                    {
                        WorkflowSequenceFlow _WorkflowSequenceFlow = _WorkflowProcess.SequenceFlows.FirstOrDefault(c => c.ID == item.Default);
                        newSequenceFlow = new sysBpmsSequenceFlow()
                        {
                            TargetElementID = _WorkflowSequenceFlow.TargetRef,
                            SourceElementID = _WorkflowSequenceFlow.SourceRef,
                            Name            = _WorkflowSequenceFlow.Name,
                            ElementID       = _WorkflowSequenceFlow.ID,
                            Element         = new sysBpmsElement()
                            {
                                ID        = _WorkflowSequenceFlow.ID,
                                Name      = _WorkflowSequenceFlow.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Sequence,
                            },
                            ID        = Guid.NewGuid(),
                            ProcessID = processID,
                        };
                    }
                    else if (gateway != null)
                    {
                        gateway.DefaultSequenceFlowID = currentDefualt.ID;
                    }
                }

                if (gateway != null)
                {
                    if (newSequenceFlow != null)
                    {
                        gateway.SequenceFlow = newSequenceFlow;
                    }
                    gateway.TypeLU  = (int)sysBpmsGateway.e_TypeLU.InclusiveGateWay;
                    resultOperation = this.Update(gateway);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                    gateway.Element.Name = item.Name;
                    elementService.Update(gateway.Element);
                }
                else
                {
                    gateway = new sysBpmsGateway()
                    {
                        ID           = Guid.NewGuid(),
                        ElementID    = item.ID,
                        ProcessID    = processID,
                        SequenceFlow = newSequenceFlow,
                        TypeLU       = (int)sysBpmsGateway.e_TypeLU.InclusiveGateWay,
                        Element      = new sysBpmsElement()
                        {
                            ID        = item.ID,
                            Name      = item.Name,
                            ProcessID = processID,
                            TypeLU    = (int)sysBpmsElement.e_TypeLU.Gateway,
                        }
                    };
                    resultOperation = this.Add(gateway);
                }
                if (!resultOperation.IsSuccess)
                {
                    return(resultOperation);
                }
            }

            //ParallelGateway
            foreach (WorkflowParallelGateway item in _WorkflowProcess.ParallelGateways)
            {
                sysBpmsGateway gateway = listGateway.FirstOrDefault(c => c.ElementID == item.ID);
                if (gateway != null)
                {
                    gateway.TypeLU  = (int)sysBpmsGateway.e_TypeLU.ParallelGateWay;
                    resultOperation = this.Update(gateway);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                    gateway.Element.Name = item.Name;
                    elementService.Update(gateway.Element);
                }
                else
                {
                    gateway = new sysBpmsGateway()
                    {
                        ID        = Guid.NewGuid(),
                        ElementID = item.ID,
                        ProcessID = processID,
                        TypeLU    = (int)sysBpmsGateway.e_TypeLU.ParallelGateWay,
                        Element   = new sysBpmsElement()
                        {
                            ID        = item.ID,
                            Name      = item.Name,
                            ProcessID = processID,
                            TypeLU    = (int)sysBpmsElement.e_TypeLU.Gateway,
                        }
                    };
                    resultOperation = this.Add(gateway);
                }
                if (!resultOperation.IsSuccess)
                {
                    return(resultOperation);
                }
            }

            return(resultOperation);
        }