Пример #1
0
        static void fixPlugins(Type[] types, CodeGeneratorConfig config, Properties properties)
        {
            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 dataProvider in unavailableDataProviders)
            {
                Helper.RemoveValue("Remove unavailable data provider", dataProvider, config.dataProviders,
                                   values => config.dataProviders = values, properties);
            }

            foreach (var codeGenerator in unavailableCodeGenerators)
            {
                Helper.RemoveValue("Remove unavailable code generator", codeGenerator, config.codeGenerators,
                                   values => config.codeGenerators = values, properties);
            }

            foreach (var postProcessor in unavailablePostProcessors)
            {
                Helper.RemoveValue("Remove unavailable post processor", postProcessor, config.postProcessors,
                                   values => config.postProcessors = values, properties);
            }

            foreach (var dataProvider in availableDataProviders)
            {
                Helper.AddValue("Add available data provider", dataProvider, config.dataProviders,
                                values => config.dataProviders = values, properties);
            }

            foreach (var codeGenerator in availableCodeGenerators)
            {
                Helper.AddValue("Add available code generator", codeGenerator, config.codeGenerators,
                                values => config.codeGenerators = values, properties);
            }

            foreach (var postProcessor in availablePostProcessors)
            {
                Helper.AddValue("Add available post processor", postProcessor, config.postProcessors,
                                values => config.postProcessors = values, properties);
            }
        }
Пример #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);
        }
Пример #3
0
        static bool fixPlugins(HashSet <string> askedRemoveKeys, HashSet <string> askedAddKeys, Type[] types, CodeGeneratorConfig config, Preferences preferences)
        {
            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)
            {
                if (!askedRemoveKeys.Contains(key))
                {
                    Helper.RemoveValue("Remove unavailable data provider", key, config.dataProviders,
                                       values => config.dataProviders = values, preferences);
                    askedRemoveKeys.Add(key);
                    changed = true;
                }
            }

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

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

            foreach (var key in availableDataProviders)
            {
                if (!askedAddKeys.Contains(key))
                {
                    Helper.AddValue("Add available data provider", key, config.dataProviders,
                                    values => config.dataProviders = values, preferences);
                    askedAddKeys.Add(key);
                    changed = true;
                }
            }

            foreach (var key in availableCodeGenerators)
            {
                if (!askedAddKeys.Contains(key))
                {
                    Helper.AddValue("Add available code generator", key, config.codeGenerators,
                                    values => config.codeGenerators = values, preferences);
                    askedAddKeys.Add(key);
                    changed = true;
                }
            }

            foreach (var key in availablePostProcessors)
            {
                if (!askedAddKeys.Contains(key))
                {
                    Helper.AddValue("Add available post processor", key, config.postProcessors,
                                    values => config.postProcessors = values, preferences);
                    askedAddKeys.Add(key);
                    changed = true;
                }
            }

            return(changed);
        }
Пример #4
0
        static void status()
        {
            if (File.Exists(Preferences.configPath))
            {
                var fileContent = File.ReadAllText(Preferences.configPath);
                var properties  = new Properties(fileContent);
                var config      = new CodeGeneratorConfig(new Config(fileContent));

                _logger.Debug(config.ToString());

                Type[]   types            = null;
                string[] configurableKeys = null;

                try {
                    types            = CodeGeneratorUtil.LoadTypesFromCodeGeneratorAssemblies();
                    configurableKeys = getConfigurableKeys(
                        CodeGeneratorUtil.GetUsed <ICodeGeneratorDataProvider>(types, config.dataProviders),
                        CodeGeneratorUtil.GetUsed <ICodeGenerator>(types, config.codeGenerators),
                        CodeGeneratorUtil.GetUsed <ICodeGenFilePostProcessor>(types, config.postProcessors)
                        );
                } catch (Exception ex) {
                    foreach (var key in getUnusedKeys(properties))
                    {
                        _logger.Info("Unused key: " + key);
                    }

                    foreach (var key in getMissingKeys(properties))
                    {
                        _logger.Warn("Missing key: " + key);
                    }

                    throw ex;
                }

                foreach (var key in getUnusedKeys(properties).Where(key => !configurableKeys.Contains(key)))
                {
                    _logger.Info("Unused key: " + key);
                }

                foreach (var key in getMissingKeys(properties))
                {
                    _logger.Warn("Missing key: " + key);
                }

                foreach (var key in configurableKeys.Where(key => !properties.HasKey(key)))
                {
                    _logger.Warn("Missing key: " + key);
                }

                printUnavailable(CodeGeneratorUtil.GetUnavailable <ICodeGeneratorDataProvider>(types, config.dataProviders));
                printUnavailable(CodeGeneratorUtil.GetUnavailable <ICodeGenerator>(types, config.codeGenerators));
                printUnavailable(CodeGeneratorUtil.GetUnavailable <ICodeGenFilePostProcessor>(types, config.postProcessors));

                printAvailable(CodeGeneratorUtil.GetAvailable <ICodeGeneratorDataProvider>(types, config.dataProviders));
                printAvailable(CodeGeneratorUtil.GetAvailable <ICodeGenerator>(types, config.codeGenerators));
                printAvailable(CodeGeneratorUtil.GetAvailable <ICodeGenFilePostProcessor>(types, config.postProcessors));
            }
            else
            {
                printNoConfig();
            }
        }