Exemple #1
0
        public bool Start(SystemForm systemForm, string key, Dictionary <string, string> prarms)
        {
            bool bResult = false;

            try
            {
                List <WorkControlEntity> controls = new List <WorkControlEntity>();
                if (prarms != null && prarms.Count > 0)
                {
                    WorkControlEntity workControlEntity = new WorkControlEntity();
                    foreach (var item in prarms)
                    {
                        workControlEntity          = new WorkControlEntity();
                        workControlEntity.FullName = item.Key;
                        workControlEntity.Value    = item.Value;
                        controls.Add(workControlEntity);
                    }
                }
                FlowEntity flowEntity = flowApp.GetForm(systemForm);
                workApp.StartApply(flowEntity?.Id, key, controls);
                bResult = true;
            }
            catch
            {
                bResult = false;
            }
            return(bResult);
        }
Exemple #2
0
        public async Task <FlowResult <FlowTransition> > CreateFlowTransitionAsync(InitFlowTransitionModel model)
        {
            var set      = StateManager.GetFlowSet <FlowTransition>();
            var stateSet = StateManager.GetFlowSet <FlowState>();

            var source = await stateSet.GetByIdAsync(model.SourceId);

            if (source == null)
            {
                return(FlowResult <FlowTransition>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(source))));
            }

            var destination = await stateSet.GetByIdAsync(model.DestinationId);

            if (destination == null)
            {
                return(FlowResult <FlowTransition>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(destination))));
            }

            var entity = FlowEntity.InitializeType(new FlowTransition()
            {
                Name           = model.Name,
                Title          = model.Title,
                SourceId       = source.Id,
                DestinationId  = destination.Id,
                TransitionType = model.TransitionType,
                TypeId         = source.TypeId,
            });

            var result = await set.CreateAsync(entity);

            return(FlowResult <FlowTransition> .Successful(result));
        }
Exemple #3
0
        public FormControlEntity GetControlByWorkId(string workId, string controlId)
        {
            FormControlEntity model = new FormControlEntity();

            using (var db = new RepositoryBase())
            {
                WorkEntity workEntity = db.FindEntity <WorkEntity>(m => m.Id == workId);
                if (workEntity != null && !string.IsNullOrEmpty(workEntity.Id))
                {
                    FlowVersionEntity flowVersionEntity = db.FindEntity <FlowVersionEntity>(m => m.Id == workEntity.FlowVersionId);
                    if (flowVersionEntity != null && !string.IsNullOrEmpty(flowVersionEntity.Id))
                    {
                        FlowEntity flowEntity = db.FindEntity <FlowEntity>(m => m.Id == flowVersionEntity.FlowId);
                        if (flowEntity != null && !string.IsNullOrEmpty(flowEntity.Id))
                        {
                            FormEntity formEntity = db.FindEntity <FormEntity>(m => m.Id == flowEntity.FormId);
                            if (formEntity != null && !string.IsNullOrEmpty(formEntity.Id))
                            {
                                model = db.FindEntity <FormControlEntity>(m => m.FormId == formEntity.Id && m.ControlId == controlId);
                            }
                        }
                    }
                }
            }
            return(model);
        }
Exemple #4
0
        public void AddSectorUp(int viewIndex)
        {
            int index = ViewIndexToFlowIndex(viewIndex);

            string sectorId = "AAAA";
            Sector sector   = Sector.Create(_root, sectorId);

            _flowData.AddEntity(sector);

            string  segmentId = "AAAA";
            Segment segment   = Segment.Create(_root, sector, segmentId);

            _flowData.AddEntity(segment);

            FlowEntity flow = FlowEntity.Create(_root, sector, segment, index);

            _flowData.AddEntity(flow);

            Cell cell = new Cell();

            cell.Flow          = flow;
            cell.Sector        = sector;
            cell.Segment       = segment;
            cell.SegmentDetail = null;
            _flowData.InsertCell(index, cell);
        }
        public async Task <FlowResult <FlowState> > CreateFlowStateAsync(InitFlowStateModel model)
        {
            var set     = StateManager.GetFlowSet <FlowState>();
            var typeSet = StateManager.GetFlowSet <FlowType>();

            var type = await typeSet.GetByIdAsync(model.TypeId);

            if (type == null)
            {
                return(FlowResult <FlowState>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(type))));
            }

            var entity = FlowEntity.InitializeType(new FlowState()
            {
                Name      = model.Name,
                Title     = model.Title,
                StateType = (byte)model.StateType,
                TypeId    = type.Id,
                Tag       = model.Tag,
            });

            var result = await set.CreateAsync(entity);

            return(FlowResult <FlowState> .Successful(result));
        }
Exemple #6
0
        public async Task <FlowResult <FlowInstance> > CreateFlowInstanceAsync(InitFlowModel model)
        {
            var set     = StateManager.GetFlowSet <FlowInstance>();
            var typeSet = StateManager.GetFlowSet <FlowType>();

            var type = await typeSet.GetByIdAsync(model.TypeId);

            if (type == null)
            {
                return(FlowResult <FlowInstance>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(type))));
            }

            var entity = FlowEntity.InitializeType(new FlowInstance()
            {
                Title         = model.Title,
                Payload       = model.Payload,
                TypeId        = type.Id,
                InitializerId = model.InitializerId,
                AccessPhrase  = model.AccessPhrase,
            });

            var result = await set.CreateAsync(entity);

            return(FlowResult <FlowInstance> .Successful(result));
        }
        protected void AndGivenADataSourceLogExistsAndIsValidAndIncludingSpecificFileTypes()
        {
            // flow entity
            _flowEntity = FlowEntity.Create <TestEntity>();

            _repo = new DataSourceLogRepo(_logDir);
            _repo.Save(new DataFileLog(_flowEntity, "*.csv"));
        }
Exemple #8
0
 public FlowNode(int flowNodeId, double flowNodeVersion, FlowQuestion flowQuestion, FlowValueType flowNodeType = FlowValueType.None, FlowEntity flowNodeEntity = FlowEntity.None, List <FlowAnswer> flowAnswers = null !)
 {
     FlowNodeId      = flowNodeId;
     FlowNodeVersion = flowNodeVersion;
     FlowQuestion    = flowQuestion;
     FlowNodeType    = flowNodeType;
     FlowNodeEntity  = flowNodeEntity;
     FlowAnswers     = flowAnswers;
 }
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        public FlowFileLog(FlowEntity entityType, string flowCode)
        {
            Guard.ArgumentNotNullOrEmptyOrWhiteSpace(flowCode, nameof(flowCode));
            Guard.ArgumentNotNull(entityType, nameof(entityType));

            Entries    = new List <FlowFileLogEntry>();
            FlowEntity = entityType;
            FlowCode   = flowCode;
        }
Exemple #10
0
        public string GetFormDesign(string flowId)
        {
            string     strContents = string.Empty;
            FlowEntity flowEntity  = flowApp.GetForm(flowId);

            if (flowEntity != null && !string.IsNullOrEmpty(flowEntity.Id) && !string.IsNullOrEmpty(flowEntity.FormId))
            {
                FormEntity formEntity = formApp.GetForm(flowEntity.FormId);
                strContents = formEntity.Codes;
            }
            return(strContents);
        }
Exemple #11
0
        public void StartApply(string flowId, string key, List <WorkControlEntity> controls)
        {
            WorkEntity workEntity = new WorkEntity();

            if (flowId != null)
            {
                FlowEntity flowentity = flowApp.GetForm(flowId);
                if (flowentity != null && !string.IsNullOrEmpty(flowentity.Id))
                {
                    FormEntity        formEntity        = formApp.GetForm(flowentity.FormId);
                    FlowVersionEntity flowVersionEntity = flowApp.GetDesign(flowId);
                    if (flowentity != null && !string.IsNullOrEmpty(flowentity.Id) &&
                        formEntity != null && !string.IsNullOrEmpty(formEntity.Id) &&
                        flowVersionEntity != null && !string.IsNullOrEmpty(flowVersionEntity.Id))
                    {
                        workEntity.Create();
                        workEntity.FullName      = flowentity.FullName;
                        workEntity.FlowVersionId = flowVersionEntity.Id;
                        workEntity.FlowStatus    = (int)WorkStatus.Applying;
                        workEntity.Codes         = formEntity.Codes;
                        workEntity.Contents      = key;
                        var loguser = OperatorProvider.Provider.GetCurrent();
                        if (loguser != null)
                        {
                            workEntity.ApplyUserId = loguser.UserId;
                        }
                        service.AddForm(workEntity, controls, null);
                        try
                        {
                            workFlowApp.Start(workEntity.Id);
                        }
                        catch (Exception ex)
                        {
                            workEntity.FlowStatus = (int)WorkStatus.Save;
                            service.Update(workEntity);
                            throw ex;
                        }
                    }
                    else
                    {
                        throw new Exception("操作失败!");
                    }
                }
                else
                {
                    throw new Exception("操作失败!");
                }
            }
            else
            {
                throw new Exception("操作失败,提交状态无效!");
            }
        }
Exemple #12
0
        public async Task <FlowResult <FlowType> > CreateFlowTypeAsync(InitFlowTypeModel initModel)
        {
            var set    = StateManager.GetFlowSet <FlowType>();
            var entity = FlowEntity.InitializeType(new FlowType()
            {
                EntityType        = initModel.EntityType.FullName,
                EntityPayloadType = initModel.EntityPayloadType.FullName,
                Name = initModel.Name,
            });
            var resultTask = await set.CreateAsync(entity);

            return(FlowResult <FlowType> .Successful(resultTask));
        }
Exemple #13
0
        protected void AndThenShouldBeAbleToRestoreProcessState()
        {
            var repo =
                new FlowSnapshotRepo <FlowSnapShot <Dto1> >(Environment.CurrentDirectory);

            var targetEntityType = new FlowEntity(typeof(Dto2));

            var result = repo.Get(targetEntityType.EntityTypeId, _flow.Code, BatchId);

            Assert.NotNull(result);
            Assert.Equal(CsvItemsToCreate - 1, result.ProcessedCount);
            Assert.Empty(result.Errors);
        }
Exemple #14
0
 public void SubmitForm(FlowEntity flowEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         flowEntity.Modify(keyValue);
         service.Update(flowEntity);
     }
     else
     {
         flowEntity.EnabledMark = true;
         flowEntity.Create();
         service.Insert(flowEntity);
     }
 }
Exemple #15
0
        public void EnbaledForm(string keyValue)
        {
            FlowEntity flowEntity = GetForm(keyValue);

            if (flowEntity != null && !string.IsNullOrEmpty(flowEntity.Id))
            {
                flowEntity.Modify(keyValue);
                flowEntity.EnabledMark = true;
                service.Update(flowEntity);
            }
            else
            {
                throw new Exception("获取数据异常!");
            }
        }
        public async Task <int> Add(FlowEntity entity)
        {
            entity.CreatedOn = DateTime.Now;
            var sql          = "INSERT INTO Flows (Id, Name, CreatedOn) Values (@Id,@Name, @CreatedOn);";
            var affectedRows = await Connection.ExecuteAsync(sql, new { Id = entity.Id, Name = entity.Name, CreatedOn = entity.CreatedOn }, Transaction);

            return(affectedRows);

            /*using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")))
             * {
             *  connection.Open();
             *  var affectedRows = await connection.ExecuteAsync(sql, entity);
             *  return affectedRows;
             * }*/
        }
        public async Task <int> Update(FlowEntity entity)
        {
            entity.ModifiedOn = DateTime.Now;
            var sql          = "UPDATE Tasks SET Name = @Name, ModifiedOn = @DateModified WHERE Id = @Id;";
            var affectedRows = await Connection.ExecuteAsync(sql, new { Name = entity.Name, ModifiedOn = entity.ModifiedOn, Id = entity.Id }, Transaction);

            return(affectedRows);

            /*using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")))
             * {
             *  connection.Open();
             *  var affectedRows = await connection.ExecuteAsync(sql, entity);
             *  return affectedRows;
             * }*/
        }
Exemple #18
0
 public void SubmitForm(FlowEntity flowEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         if (flowEntity.FormType == (int)FormType.Custom)
         {
             flowEntity.FormUrl = string.Empty;
         }
         if (flowEntity.FormType == (int)FormType.System)
         {
             if (IsExistSystemFlow((SystemForm)flowEntity.SystemFormType, keyValue))
             {
                 throw new Exception("当前系统表单已存在流程,请确认!");
             }
             if (flowEntity.SystemFormType != null)
             {
                 flowEntity.FormUrl        = EnumHelp.enumHelp.GetDefaultValue(typeof(SystemForm), (int)flowEntity.SystemFormType);
                 flowEntity.SystemFormName = EnumHelp.enumHelp.GetDescription(typeof(SystemForm), (int)flowEntity.SystemFormType);
             }
             flowEntity.FormId = string.Empty;
         }
         flowEntity.Modify(keyValue);
         service.Update(flowEntity);
     }
     else
     {
         if (flowEntity.FormType == (int)FormType.Custom)
         {
             flowEntity.FormUrl = string.Empty;
         }
         if (flowEntity.FormType == (int)FormType.System)
         {
             if (IsExistSystemFlow((SystemForm)flowEntity.SystemFormType, keyValue))
             {
                 throw new Exception("当前系统表单已存在流程,请确认!");
             }
             if (flowEntity.SystemFormType != null)
             {
                 flowEntity.FormUrl        = EnumHelp.enumHelp.GetDefaultValue(typeof(SystemForm), (int)flowEntity.SystemFormType);
                 flowEntity.SystemFormName = EnumHelp.enumHelp.GetDescription(typeof(SystemForm), (int)flowEntity.SystemFormType);
             }
             flowEntity.FormId = string.Empty;
         }
         flowEntity.EnabledMark = true;
         flowEntity.Create();
         service.Insert(flowEntity);
     }
 }
Exemple #19
0
        /// <summary>
        /// 获取当前流程申请时自定义默认值
        /// </summary>
        /// <param name="flowId"></param>
        public string GetCommonCustomDefaultTypeJson(string flowId, string controlId)
        {
            string strTypes = string.Empty;

            FlowEntity flowEntity = flowApp.GetForm(flowId);

            if (flowEntity != null && !string.IsNullOrEmpty(flowEntity.Id) && !string.IsNullOrEmpty(flowEntity.FormId))
            {
                FormControlEntity formControl = service.GetControl(flowEntity.FormId, controlId);
                if (formControl != null && !string.IsNullOrEmpty(formControl.Id))
                {
                    strTypes = formControl.DefaultType;
                }
            }
            return(strTypes);
        }
Exemple #20
0
        public bool Start(SystemForm systemForm, string key)
        {
            bool bResult = false;

            try
            {
                FlowEntity flowEntity = flowApp.GetForm(systemForm);
                workApp.StartApply(flowEntity?.Id, key);
                bResult = true;
            }
            catch
            {
                bResult = false;
            }
            return(bResult);
        }
Exemple #21
0
        public async Task <FlowResult <FlowStep> > CreateFlowStepAsync(MoveModel model)
        {
            var set           = StateManager.GetFlowSet <FlowStep>();
            var instanceSet   = StateManager.GetFlowSet <FlowInstance>();
            var transitionSet = StateManager.GetFlowSet <FlowTransition>();
            var stateSet      = StateManager.GetFlowSet <FlowState>();

            var instance = await instanceSet.GetByIdAsync(model.InstanceId);

            if (instance == null)
            {
                return(FlowResult <FlowStep>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(instance))));
            }

            var transition = await transitionSet.GetByIdAsync(model.TransitionId);

            if (transition == null)
            {
                return(FlowResult <FlowStep>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(transition))));
            }

            var state = await stateSet.GetByIdAsync(transition.DestinationId);

            if (state == null)
            {
                return(FlowResult <FlowStep>
                       .Failed(new FlowError(FlowErrors.ItemNotFound, nameof(state))));
            }

            var entity = FlowEntity.InitializeType(new FlowStep()
            {
                InstanceId        = instance.Id,
                IsCurrent         = true,
                TransitionId      = transition.Id,
                Payload           = model.Payload,
                Comment           = model.Comment,
                CurrentStateName  = state.Name,
                CurrentStateTitle = state.Title,
                CurrentStateType  = state.StateType,
            });

            var result = await set.CreateAsync(entity);

            return(FlowResult <FlowStep> .Successful(result));
        }
Exemple #22
0
        public void SaveDesign(string keyValue, string codes)
        {
            FlowEntity        flowEntity        = GetForm(keyValue);
            FlowVersionEntity flowVersionEntity = new FlowVersionEntity();
            Random            rand = new Random();

            flowVersionEntity.EnCode = "V" + DateTime.Now.ToString("yyyyMMddHHmmss") + rand.Next(0000, 9999);
            flowVersionEntity.Codes  = codes;
            if (flowEntity != null && !string.IsNullOrEmpty(flowEntity.Id))
            {
                flowVersionEntity.FlowId = flowEntity.Id;
                JObject obj = JObject.Parse(codes);
                if (obj != null)
                {
                    foreach (KeyValuePair <string, JToken> item in obj)
                    {
                        string key = item.Key;
                        switch (key)
                        {
                        case "title":
                            break;

                        case "nodes":
                            GenFlowNodes(flowVersionEntity, item);
                            break;

                        case "lines":
                            GenFlowLines(flowVersionEntity, item);
                            break;

                        case "areas":
                            GenFlowAreas(flowVersionEntity, item);
                            break;

                        case "initNum":
                            flowVersionEntity.InitNum = (int)item.Value;
                            break;
                        }
                    }
                }
                service.SaveDesign(flowVersionEntity);
            }
            else
            {
                throw new Exception("获取数据异常!");
            }
        }
        public async Task <Guid> Create(FlowModel model)
        {
            var entity = new FlowEntity();

            entity.Name = model.Name;
            entity.Id   = Guid.NewGuid();
            var result = await _unitOfWork.Flows.Add(entity);

            foreach (var state in model.States)
            {
                var stateEntity = new FlowStatesEntity {
                    FlowId = entity.Id, Id = Guid.NewGuid(), Order = state.Order, StateId = state.StateId, CreatedOn = DateTime.Now
                };
                await _unitOfWork.FlowStates.Add(stateEntity);
            }
            _unitOfWork.Commit();

            return(entity.Id);
        }
Exemple #24
0
        private bool IsExistSystemFlow(SystemForm systemForm, string flowId)
        {
            bool bResult    = false;
            var  expression = ExtLinq.True <FlowEntity>();

            expression = expression.And(t => t.DeleteMark != true &&
                                        t.EnabledMark == true &&
                                        t.FormType == (int)FormType.System &&
                                        t.SystemFormType == (int)systemForm);
            if (!string.IsNullOrWhiteSpace(flowId))
            {
                expression = expression.And(t => t.Id != flowId);
            }
            FlowEntity flow = service.IQueryable(expression).OrderBy(t => t.SortCode).FirstOrDefault();

            if (flow == null || string.IsNullOrWhiteSpace(flow.Id))
            {
                bResult = true;
            }
            return(bResult);
        }
Exemple #25
0
 /// <summary>
 /// 添加服务
 /// </summary>
 /// <param name="flow"></param>
 protected virtual IDomainService CreateDomainService(FlowEntity flow)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(flow.ClassName))
         {
             return(null);
         }
         var t = Type.GetType(flow.ClassName);
         if (t == null)
         {
             return(null);
         }
         return(Activator.CreateInstance(t) as IDomainService);
     }
     catch (Exception ex)
     {
         Winner.Creator.Get <Winner.Log.ILog>().AddException(ex);
     }
     return(null);
 }
Exemple #26
0
 /// <summary>
 /// 生成
 /// </summary>
 /// <param name="flow"></param>
 protected virtual void CreateArgsService(FlowEntity flow)
 {
     lock (DomainServiceLocker)
     {
         if (flow == null)
         {
             return;
         }
         var domainService = CreateDomainService(flow);
         if (flow.Nodes == null)
         {
             return;
         }
         foreach (var node in flow.Nodes)
         {
             SetNodeDelegate(node, domainService);
         }
         if (DomainServices.ContainsKey(flow.Id))
         {
             DomainServices.Remove(flow.Id);
         }
         DomainServices.Add(flow.Id, domainService);
     }
 }
Exemple #27
0
 public ActionResult SubmitForm(FlowEntity flowEntity, string keyValue)
 {
     flowApp.SubmitForm(flowEntity, keyValue);
     return(Success("操作成功。"));
 }
        /// <summary>
        ///     Enriches the source data with data from parts.
        /// </summary>
        /// <typeparam name="TTarget">The whole data type to enrich.</typeparam>
        /// <param name="targets">The data source for 'whole' objects that will be enriched..</param>
        /// <param name="enrichers">The sources to enrich 'whole' target objects.</param>
        /// <returns></returns>
        public void Enrich <TTarget>(
            FlowBatch flowBatch,
            IEnumerable <IEnrichmentTarget <TTarget> > targets,
            IEnumerable <IEnricher <TTarget> > enrichers)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Enriching targets.");
            }

            // parallelize enrichment of the targets
            foreach (var enricher in enrichers.AsParallel())
            {
                // enrichment log to record transactions
                var db = new EnricherLog(flowBatch.Flow, enricher.SourceEntityType);

                // list of items to create
                // ReSharper disable once PossibleMultipleEnumeration
                foreach (var target in targets)
                {
                    // record event so that it is not duplicated
                    var logEntry = new EnrichmentLogEntry
                    {
                        DateCreated     = DateTime.UtcNow,
                        Batch           = flowBatch,
                        SourceAddressId = enricher.AddressId,
                        TargetAddressId = target.AddressId,
                        TargetEntity    = FlowEntity.Create <TTarget>()
                    };

                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug($"Enriching target with enricher {enricher}.");
                    }

                    foreach (var entity in target.Get())
                    {
                        try
                        {
                            // find the parts that can enrich the whole
                            var foundParts = enricher.Find(entity);

                            // ReSharper disable once SuspiciousTypeConversion.Global
                            foreach (var part in foundParts)
                            {
                                try
                                {
                                    // enrich the whole from the part
                                    enricher.Enrich(part, entity);

                                    // increment entities enriched
                                    logEntry.EntitiesEnriched++;
                                }
                                catch (Exception ex)
                                {
                                    throw new ApplicationException(
                                              $"Failed to enrich {target} from {part} due to an unexpected error.",
                                              ex);
                                }
                            }
                        }
                        catch (ApplicationException aex)
                        {
                            db.Exceptions.Add(aex);

                            throw;
                        }
                        catch (Exception ex)
                        {
                            db.Exceptions.Add(ex);

                            throw new Exception(
                                      $"Failed to enrich whole {target} from source {targets} due to an unexpected error.", ex);
                        }
                    }

                    // update transasction log
                    lock (this)
                    {
                        // the date/time completed
                        logEntry.Completed = DateTime.UtcNow;
                        // add log entry after completes
                        db.Logs.Add(logEntry);
                    }
                }

                this._logRepository.Save(db);
            }
        }
Exemple #29
0
 public List <Models.FlowAnswer> GetLookupValues(FlowEntity entity) => entity switch
 {
Exemple #30
0
 /// <summary>
 /// 添加服务
 /// </summary>
 /// <param name="flow"></param>
 protected virtual IDomainService CreateDomainService(FlowEntity flow)
 {
     return(Winner.Creator.Get <Winner.Creation.IFactory>().Get <IDomainService>(flow.ClassName));
 }