Example #1
0
        /// <summary>
        /// Processes all arguments.
        /// </summary>
        public bool ProcessArgs(String[] args)
        {
            int length = argvSource.GetArguments().Length;

            if (argvSource.Configs[configName].Get("help") != null)
            {
                PrintUsage();
                return(false);
            }

            configPath = ConfigFilePath();

            string configFile = argvSource.Configs[configName].Get("config", "SxtaConfig.xml");
            bool   showDialog = bool.Parse(argvSource.Configs[configName].Get("dialog", "true"));

            Configurator config = new Configurator(configFile, showDialog);

            source = config.ConfigurationSource;

            // We set reconf in advance, just in case something screws up, in
            // which case we want the configurator to show-up by default.
            //config.SetReconf();

            // Clear the reconf flag since things seem to be working.
            //config.ClearReconf();

            string logFile = argvSource.Configs[configName].Get("log");

            if (!string.IsNullOrEmpty(logFile) && File.Exists(logFile))
            {
                // Log4Net is configured using a DOMConfigurator.
                log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(logFile));
            }
            else
            {
                System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();

                string tmp          = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace;
                Stream configStream = asm.GetManifestResourceStream(tmp + "." + "SxtaLog4NetConfig.xml");
                if (configStream == null)
                {
                    // Set up a simple configuration that logs on the console.
                    log4net.Config.BasicConfigurator.Configure();
                }
                else
                {
                    log4net.Config.XmlConfigurator.Configure(configStream);
                }
            }

            return(true);
        }
Example #2
0
        public void GetArguments()
        {
            string[] arguments = new string[] { "--help", "-d", "doc.xml",
                                                "/pet:cat" };
            ArgvConfigSource source = new ArgvConfigSource(arguments);

            source.AddSwitch("Base", "help", "h");
            source.AddSwitch("Base", "doc", "d");
            source.AddSwitch("Base", "short");

            string[] args = source.GetArguments();
            Assert.IsTrue(args != arguments);              // must be a different instance
            Assert.AreEqual(4, args.Length);
            Assert.AreEqual("--help", args[0]);
            Assert.AreEqual("-d", args[1]);
            Assert.AreEqual("doc.xml", args[2]);
            Assert.AreEqual("/pet:cat", args[3]);
        }
Example #3
0
File: Editor.cs Project: psla/nini
        /// <summary>
        /// Processes all arguments.
        /// </summary>
        public void ProcessArgs()
        {
            if (argvSource.GetArguments().Length < 1 ||
                IsArg("help"))
            {
                PrintUsage();
                return;
            }

            verbose = IsArg("verbose");

            if (IsArg("version"))
            {
                PrintVersion();
                return;
            }

            configPath = ConfigFilePath();
            if (IsArg("new"))
            {
                try {
                    CreateNewFile();
                }
                catch (Exception ex) {
                    ThrowError("Could not create file: " + ex.Message);
                }
            }

            if (!File.Exists(configPath))
            {
                ThrowError("Config file does not exist");
            }

            if (IsArg("list"))
            {
                ListConfigs();
            }
            if (IsArg("add"))
            {
                AddConfig();
            }
            if (IsArg("remove"))
            {
                RemoveConfig();
            }
            if (IsArg("list-keys"))
            {
                ListKeys();
            }
            if (IsArg("set-key"))
            {
                SetKey();
            }
            if (IsArg("remove-key"))
            {
                RemoveKey();
            }
            if (IsArg("get-key"))
            {
                GetKey();
            }
        }