Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public ResultOperation UpdateTraceToStart(sysBpmsProcess process)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                List <sysBpmsGateway> listGateways = new GatewayService(base.UnitOfWork).GetList(process.ID).ToList();
                if (listGateways.Any())
                {
                    List <sysBpmsElement>      listElements     = new ElementService(base.UnitOfWork).GetList(process.ID, null, "");
                    List <sysBpmsSequenceFlow> listSequenceFlow = new SequenceFlowService(base.UnitOfWork).GetList(process.ID, "", "", "");
                    this.BeginTransaction();
                    foreach (sysBpmsGateway item in listGateways)
                    {
                        if (resultOperation.IsSuccess)
                        {
                            List <string> listEvaluatedID = new List <string>();
                            List <string> listTaskID      = new List <string>();
                            List <string> listTracedItems = new List <string>();
                            this.GetRecursiveTraceToStart(listElements.FirstOrDefault(c => c.ID == item.ElementID), listTaskID, listEvaluatedID, listElements, listSequenceFlow, listTracedItems);

                            item.TraceToStart = string.Join(",", listTaskID);
                            resultOperation   = new GatewayService(base.UnitOfWork).Update(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }
        public ResultOperation Delete(Guid taskId)
        {
            ResultOperation resultOperation = null;

            try
            {
                resultOperation = new ResultOperation();
                if (resultOperation.IsSuccess)
                {
                    sysBpmsTask sysBpmsTask = this.GetInfo(taskId);
                    this.BeginTransaction();

                    if (new ThreadTaskService(base.UnitOfWork).HasAny(sysBpmsTask.ProcessID, sysBpmsTask.ID))
                    {
                        resultOperation.AddError(LangUtility.Get("CannotDelete.Text", nameof(sysBpmsTask)));
                        return(resultOperation);
                    }

                    foreach (sysBpmsStep item in new StepService(base.UnitOfWork).GetList(taskId, null))
                    {
                        resultOperation = new StepService(base.UnitOfWork).Delete(item.ID);
                        if (!resultOperation.IsSuccess)
                        {
                            break;
                        }
                    }
                    if (resultOperation.IsSuccess)
                    {
                        this.UnitOfWork.Repository <ITaskRepository>().Delete(taskId);
                        this.UnitOfWork.Save();
                        resultOperation = new ElementService(base.UnitOfWork).Delete(sysBpmsTask.ElementID, sysBpmsTask.ProcessID);
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
        public ResultOperation Delete(Guid ID)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                sysBpmsLane lane = this.GetInfo(ID);
                this.BeginTransaction();
                this.UnitOfWork.Repository <ILaneRepository>().Delete(ID);
                this.UnitOfWork.Save();
                resultOperation = new ElementService(this.UnitOfWork).Delete(lane.ElementID, lane.ProcessID);
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
        private ResultOperation UpdateTask(Domain.sysBpmsTask task, string name, Domain.sysBpmsTask.e_MarkerTypeLU?markerTypeLU)
        {
            ResultOperation resultOperation = new ResultOperation();

            //if task.MarkerTypeLU was changed, it updates task.
            if (task.MarkerTypeLU != (markerTypeLU.HasValue ? (int)markerTypeLU : (int?)null))
            {
                task.MarkerTypeLU = markerTypeLU.HasValue ? (int)markerTypeLU : (int?)null;
                resultOperation   = this.Update(task);
                if (!resultOperation.IsSuccess)
                {
                    return(resultOperation);
                }
            }
            //if Element.Name was changed, it updates Element.
            if (task.Element.Name != name)
            {
                task.Element.Name = name;
                resultOperation   = new ElementService(this.UnitOfWork).Update(task.Element);
            }
            return(resultOperation);
        }
Exemplo n.º 6
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);
        }
        public ResultOperation NewVersion(sysBpmsProcess current, string userName)
        {
            ResultOperation resultOperation;

            try
            {
                resultOperation = new ResultOperation();
                if (resultOperation.IsSuccess)
                {
                    if (this.GetList((int)sysBpmsProcess.Enum_StatusLU.Draft, current.ParentProcessID ?? current.ID).Any())
                    {
                        resultOperation.AddError(LangUtility.Get("NewVersionError.Text", nameof(sysBpmsProcess)));
                        return(resultOperation);
                    }
                    this.BeginTransaction();

                    //Create new process
                    sysBpmsProcess newProcess = this.GetInfo(current.ID);
                    newProcess.CreateDate      = DateTime.Now;
                    newProcess.UpdateDate      = DateTime.Now;
                    newProcess.StatusLU        = (int)sysBpmsProcess.Enum_StatusLU.Draft;
                    newProcess.ProcessVersion  = newProcess.ProcessVersion + 1;
                    newProcess.ParentProcessID = current.ParentProcessID.HasValue ? current.ParentProcessID.Value : current.ID;
                    newProcess.Number          = this.CalculateSerlialNumber(this.UnitOfWork.Repository <IProcessRepository>().MaxNumber() + 1);
                    newProcess.FormattedNumber = this.CalculateFormatNumber(newProcess.Number.Value, DateTime.Now.Date);

                    this.UnitOfWork.Repository <IProcessRepository>().Add(newProcess);
                    this.UnitOfWork.Save();
                    //Copy Variable
                    Dictionary <Guid, Guid> variableConvertID   = new Dictionary <Guid, Guid>();
                    VariableService         variableService     = new VariableService(base.UnitOfWork);
                    List <sysBpmsVariable>  sysBpmsVariableList = variableService.GetList(current.ID, null, null, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsVariable item in sysBpmsVariableList)
                        {
                            Guid oldGuidID = item.ID;
                            item.ProcessID  = newProcess.ID;
                            resultOperation = variableService.Add(item, null);
                            variableConvertID.Add(oldGuidID, item.ID);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy VariableDependency
                    VariableDependencyService        variableDependencyService     = new VariableDependencyService(base.UnitOfWork);
                    List <sysBpmsVariableDependency> sysBpmsVariableDependencyList = variableDependencyService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsVariableDependency item in sysBpmsVariableDependencyList)
                        {
                            if (item.ToVariableID.HasValue)
                            {
                                item.ToVariableID = variableConvertID[item.ToVariableID.Value];
                            }
                            item.DependentVariableID = variableConvertID[item.DependentVariableID];
                            resultOperation          = variableDependencyService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy Element
                    ElementService        elementService     = new ElementService(base.UnitOfWork);
                    List <sysBpmsElement> sysBpmsElementList = elementService.GetList(current.ID, null, "");
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsElement item in sysBpmsElementList)
                        {
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            resultOperation = elementService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy Lane
                    LaneService        laneService     = new LaneService(base.UnitOfWork);
                    List <sysBpmsLane> sysBpmsLaneList = laneService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsLane item in sysBpmsLaneList)
                        {
                            item.ID        = Guid.NewGuid();
                            item.ProcessID = newProcess.ID;
                            item.Element   = null;
                            laneService.Add(item);
                        }
                    }
                    //Copy event
                    EventService        eventService     = new EventService(base.UnitOfWork);
                    List <sysBpmsEvent> sysBpmsEventList = eventService.GetList(null, current.ID, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsEvent item in sysBpmsEventList)
                        {
                            item.ID         = Guid.NewGuid();
                            item.ProcessID  = newProcess.ID;
                            item.Element    = null;
                            resultOperation = eventService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy SequenceFlow
                    Dictionary <Guid, Guid>    flowConvertID           = new Dictionary <Guid, Guid>();
                    SequenceFlowService        sequenceFlowService     = new SequenceFlowService(base.UnitOfWork);
                    List <sysBpmsSequenceFlow> sysBpmsSequenceFlowList = sequenceFlowService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsSequenceFlow item in sysBpmsSequenceFlowList)
                        {
                            Guid flowNewId = Guid.NewGuid();
                            flowConvertID.Add(item.ID, flowNewId);
                            item.ID         = flowNewId;
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            item.Element    = null;
                            resultOperation = sequenceFlowService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Copy gateway
                    GatewayService        gatewayService     = new GatewayService(base.UnitOfWork);
                    ConditionService      conditionService   = new ConditionService(base.UnitOfWork);
                    List <sysBpmsGateway> sysBpmsGatewayList = gatewayService.GetList(current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsGateway item in sysBpmsGatewayList)
                        {
                            List <sysBpmsCondition> sysBpmsConditionList = conditionService.GetList(item.ID, null, null);
                            item.ID        = Guid.NewGuid();
                            item.ProcessID = newProcess.ID;
                            item.Element   = null;
                            if (item.DefaultSequenceFlowID.HasValue)
                            {
                                item.DefaultSequenceFlowID = flowConvertID[item.DefaultSequenceFlowID.Value];
                            }
                            resultOperation = gatewayService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                            foreach (sysBpmsCondition condition in sysBpmsConditionList)
                            {
                                condition.GatewayID = item.ID;
                                if (condition.SequenceFlowID.HasValue)
                                {
                                    condition.SequenceFlowID = flowConvertID[condition.SequenceFlowID.Value];
                                }
                                condition.Gateway      = null;
                                condition.SequenceFlow = null;
                                resultOperation        = conditionService.Add(condition);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Copy dynamicForm
                    Dictionary <Guid, Guid>   formConvertID          = new Dictionary <Guid, Guid>();
                    DynamicFormService        dynamicFormService     = new DynamicFormService(base.UnitOfWork);
                    ApplicationPageService    applicationPageService = new ApplicationPageService(base.UnitOfWork);
                    List <sysBpmsDynamicForm> sysBpmsDynamicFormList = dynamicFormService.GetList(current.ID, null, null, "", null, null);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsDynamicForm item in sysBpmsDynamicFormList)
                        {
                            Guid oldID = item.ID;
                            item.ProcessId = newProcess.ID;
                            //First change code id.
                            dynamicFormService.UpdateBackendCodeID(item);
                            //Then update sourceCode value.
                            dynamicFormService.GetSourceCode(item);
                            item.Process    = null;
                            resultOperation = dynamicFormService.Add(item,
                                                                     item.ApplicationPageID.HasValue ? applicationPageService.GetInfo(item.ApplicationPageID.Value) : null, userName);
                            formConvertID.Add(oldID, item.ID);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                        }
                    }
                    //Update formHtml control formid property
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsDynamicForm item in sysBpmsDynamicFormList)
                        {
                            if (item.DesignJson.Contains("formId"))
                            {
                                formConvertID.ToList().ForEach(c =>
                                {
                                    item.DesignJson = item.DesignJson.Replace(c.Key.ToString(), c.Value.ToString());
                                });
                                resultOperation = dynamicFormService.Update(item, userName);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Copy task
                    TaskService        taskService     = new TaskService(base.UnitOfWork);
                    StepService        stepService     = new StepService(base.UnitOfWork);
                    List <sysBpmsTask> sysBpmsTaskList = taskService.GetList(null, current.ID);
                    if (resultOperation.IsSuccess)
                    {
                        foreach (sysBpmsTask item in sysBpmsTaskList)
                        {
                            List <sysBpmsStep> sysBpmsStepList = stepService.GetList(item.ID, null);
                            item.ID         = Guid.NewGuid();
                            item.ProcessID  = newProcess.ID;
                            item.Process    = null;
                            item.Element    = null;
                            resultOperation = taskService.Add(item);
                            if (!resultOperation.IsSuccess)
                            {
                                break;
                            }
                            foreach (sysBpmsStep step in sysBpmsStepList)
                            {
                                step.TaskID = item.ID;
                                if (step.DynamicFormID.HasValue)
                                {
                                    step.DynamicFormID = formConvertID[step.DynamicFormID.Value];
                                }
                                step.DynamicForm = null;
                                step.Task        = null;
                                resultOperation  = stepService.Add(step);
                                if (!resultOperation.IsSuccess)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    this.UnitOfWork.Save();
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }
Exemplo n.º 8
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);
        }
        public ResultOperation Update(Guid processID, WorkflowProcess workflowProcess)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                this.BeginTransaction();
                List <sysBpmsSequenceFlow> SequenceFlows = this.GetList(processID);
                foreach (sysBpmsSequenceFlow item in SequenceFlows.Where(c => !workflowProcess.SequenceFlows.Any(d => d.ID == c.ElementID)))
                {
                    resultOperation = this.Delete(item.ID);
                    if (!resultOperation.IsSuccess)
                    {
                        return(resultOperation);
                    }
                }

                //save all SequenceFlows.
                foreach (WorkflowSequenceFlow item in workflowProcess.SequenceFlows)
                {
                    sysBpmsSequenceFlow sequenceFlow = SequenceFlows.FirstOrDefault(c => c.ElementID == item.ID);
                    if (sequenceFlow != null)
                    {
                        if (sequenceFlow.Name != item.Name ||
                            sequenceFlow.SourceElementID != item.SourceRef ||
                            sequenceFlow.TargetElementID != item.TargetRef)
                        {
                            sequenceFlow.Name            = item.Name;
                            sequenceFlow.SourceElementID = item.SourceRef;
                            sequenceFlow.TargetElementID = item.TargetRef;
                            resultOperation = this.Update(sequenceFlow);

                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                            //Element
                            sequenceFlow.Element.Name = item.Name;
                            resultOperation           = new ElementService(this.UnitOfWork).Update(sequenceFlow.Element);
                            if (!resultOperation.IsSuccess)
                            {
                                return(resultOperation);
                            }
                        }
                    }
                    else
                    {
                        sequenceFlow = new sysBpmsSequenceFlow()
                        {
                            ID              = Guid.NewGuid(),
                            ElementID       = item.ID,
                            ProcessID       = processID,
                            Name            = item.Name,
                            SourceElementID = item.SourceRef,
                            TargetElementID = item.TargetRef,
                            //Element
                            Element = new sysBpmsElement()
                            {
                                ID        = item.ID,
                                Name      = item.Name,
                                ProcessID = processID,
                                TypeLU    = (int)sysBpmsElement.e_TypeLU.Sequence,
                            }
                        };
                        resultOperation = this.Add(sequenceFlow);
                        if (!resultOperation.IsSuccess)
                        {
                            return(resultOperation);
                        }
                    }
                }
                ;
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            if (resultOperation.IsSuccess)
            {
                this.UnitOfWork.Save();
            }
            base.FinalizeService(resultOperation);

            return(resultOperation);
        }