Exemplo n.º 1
0
        public override void Run(string[] args)
        {
            if (assertPreferences(args))
            {
                var preferences = loadPreferences(args);
                var config      = new CodeGeneratorConfig();
                config.Configure(preferences);

                var cliConfig = new CLIConfig();
                cliConfig.Configure(preferences);

                forceAddKeys(config.defaultProperties, preferences);
                forceAddKeys(cliConfig.defaultProperties, preferences);

                Type[] types = null;

                try {
                    types = CodeGeneratorUtil.LoadTypesFromPlugins(preferences);
                    getConfigurables(types, config);
                } catch (Exception ex) {
                    throw ex;
                }

                var askedRemoveKeys = new HashSet <string>();
                var askedAddKeys    = new HashSet <string>();
                while (fix(askedRemoveKeys, askedAddKeys, types, config, cliConfig, preferences))
                {
                }
            }
        }
Exemplo n.º 2
0
        protected override void run()
        {
            var config = new CodeGeneratorConfig();

            config.Configure(_preferences);

            var cliConfig = new CLIConfig();

            cliConfig.Configure(_preferences);

            forceAddKeys(config.defaultProperties, _preferences);
            forceAddKeys(cliConfig.defaultProperties, _preferences);

            Type[] types = null;

            try {
                types = CodeGeneratorUtil.LoadTypesFromPlugins(_preferences);
                // A test to check if all types can be resolved and instantiated.
                CodeGeneratorUtil.GetEnabledInstancesOf <ICodeGeneratorDataProvider>(types, config.dataProviders);
                CodeGeneratorUtil.GetEnabledInstancesOf <ICodeGenerator>(types, config.codeGenerators);
                CodeGeneratorUtil.GetEnabledInstancesOf <ICodeGenFilePostProcessor>(types, config.postProcessors);
            } catch (Exception ex) {
                throw ex;
            }

            var askedRemoveKeys = new HashSet <string>();
            var askedAddKeys    = new HashSet <string>();

            while (fix(askedRemoveKeys, askedAddKeys, types, config, cliConfig, _preferences))
            {
            }
        }
Exemplo n.º 3
0
        protected override void run()
        {
            var config = new CodeGeneratorConfig();

            config.Configure(_preferences);

            var cliConfig = new CLIConfig();

            cliConfig.Configure(_preferences);

            fabl.Debug(_preferences.ToString());

            Type[] types = null;
            Dictionary <string, string> defaultProperties = null;

            try {
                types             = CodeGeneratorUtil.LoadTypesFromPlugins(_preferences);
                defaultProperties = CodeGeneratorUtil.GetDefaultProperties(types, config);
            } catch (Exception ex) {
                printKeyStatus(config.defaultProperties.Keys.ToArray(), cliConfig, _preferences);
                throw ex;
            }

            var requiredKeys = config.defaultProperties
                               .Merge(cliConfig.defaultProperties)
                               .Merge(defaultProperties).Keys.ToArray();

            printKeyStatus(requiredKeys, cliConfig, _preferences);
            printPluginStatus(types, config);
            printCollisions(config);
        }
Exemplo n.º 4
0
        static void printKeyStatus(string[] requiredKeys, CLIConfig cliConfig, Preferences preferences)
        {
            var unusedKeys = Helper
                             .GetUnusedKeys(requiredKeys, preferences)
                             .Where(key => !cliConfig.ignoreUnusedKeys.Contains(key));

            foreach (var key in unusedKeys)
            {
                fabl.Info("Unused key: " + key);
            }

            foreach (var key in Helper.GetMissingKeys(requiredKeys, preferences))
            {
                fabl.Warn("Missing key: " + key);
            }
        }
Exemplo n.º 5
0
        public static void RemoveOrIgnoreKey(string question, string key, CLIConfig cliConfig, Preferences preferences)
        {
            fabl.Warn(question + ": '" + key + "' ? (y / n / (i)gnore)");
            var userDecision = GetComplexUserDecision();

            if (userDecision == UserDecision.Accept)
            {
                preferences.properties.RemoveProperty(key);
                preferences.Save();
                fabl.Warn("Removed: " + key);
            }
            else if (userDecision == UserDecision.Ignore)
            {
                var valueList = cliConfig.ignoreUnusedKeys.ToList();
                valueList.Add(key);
                cliConfig.ignoreUnusedKeys = valueList.ToArray();
                preferences.Save();
                fabl.Warn("Ignoring: " + key);
            }
        }
Exemplo n.º 6
0
        public override void Run(string[] args)
        {
            if (assertPreferences(args))
            {
                var preferences = loadPreferences(args);
                var config      = new CodeGeneratorConfig();
                config.Configure(preferences);

                var cliConfig = new CLIConfig();
                cliConfig.Configure(preferences);

                fabl.Debug(preferences.ToString());

                Type[] types = null;
                Dictionary <string, string> configurables = null;

                try {
                    types         = CodeGeneratorUtil.LoadTypesFromPlugins(preferences);
                    configurables = CodeGeneratorUtil.GetConfigurables(
                        CodeGeneratorUtil.GetUsed <ICodeGeneratorDataProvider>(types, config.dataProviders),
                        CodeGeneratorUtil.GetUsed <ICodeGenerator>(types, config.codeGenerators),
                        CodeGeneratorUtil.GetUsed <ICodeGenFilePostProcessor>(types, config.postProcessors)
                        );
                } catch (Exception ex) {
                    printKeyStatus(config.defaultProperties.Keys.ToArray(), cliConfig, preferences);
                    throw ex;
                }

                var requiredKeys = config.defaultProperties
                                   .Merge(cliConfig.defaultProperties)
                                   .Merge(configurables).Keys.ToArray();

                printKeyStatus(requiredKeys, cliConfig, preferences);
                printPluginStatus(types, config);
            }
        }
Exemplo n.º 7
0
        static bool fix(HashSet <string> askedRemoveKeys, HashSet <string> askedAddKeys, Type[] types, CodeGeneratorConfig config, CLIConfig cliConfig, Preferences preferences)
        {
            var changed = fixPlugins(askedRemoveKeys, askedAddKeys, types, config, preferences);

            forceAddKeys(getConfigurables(types, config), preferences);

            var requiredKeys = config.defaultProperties
                               .Merge(cliConfig.defaultProperties)
                               .Merge(getConfigurables(types, config)).Keys.ToArray();

            removeUnusedKeys(askedRemoveKeys, requiredKeys, cliConfig, preferences);

            return(changed);
        }
Exemplo n.º 8
0
        static void removeUnusedKeys(HashSet <string> askedRemoveKeys, string[] requiredKeys, CLIConfig cliConfig, Preferences preferences)
        {
            var unusedKeys = Helper
                             .GetUnusedKeys(requiredKeys, preferences)
                             .Where(key => !cliConfig.ignoreUnusedKeys.Contains(key));

            foreach (var key in unusedKeys)
            {
                if (!askedRemoveKeys.Contains(key))
                {
                    Helper.RemoveOrIgnoreKey("Remove unused key", key, cliConfig, preferences);
                    askedRemoveKeys.Add(key);
                }
            }
        }