Load() публичный статический Метод

Loads CS-Script application settings from a file. Default settings object is returned if it cannot be loaded from the file.
public static Load ( string fileName ) : Settings
fileName string File name of the XML file
Результат Settings
Пример #1
0
        public void ProcessConfigCommand(string command)
        {
            //-config                  - lists/print current settings value
            //-config:raw              - print current config file content
            //-config:ls               - lists/print current settings value (same as simple -config)
            //-config:create           - create config file with default settings
            //-config:default          - print default settings
            //-config:get:name         - print current config file value
            //-config:set:name=value   - set current config file value
            try
            {
                if (command == "create")
                {
                    CreateDefaultConfigFile();
                }
                else if (command == "default")
                {
                    print(new Settings().ToStringRaw());
                }
                else if (command == "ls" || command == null)
                {
                    print(Settings.Load(false).ToString());
                }
                else if (command == "raw" || command == "xml")
                {
                    var currentConfig = Settings.Load(false) ?? new Settings();
                    print(currentConfig.ToStringRaw());
                }
                else if (command.StartsWith("get:"))
                {
                    string name          = command.Substring(4);
                    var    currentConfig = Settings.Load(false) ?? new Settings();
                    var    value         = currentConfig.Get(ref name);
                    print(name + ": " + value);
                }
                else if (command.StartsWith("set:"))
                {
                    // set:DefaultArguments=-ac
                    string name, value;

                    string[] tokens = command.Substring(4).Split(new char[] { '=', ':' }, 2);
                    if (tokens.Length != 2)
                    {
                        throw new CLIException("Invalid set config property expression. Must be in name 'set:<name>=<value>' format.");
                    }

                    name  = tokens[0];
                    value = tokens[1].Trim().Trim('"');

                    var currentConfig = Settings.Load(true) ?? new Settings();
                    currentConfig.Set(name, value);
                    currentConfig.Save();

                    var new_value = currentConfig.Get(ref name);
                    print("set: " + name + ": " + new_value);
                }
            }
            catch (Exception e)
            {
                throw new CLIException(e.Message); //only a message, stack info for CLI is too verbose
            }
            throw new CLIExitRequest();
        }
Пример #2
0
        public void ProcessConfigCommand(string command)
        {
            //-config                  - lists/print current settings value
            //-config:raw              - print current config file content
            //-config:ls               - lists/print current settings value (same as simple -config)
            //-config:create           - create config file with default settings
            //-config:default          - print default settings
            //-config:get:name         - print current config file value
            //-config:set:name=value   - set current config file value
            try
            {
                if (command == "create")
                {
                    CreateDefaultConfigFile();
                }
                else if (command == "default")
                {
                    print(new Settings().ToStringRaw());
                }
                else if (command == "ls" || command == null)
                {
                    print(Settings.Load(false).ToString());
                }
                else if (command == "raw" || command == "xml")
                {
                    var currentConfig = Settings.Load(false) ?? new Settings();
                    print(currentConfig.ToStringRaw());
                }
                else if (command.StartsWith("get:"))
                {
                    string name          = command.Substring(4);
                    var    currentConfig = Settings.Load(false) ?? new Settings();
                    var    value         = currentConfig.Get(ref name);
                    print(name + ": " + value);
                }
                else if (command.StartsWith("set:"))
                {
                    // set:DefaultArguments=-ac
                    // set:roslyn
                    string name, value;

                    if (command.SameAs("set:roslyn"))
                    {
                        var asmDir = Assembly.GetExecutingAssembly().GetAssemblyDirectoryName();

                        var providerFile = ExistingFile(asmDir, "CSSRoslynProvider.dll") ??
                                           ExistingFile(asmDir, "Lib", "CSSRoslynProvider.dll");

                        if (providerFile != null)
                        {
                            name  = "UseAlternativeCompiler";
                            value = providerFile;
                        }
                        else
                        {
                            throw new CLIException("Cannot locate Roslyn provider CSSRoslynProvider.dll");
                        }
                    }
                    else
                    {
                        string[] tokens = command.Substring(4).Split(new char[] { '=', ':' }, 2);
                        if (tokens.Length != 2)
                        {
                            throw new CLIException("Invalid set config property expression. Must be in name 'set:<name>=<value>' format.");
                        }

                        name  = tokens[0];
                        value = tokens[1].Trim().Trim('"');
                    }

                    var currentConfig = Settings.Load(true) ?? new Settings();
                    currentConfig.Set(name, value);
                    currentConfig.Save();

                    var new_value = currentConfig.Get(ref name);
                    print("set: " + name + ": " + new_value);
                }
            }
            catch (Exception e)
            {
                throw new CLIException(e.Message); //only a message, stack info for CLI is too verbose
            }
            throw new CLIExitRequest();
        }