public PluginGeneratorValidator() { this.RuleFor(x => x.Generator).NotEmpty().WithMessage(Config.ValidationMessages.PLUGIN_GENERATOR_WAS_NOT_FOUND); this.RuleFor(x => x.Guid).NotEmpty().WithMessage(Config.ValidationMessages.GUID_IS_EMPTY); this.RuleFor(x => x.Guid).Custom((guid, cntx) => { PluginGenerator pg = (PluginGenerator)cntx.InstanceToValidate; if (pg.Parent == null) { return; } GroupListPlugins lst = (GroupListPlugins)pg.Parent.Parent; StringBuilder sb = new StringBuilder(); sb.Append("Not unique Generator Guid. Plugin/Generator: "); int count = 0; string sep = ""; foreach (var tt in lst.ListPlugins) { foreach (var t in tt.ListGenerators) { if (t.Guid == guid) { sb.Append(sep); sb.Append(tt.Name); sb.Append("/"); sb.Append(t.Name); sep = ", "; count++; } } } if (count > 1) { sb.Append(". Remove extra plugings"); cntx.AddFailure(sb.ToString()); } }); this.RuleFor(x => x).Custom((name, cntx) => { PluginGenerator pg = (PluginGenerator)cntx.InstanceToValidate; if (pg.Generator == null) { return; } switch (pg.Generator.PluginGeneratorType) { case common.vPluginLayerTypeEnum.DbDesign: if (!(pg.Generator is IvPluginDbGenerator)) { cntx.AddFailure("Interface 'IDbMigrator' is not implemented. Remove or fix Plugin: " + pg.Name); } break; default: break; } }); }
public PluginValidator() { this.RuleFor(x => x.VPlugin).NotEmpty().WithMessage(Config.ValidationMessages.PLUGIN_WAS_NOT_FOUND); this.RuleFor(x => x.Guid).NotEmpty().WithMessage(Config.ValidationMessages.GUID_IS_EMPTY); this.RuleFor(x => x.Guid).Custom((guid, cntx) => { var pg = (Plugin)cntx.InstanceToValidate; GroupListPlugins lst = (GroupListPlugins)pg.Parent; StringBuilder sb = new StringBuilder(); sb.Append("Not unique Plugin Guid. Plugins: "); int count = 0; string sep = ""; foreach (var t in lst.ListPlugins) { if (t.Guid == guid) { sb.Append(sep); sb.Append(t.Name); sep = ", "; count++; } } if (count > 1) { sb.Append(". Remove extra plugings"); cntx.AddFailure(sb.ToString()); } }); //this.RuleFor(x => x.Guid) // .Custom((file, cntx) => // { // if (!string.IsNullOrEmpty(file)) // { // var pg = (AppProjectGenerator)cntx.InstanceToValidate; // var path = pg.GetGenerationFilePath(); // var gs = (GroupListAppSolutions)pg.Parent.Parent.Parent; // StringBuilder sb = new StringBuilder(); // sb.Append("Files override each other . Generators: "); // int count = 0; // string sep = ""; // foreach (var t in gs.ListAppSolutions) // { // foreach (var tt in t.ListAppProjects) // { // foreach (var ttt in tt.ListAppProjectGenerators) // { // if (pg != ttt && ttt.GetGenerationFilePath() == path) // { // sb.Append(sep); // sb.Append(t.Name); // sb.Append(@"\"); // sb.Append(tt.Name); // sb.Append(@"\"); // sb.Append(ttt.Name); // sep = ", "; // count++; // } // } // } // } // if (count > 1) // { // sb.Append(". Change generation file path"); // cntx.AddFailure(sb.ToString()); // } // } // }); // unique guid for generator // unique guid for generator node settings }