public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, List <IHelixLayerInfo> otherModule, List <ITemplate> allTemplates, List <ITemplate> otherTemplates, ITemplate currentTemplate) { foreach (var baseTemplate in currentTemplate.BaseTemplates) { var conflictingTemplates = otherTemplates.Where(o => o.Id.Equals(baseTemplate)).ToList(); foreach (var conflictingTemplate in conflictingTemplates) { var isInSameModule = currentModule.Value.Any(p => p.Id.Equals(conflictingTemplate.Id)); if (!isInSameModule) { return(new RuleValidationResult(GetFailResult(), $"Cross module template inheritance found between {currentTemplate} and {otherTemplates.FirstOrDefault(p => p.Id.Equals(conflictingTemplate.Id))}")); } if (!_allowInheritanceInsideSameModule) { return(new RuleValidationResult(GetFailResult(), $"Template inheritance found between {currentTemplate} and {currentModule.Value.FirstOrDefault(p => p.Id.Equals(conflictingTemplate.Id))}")); } } } return(new RuleValidationResult(RuleResult.Success)); }
private List <IRuleValidationResult> ProcessLayer(IHelixLayerInfo layer, List <IHelixLayerInfo> allLayers) { var validationResult = new List <IRuleValidationResult>(); foreach (var currentModule in layer.Modules) { var dataElements = currentModule.Value.Cast <IRendering>().ToList(); foreach (var rendering in dataElements) { var success = true; foreach (var rule in _rules) { var result = rule.Validate(allLayers, layer, currentModule, rendering); if (result.Result != RuleResult.Success) { validationResult.Add(new RuleValidationResult(result.Result, GetResultMessage(rendering, rule, result))); success = false; } } if (success) { validationResult.Add(new RuleValidationResult(RuleResult.Success, GetSuccessResultMessage(rendering))); } } } return(validationResult); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, List <IHelixLayerInfo> otherModule, List <ITemplate> allTemplates, List <ITemplate> otherTemplates, ITemplate currentTemplate) { var fields = new HashSet <IField>(); var result = AddField(currentTemplate, fields, currentTemplate); if (result.Result != RuleResult.Success) { return(result); } foreach (var baseTemplate in currentTemplate.BaseTemplates) { var bases = allTemplates.FirstOrDefault(p => p.Id.Equals(baseTemplate)); if (bases != null) { result = AddField(bases, fields, currentTemplate); if (result.Result != RuleResult.Success) { return(result); } } } return(new RuleValidationResult(RuleResult.Success)); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, List <IHelixLayerInfo> otherModule, List <ITemplate> allTemplates, List <ITemplate> otherTemplates, ITemplate currentTemplate) { var hasCircularReference = currentTemplate.BaseTemplates.Any(p => p.Equals(currentTemplate.Id)); var result = GetFailResult(); return(!hasCircularReference ? new RuleValidationResult(RuleResult.Success) : new RuleValidationResult(result, $"The template {currentTemplate} has circular reference.")); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, IEnumerable <ISetting> allSettings, ISetting currentSetting) { if (currentSetting.Template != null && currentSetting.Template.Path.IndexOf(currentLayer.Name, StringComparison.InvariantCultureIgnoreCase) < 0 && !TemplateFromFoundation(currentSetting)) { return(new RuleValidationResult(GetFailResult(), $"Cross module template inheritance found for setting: {currentSetting} with the template: {currentSetting.Template}")); } return(new RuleValidationResult(RuleResult.Success)); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, List <IHelixLayerInfo> otherModule, List <ITemplate> allTemplates, List <ITemplate> otherTemplates, ITemplate currentTemplate) { if (currentLayer.Name.Equals("Foundation", StringComparison.InvariantCultureIgnoreCase) && !currentTemplate.Name.StartsWith("_")) { return(new RuleValidationResult(GetFailResult(), $"The Template {currentTemplate} is not follows Foundation layer naming convention.")); } return(new RuleValidationResult(RuleResult.Success)); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, IRendering currentRendering) { var illegalChar = new List <string> { ",", "-", "." }; foreach (var c in illegalChar) { if (currentRendering.Name.Contains("-")) { return(new RuleValidationResult(GetFailResult(), $"The Rendering {currentRendering} has illegal Character on its name.")); } } return(new RuleValidationResult(RuleResult.Success)); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, List <IHelixLayerInfo> otherModule, List <ITemplate> allTemplates, List <ITemplate> otherTemplates, ITemplate currentTemplate) { if (_illegalChars != null) { var illegalChar = _illegalChars.ToCharArray(); foreach (var c in illegalChar) { if (currentTemplate.Name.IndexOf(c) > -1) { return(new RuleValidationResult(GetFailResult(), $"The Template {currentTemplate} has illegal Character on its name.")); } } } return(new RuleValidationResult(RuleResult.Success)); }
public IRuleValidationResult Validate(IEnumerable <IHelixLayerInfo> allLayers, IHelixLayerInfo currentLayer, KeyValuePair <string, IDataElement[]> currentModule, IRendering currentRendering) { var datasourceLocation = currentRendering.Fields.FirstOrDefault(p => p.Id == _renderingDatasourceLocationId); var datasourceTemplate = currentRendering.Fields.FirstOrDefault(p => p.Id == _renderingDatasourceTemplateId); if (_datasourceLocation && datasourceLocation != null && !string.IsNullOrEmpty(datasourceLocation.Value) && datasourceLocation.Value.StartsWith("/")) { return(new RuleValidationResult(GetFailResult(), $"DataSource Location is set to: {datasourceLocation.Value} for this rendering: {currentRendering}")); } if (_datasourceTemplate && datasourceTemplate != null && !string.IsNullOrEmpty(datasourceTemplate.Value)) { return(new RuleValidationResult(GetFailResult(), $"DataSource Template is set to: {datasourceTemplate.Value} for this rendering: {currentRendering}")); } return(new RuleValidationResult(RuleResult.Success)); }
private List <IRuleValidationResult> ProcessLayer(List <IHelixLayerInfo> allLayers, IHelixLayerInfo layer, List <ITemplate> allTemplates) { var others = allLayers.Except(layer.DependentLayers, new HelixLayerEqualityComparer()) .Cast <IHelixLayerInfo>().ToList(); var otherTemplates = others .SelectMany(p => p.Modules.SelectMany(q => q.Value.Select(u => u as ITemplate))).ToList(); var validationResult = new List <IRuleValidationResult>(); foreach (var currentModule in layer.Modules) { var dataElements = currentModule.Value.Cast <ITemplate>().Where(p => p.BaseTemplates.Length > 0) .ToList(); foreach (var template in dataElements) { var success = true; foreach (var rule in _rules) { var result = rule.Validate(allLayers, layer, currentModule, others, allTemplates, otherTemplates, template); if (result.Result != RuleResult.Success) { validationResult.Add(new RuleValidationResult(result.Result, GetResultMessage(template, rule, result))); success = false; } } if (success) { validationResult.Add(new RuleValidationResult(RuleResult.Success, GetSuccessResultMessage(template))); } } } return(validationResult); }
private List <IRuleValidationResult> ValidateSettingItem(List <IHelixLayerInfo> allLayers, IHelixLayerInfo layer, List <ISetting> allSettings, KeyValuePair <string, IDataElement[]> currentModule, ISetting currentSetting) { var validationResult = new List <IRuleValidationResult>(); var success = true; foreach (var rule in _rules) { var result = rule.Validate(allLayers, layer, currentModule, allSettings, currentSetting); if (result.Result != RuleResult.Success) { validationResult.Add(new RuleValidationResult(result.Result, GetResultMessage(currentSetting, rule, result))); success = false; } } if (success) { validationResult.Add(new RuleValidationResult(RuleResult.Success, GetSuccessResultMessage(currentSetting))); } foreach (var child in currentSetting.Children) { validationResult.AddRange(ValidateSettingItem(allLayers, layer, allSettings, currentModule, child)); } return(validationResult); }
private List <IRuleValidationResult> ProcessLayer(List <IHelixLayerInfo> allLayers, IHelixLayerInfo layer, List <ISetting> allSettings) { var validationResult = new List <IRuleValidationResult>(); foreach (var currentModule in layer.Modules) { var dataElements = currentModule.Value.Cast <ISetting>().ToList(); foreach (var currentSetting in dataElements) { validationResult.AddRange(ValidateSettingItem(allLayers, layer, allSettings, currentModule, currentSetting)); } } return(validationResult); }