public EntityWorkflow CreateWorkflow() { WorkflowProvider workflowProvider = new WorkflowProvider { Guid = _guid, Name = _name, PropertyName = _propertyName, EntitySet = _entitySet, StageListGuid = _stageListGuid, StagePropertyGuid = _stagePropertyGuid, Types = _types.ToArray(), ShowInLinks = new HashSet <Guid>(_showInLinks), HistoryConfiguration = _historyCofiguration }; EntityWorkflow result = new EntityWorkflow(workflowProvider); ValueList valueList; if (_stageListGuid == Guid.Empty) { EntitySetScheme scheme = _entitySet.GetScheme(); if (_types.Count == 0) { valueList = (scheme.Properties.Find(_stagePropertyGuid)?.Format as ValueListPropertyFormat)?.ValueList?.GetList(); } else { EntityType type = _types.SelectMany(t => t.GetTypes(scheme.Types)).FirstOrDefault(); valueList = (type?.Properties.Find(_stagePropertyGuid)?.Format as ValueListPropertyFormat)?.ValueList?.GetList(); } } else { valueList = ValueList.GetValueList(_entitySet.Connection, _stageListGuid); if (valueList == null) { throw new ModelException(ErrorLevel.Warning, "Не найден список значений {0}", _stageListGuid); } } ILookup <object, ValueListItem> items = valueList?.ToLookup(i => i.WorkflowValue); List <EntityWorkflowStage> stages = new List <EntityWorkflowStage>(); foreach (KeyValuePair <object, IEntityWorkflowStage> source in _stages) { StageProvider stageProvider = new StageProvider { Id = source.Key, Item = items?[source.Key].FirstOrDefault() }; stages.Add(new EntityWorkflowStage(result, stageProvider)); } result.Stages = stages; Dictionary <object, List <EntityWorkflowTransition> > transitionsTo = stages.ToDictionary(s => s.Id, s => new List <EntityWorkflowTransition>()); Dictionary <object, List <EntityWorkflowTransition> > transitionsFrom = stages.ToDictionary(s => s.Id, s => new List <EntityWorkflowTransition>()); result.Transitions = _transitions.OfType <TransitionInfo>().Select( t => t.CreateTransition(result, workflowProvider, transitionsTo, transitionsFrom)).ToList(); foreach (EntityWorkflowStage stage in stages) { stage.SetTransitionsTo(transitionsTo[stage.Id]); stage.SetTransitionsFrom(transitionsFrom[stage.Id]); } return(result); }