private static Result InnerSyncVariables <T>(T entity, CollectorSerializerRoot serializerRoot, string definition, DefinitionType definitionType) where T : RuleEntity//, new() { //получаем все переменные Устава var globalVariables = entity.TypiconVersion.TypiconVariables; //очищаем все ссылки на используемые ранее Переменные данного типа globalVariables.ForEach(c => c.ClearLinks(entity, definitionType)); //получаем локальные переменные var localVariables = GetLocalVariables(serializerRoot, definition); var errors = new List <string>(); foreach (var v in localVariables) { var found = globalVariables.FirstOrDefault(c => c.Name == v.Name); if (found != null) { //type mismatch? if (found.Type == v.Type) { found.AddLink(entity, definitionType); } else { errors.Add($"Ошибка: Переменная {found.Name} уже зарегистрирована в Уставе с типом переменной {found.Type}."); } } else { //нет такой переменной еще - значит добавляем var variable = new TypiconVariable() { TypiconVersion = entity.TypiconVersion, Name = v.Name, Type = v.Type }; variable.AddLink(entity, definitionType); entity.TypiconVersion.TypiconVariables.Add(variable); } } //удаляем Переменные Устава, у которых нет ссылок entity.TypiconVersion.TypiconVariables .RemoveAll(c => c.CommonRuleLinks.Count == 0 && c.ExplicitAddRuleLinks.Count == 0 && c.MenologyRuleLinks.Count == 0 && c.TriodionRuleLinks.Count == 0 && c.SignLinks.Count == 0); return((errors.Count > 0) ? Result.Fail(string.Join('\n', errors)) : Result.Ok()); }
private Result <VariableEditModelBase> GetModel(TypiconVariable variable) { VariableEditModelBase result = null; var links = GetLinks(variable); switch (variable.Type) { case VariableType.Worship: { result = new VariableEditWorshipModel() { Id = variable.Id, TypiconId = variable.TypiconVersion.TypiconId, IsTemplate = variable.TypiconVersion.IsTemplate, Name = variable.Name, Type = variable.Type, Header = variable.Header, Description = variable.Description, Count = links.Count, Links = links, Value = Compose(variable.Value) }; break; } case VariableType.Time: default: { result = new VariableEditTimeModel() { Id = variable.Id, TypiconId = variable.TypiconVersion.TypiconId, IsTemplate = variable.TypiconVersion.IsTemplate, Name = variable.Name, Type = variable.Type, Header = variable.Header, Description = variable.Description, Count = links.Count, Links = links, Value = variable.Value }; break; } } return((result != null) ? Result.Ok(result) : Result.Fail <VariableEditModelBase>("Ошибка при формировании объекта.")); }
private List <VariableLinkModel> GetLinks(TypiconVariable found) { var result = new List <VariableLinkModel>(); result.AddRange(found.CommonRuleLinks .Select(c => new VariableLinkModel() { EntityId = c.EntityId, EntityName = nameof(CommonRule), DefinitionType = DefinitionType.Rule })); result.AddRange(found.ExplicitAddRuleLinks .Select(c => new VariableLinkModel() { EntityId = c.EntityId, EntityName = nameof(ExplicitAddRule), DefinitionType = DefinitionType.Rule })); result.AddRange(found.SignLinks .Select(c => new VariableLinkModel() { EntityId = c.EntityId, EntityName = nameof(Sign), DefinitionType = c.DefinitionType })); result.AddRange(found.MenologyRuleLinks .Select(c => new VariableLinkModel() { EntityId = c.EntityId, EntityName = nameof(MenologyRule), DefinitionType = c.DefinitionType })); result.AddRange(found.TriodionRuleLinks .Select(c => new VariableLinkModel() { EntityId = c.EntityId, EntityName = nameof(TriodionRule), DefinitionType = c.DefinitionType })); return(result); }
private string HandleValue(TypiconVariable found) { switch (found.Type) { case VariableType.Time: { return(found.Value); } case VariableType.Worship: { throw new NotImplementedException(); } default: { return(found.Value); } } }