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;
                }
            });
        }
Exemple #2
0
        private void Init()
        {
            this.isNeedInit = false;
            lock (this.lockobj)
            {
                if (AppDbSettings.ListPlugins == null)
                {
                    AppDbSettings.ListPlugins = new ObservableCollection <Plugin>();
                    IParent p = (IParent)this;
                    while (p.Parent != null)
                    {
                        p = p.Parent;
                    }

                    Config cfg = (Config)p;
                    if (cfg.DicPluginLists.ContainsKey(vPluginLayerTypeEnum.DbConnection))
                    {
                        var lst = cfg.DicPluginLists[vPluginLayerTypeEnum.DbConnection];
                        foreach (var t in lst)
                        {
                            if (AppDbSettings.ListPlugins.Contains(t.Plugin))
                            {
                                continue;
                            }

                            AppDbSettings.ListPlugins.Add(t.Plugin);
                        }
                    }
                }
            }
            if (this.PluginGuid.Length == 0)
            {
                this.ListPluginGens.Clear();
                this.ListDbConns.Clear();
            }
            else
            {
                Plugin plugin = null;
                foreach (var t in AppDbSettings.ListPlugins)
                {
                    if (this.PluginGuid == t.Guid)
                    {
                        plugin = t;
                        break;
                    }
                }
                if (plugin == null)
                {
                    return;
                }

                this.ListPluginGens.Clear();
                foreach (var t in plugin.ListGenerators)
                {
                    if (t.Generator.PluginGeneratorType == vPluginLayerTypeEnum.DbConnection)
                    {
                        this.ListPluginGens.Add(t);
                    }
                }
                if (this.PluginGenGuid.Length == 0)
                {
                    this.ListDbConns.Clear();
                }
                else
                {
                    PluginGenerator gen = null;
                    foreach (var t in this.ListPluginGens)
                    {
                        if (this.PluginGenGuid == t.Guid)
                        {
                            gen = t;
                            break;
                        }
                    }
                    if (gen == null)
                    {
                        return;
                    }

                    this.ListDbConns.Clear();
                    foreach (var t in gen.ListSettings)
                    {
                        this.ListDbConns.Add(t);
                    }
                }
            }
        }