Example #1
0
        public static CodeGenerator CodeGeneratorFromProperties()
        {
            var properties = Preferences.LoadProperties();

            var config = new CodeGeneratorConfig();

            config.Configure(properties);

            var types = LoadTypesFromPlugins(properties);

            var dataProviders  = GetEnabledInstances <ICodeGeneratorDataProvider>(types, config.DataProviders);
            var codeGenerators = GetEnabledInstances <ICodeGenerator>(types, config.CodeGenerators);
            var postProcessors = GetEnabledInstances <ICodeGenFilePostProcessor>(types, config.PostProcessors);

            Configure(dataProviders, properties);
            Configure(codeGenerators, properties);
            Configure(postProcessors, properties);

            return(new CodeGenerator(dataProviders, codeGenerators, postProcessors));
        }
Example #2
0
        static void PrintPluginStatus(Type[] types, CodeGeneratorConfig config)
        {
            var unavailableDataProviders =
                CodeGeneratorUtil.GetUnavailable <ICodeGeneratorDataProvider>(types, config.DataProviders);
            var unavailableCodeGenerators =
                CodeGeneratorUtil.GetUnavailable <ICodeGenerator>(types, config.CodeGenerators);
            var unavailablePostProcessors =
                CodeGeneratorUtil.GetUnavailable <ICodeGenFilePostProcessor>(types, config.PostProcessors);

            var availableDataProviders =
                CodeGeneratorUtil.GetAvailable <ICodeGeneratorDataProvider>(types, config.DataProviders);
            var availableCodeGenerators = CodeGeneratorUtil.GetAvailable <ICodeGenerator>(types, config.CodeGenerators);
            var availablePostProcessors =
                CodeGeneratorUtil.GetAvailable <ICodeGenFilePostProcessor>(types, config.PostProcessors);

            PrintUnavailable(unavailableDataProviders);
            PrintUnavailable(unavailableCodeGenerators);
            PrintUnavailable(unavailablePostProcessors);

            PrintAvailable(availableDataProviders);
            PrintAvailable(availableCodeGenerators);
            PrintAvailable(availablePostProcessors);
        }
Example #3
0
        static bool FixPlugins(HashSet <string> askedRemoveKeys, HashSet <string> askedAddKeys, Type[] types,
                               CodeGeneratorConfig config, Properties properties)
        {
            var changed = false;

            var unavailableDataProviders =
                CodeGeneratorUtil.GetUnavailable <ICodeGeneratorDataProvider>(types, config.DataProviders);
            var unavailableCodeGenerators =
                CodeGeneratorUtil.GetUnavailable <ICodeGenerator>(types, config.CodeGenerators);
            var unavailablePostProcessors =
                CodeGeneratorUtil.GetUnavailable <ICodeGenFilePostProcessor>(types, config.PostProcessors);

            var availableDataProviders =
                CodeGeneratorUtil.GetAvailable <ICodeGeneratorDataProvider>(types, config.DataProviders);
            var availableCodeGenerators = CodeGeneratorUtil.GetAvailable <ICodeGenerator>(types, config.CodeGenerators);
            var availablePostProcessors =
                CodeGeneratorUtil.GetAvailable <ICodeGenFilePostProcessor>(types, config.PostProcessors);

            foreach (var key in unavailableDataProviders.Where(k => !askedRemoveKeys.Contains(k)))
            {
                Helper.RemoveValue("Remove unavailable data provider", key, config.DataProviders,
                                   values => config.DataProviders = values, properties);
                askedRemoveKeys.Add(key);
                changed = true;
            }

            foreach (var key in unavailableCodeGenerators.Where(k => !askedRemoveKeys.Contains(k)))
            {
                Helper.RemoveValue("Remove unavailable code generator", key, config.CodeGenerators,
                                   values => config.CodeGenerators = values, properties);
                askedRemoveKeys.Add(key);
                changed = true;
            }

            foreach (var key in unavailablePostProcessors.Where(k => !askedRemoveKeys.Contains(k)))
            {
                Helper.RemoveValue("Remove unavailable post processor", key, config.PostProcessors,
                                   values => config.PostProcessors = values, properties);
                askedRemoveKeys.Add(key);
                changed = true;
            }

            foreach (var key in availableDataProviders.Where(k => !askedRemoveKeys.Contains(k)))
            {
                Helper.AddValue("Add available data provider", key, config.DataProviders,
                                values => config.DataProviders = values, properties);
                askedAddKeys.Add(key);
                changed = true;
            }

            foreach (var key in availableCodeGenerators.Where(k => !askedRemoveKeys.Contains(k)))
            {
                Helper.AddValue("Add available code generator", key, config.CodeGenerators,
                                values => config.CodeGenerators = values, properties);
                askedAddKeys.Add(key);
                changed = true;
            }

            foreach (var key in availablePostProcessors.Where(k => !askedRemoveKeys.Contains(k)))
            {
                Helper.AddValue("Add available post processor", key, config.PostProcessors,
                                values => config.PostProcessors = values, properties);
                askedAddKeys.Add(key);
                changed = true;
            }

            return(changed);
        }