static int HandleDefaultConfig(MConfigOptions options, Configuration config)
        {
            FeatureTarget target = options.Target;

            string[] commandArguments = options.PlainArguments;
            string   configName, targetPath;

            if (commandArguments.Length < 2)
            {
                switch (target)
                {
                case FeatureTarget.Any:
                    Console.Error.WriteLine("No default config file for target 'Any'");
                    return(1);

                case FeatureTarget.Web:
                    configName = "Web.config";
                    break;

                case FeatureTarget.Application:
                    configName = "application.exe.config";
                    break;

                default:
                    Console.Error.WriteLine("Unknown target '{0}'", target);
                    return(1);
                }
            }
            else
            {
                configName = commandArguments [1];
            }

            if (commandArguments.Length < 3)
            {
                targetPath = ".";
            }
            else
            {
                targetPath = commandArguments [2];
            }

            try
            {
                config.WriteDefaultConfigFile(configName, targetPath, target);
            }
            catch (Exception ex)
            {
                PrintException(ex, "Failed to write default config file '{0}':",
                               configName);
                return(1);
            }

            return(0);
        }
        static int Main(string[] args)
        {
            MConfigOptions options = new MConfigOptions();

            options.Parse(args);

            if (!String.IsNullOrEmpty(options.ConfigFile))
            {
                configPaths [3] = options.ConfigFile;
            }

            Configuration config = new Configuration();

            try
            {
                config.Load(configPaths);
            }
            catch (Exception ex)
            {
                PrintException(ex, "Failed to load configuration files:");
                return(1);
            }

            string[] commandArguments = options.PlainArguments;
            if (commandArguments == null || commandArguments.Length == 0)
            {
                options.UsageCommands();
                DisplayList("Default config files:", config.DefaultConfigFiles);
                Console.WriteLine();
                DisplayList("Available features:", config.Features);
                return(1);
            }

            HandleCommand commandHandler = FindCommandHandler(commandArguments [0]);

            if (commandHandler == null)
            {
                Console.Error.WriteLine("Unknown command '{0}'", commandArguments [0]);
                return(1);
            }

            IDefaultConfigFileContainer[] containers = config.GetHandlersForInterface <IDefaultConfigFileContainer> ();
            if (containers != null && containers.Length > 0)
            {
                foreach (IDefaultConfigFileContainer c in containers)
                {
                    c.OverwriteFile += new OverwriteFileEventHandler(OnOverwriteFile);
                }
            }

            return(commandHandler(options, config));
        }
        static int HandleAddFeature(MConfigOptions options, Configuration config)
        {
            string[] commandArguments = options.PlainArguments;
            if (commandArguments.Length < 2)
            {
                Console.Error.WriteLine("Command requires at least one argument.");
                return(1);
            }

            FeatureTarget target = options.Target;
            string        featureName = commandArguments [1], configPath;

            if (commandArguments.Length > 2)
            {
                configPath = commandArguments [2];
            }
            else
            {
                switch (target)
                {
                case FeatureTarget.Any:
                    Console.Error.WriteLine("No default config file for target 'Any'");
                    return(1);

                case FeatureTarget.Web:
                    configPath = "Web.config";
                    break;

                case FeatureTarget.Application:
                    configPath = "application.exe.config";
                    break;

                default:
                    Console.Error.WriteLine("Unknown target '{0}'", target);
                    return(1);
                }
            }

            try
            {
                config.AddFeature(configPath, target, featureName);
            }
            catch (Exception ex)
            {
                PrintException(ex, "Failed to add feature '{0}' to config file '{1}'.",
                               featureName, configPath);
                return(1);
            }

            return(0);
        }
Beispiel #4
0
		static int HandleDefaultConfig (MConfigOptions options, Configuration config)
		{
			FeatureTarget target = options.Target;
			string[] commandArguments = options.PlainArguments;
			string configName, targetPath;

			if (commandArguments.Length < 2) {
				switch (target) {
					case FeatureTarget.Any:
						Console.Error.WriteLine ("No default config file for target 'Any'");
						return 1;
						
					case FeatureTarget.Web:
						configName = "Web.config";
						break;
						
					case FeatureTarget.Application:
						configName = "application.exe.config";
						break;

					default:
						Console.Error.WriteLine ("Unknown target '{0}'", target);
						return 1;
				}
			} else
				configName = commandArguments [1];

			if (commandArguments.Length < 3)
				targetPath = ".";
			else
				targetPath = commandArguments [2];

			try {
				config.WriteDefaultConfigFile (configName, targetPath, target);
			} catch (Exception ex) {
				PrintException (ex, "Failed to write default config file '{0}':",
						configName);
				return 1;
			}			

			return 0;
		}
Beispiel #5
0
		static int HandleAddFeature (MConfigOptions options, Configuration config)
		{
			string[] commandArguments = options.PlainArguments;
			if (commandArguments.Length < 2) {
				Console.Error.WriteLine ("Command requires at least one argument.");
				return 1;
			}
			
			FeatureTarget target = options.Target;
			string featureName = commandArguments [1], configPath;
			if (commandArguments.Length > 2)
				configPath = commandArguments [2];
			else {
				switch (target) {
					case FeatureTarget.Any:
						Console.Error.WriteLine ("No default config file for target 'Any'");
						return 1;
						
					case FeatureTarget.Web:
						configPath = "Web.config";
						break;
						
					case FeatureTarget.Application:
						configPath = "application.exe.config";
						break;

					default:
						Console.Error.WriteLine ("Unknown target '{0}'", target);
						return 1;
				}
			}
			
			try {
				config.AddFeature (configPath, target, featureName);
			} catch (Exception ex) {
				PrintException (ex, "Failed to add feature '{0}' to config file '{1}'.",
						featureName, configPath);
				return 1;
			}
			
			return 0;
		}
Beispiel #6
0
		static int Main (string[] args)
		{
			MConfigOptions options = new MConfigOptions ();
			options.Parse (args);
			
			if (!String.IsNullOrEmpty (options.ConfigFile))
				configPaths [3] = options.ConfigFile;
			
			Configuration config = new Configuration ();
			try {
				config.Load (configPaths);
			} catch (Exception ex) {
				PrintException (ex, "Failed to load configuration files:");
				return 1;
			}
			
			string[] commandArguments = options.PlainArguments;
			if (commandArguments == null || commandArguments.Length == 0) {
				options.UsageCommands ();
				DisplayList ("Default config files:", config.DefaultConfigFiles);
				Console.WriteLine ();
				DisplayList ("Available features:", config.Features);
				return 1;
			}
			
			HandleCommand commandHandler = FindCommandHandler (commandArguments [0]);
			if (commandHandler == null) {
				Console.Error.WriteLine ("Unknown command '{0}'", commandArguments [0]);
				return 1;
			}

			IDefaultConfigFileContainer[] containers = config.GetHandlersForInterface <IDefaultConfigFileContainer> ();
			if (containers != null && containers.Length > 0)
				foreach (IDefaultConfigFileContainer c in containers)
					c.OverwriteFile += new OverwriteFileEventHandler (OnOverwriteFile);
			
			return commandHandler (options, config);
		}