Пример #1
0
        /// <summary>
        /// initializes from a Config.js file specified by the path
        /// </summary>
        public static void Initialize(string path = @"config.js")
        {
            string fpOld    = Path.Combine(Environment.CurrentDirectory, path);
            string fpNew    = Path.Combine(Environment.CurrentDirectory, Path.GetFileNameWithoutExtension(path) + ".js");
            string fpChoice = null;

            try
            {
                if (!File.Exists(fpNew) && File.Exists(fpOld))
                {
                    File.Move(fpOld, fpNew);
                    fpChoice = fpNew;
                }
                else if (File.Exists(fpNew))
                {
                    fpChoice = fpNew;
                }
                else
                {
                    Console.WriteLine("Configuration file is missing.  Please copy the file Config.js.example to Config.js and edit it to match your needs before running ACE.");
                    throw new Exception("missing configuration file");
                }
                Config = JsonConvert.DeserializeObject <MasterConfiguration>(new JsMinifier().Minify(File.ReadAllText(fpChoice)));
            }
            catch (Exception exception)
            {
                Console.WriteLine("An exception occured while loading the configuration file!");
                Console.WriteLine($"Exception: {exception.Message}");

                // environment.exit swallows this exception for testing purposes.  we want to expose it.
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// initializes from a Config.js file specified by the path
        /// </summary>
        public static void Initialize(string path = @"Config.js")
        {
            var directoryName = Path.GetDirectoryName(path);
            var fileName      = Path.GetFileName(path) ?? "Config.js";

            string pathToUse;

            // If no directory was specified, try both the current directory and the startup directory
            if (string.IsNullOrWhiteSpace(directoryName))
            {
                directoryName = Environment.CurrentDirectory;

                pathToUse = Path.Combine(directoryName, fileName);

                if (!File.Exists(pathToUse))
                {
                    // File not found in Environment.CurrentDirectory
                    // Lets try the ExecutingAssembly Location
                    var executingAssemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;

                    directoryName = Path.GetDirectoryName(executingAssemblyLocation);

                    if (directoryName != null)
                    {
                        pathToUse = Path.Combine(directoryName, fileName);
                    }
                }
            }
            else
            {
                pathToUse = path;
            }

            try
            {
                if (!File.Exists(pathToUse))
                {
                    Console.WriteLine("Configuration file is missing.  Please copy the file Config.js.example to Config.js and edit it to match your needs before running ACE.");
                    throw new Exception("missing configuration file");
                }

                var fileText = File.ReadAllText(pathToUse);

                Config = JsonConvert.DeserializeObject <MasterConfiguration>(new JsMinifier().Minify(fileText));
            }
            catch (Exception exception)
            {
                Console.WriteLine("An exception occured while loading the configuration file!");
                Console.WriteLine($"Exception: {exception.Message}");

                // environment.exit swallows this exception for testing purposes.  we want to expose it.
                throw;
            }
        }
Пример #3
0
        /// <summary>
        /// initializes from a config.json file specified by the path
        /// </summary>
        public static void Initialize(string path = @"Config.json")
        {
            try
            {
                Config = JsonConvert.DeserializeObject <MasterConfiguration>(File.ReadAllText(path));
            }
            catch (Exception exception)
            {
                Console.WriteLine("An exception occured while loading the configuration file!");
                Console.WriteLine($"Exception: {exception.Message}");

                // environment.exit swallows this exception for testing purposes.  we want to expose it.
                throw;
            }
        }
Пример #4
0
        /// <summary>
        /// initializes from a Config.js file specified by the path
        /// </summary>
        public static void Initialize(string filename = @"Config.js")
        {
            var path = Path.GetDirectoryName(filename);

            if (string.IsNullOrWhiteSpace(path))
            {
                path = Environment.CurrentDirectory;
            }

            string fpOld    = Path.Combine(path, Path.GetFileNameWithoutExtension(filename) + ".json");
            string fpNew    = Path.Combine(path, Path.GetFileNameWithoutExtension(filename) + ".js");
            string fpChoice = null;

            try
            {
                if (!File.Exists(fpNew) && File.Exists(fpOld))
                {
                    File.Move(fpOld, fpNew);
                    fpChoice = fpNew;
                }
                else if (File.Exists(fpNew))
                {
                    fpChoice = fpNew;
                }
                else
                {
                    Console.WriteLine("Configuration file is missing.  Will use default settings for host and port. If you wish to change these settings, pleae copy the file Config.js.example to Config.js and edit it to match your needs");
                    Config = new MasterConfiguration("0.0.0.0", 9000);
                }

                // Config is not null if we've already created it with our default settings due to a missing config file
                if (Config == null)
                {
                    Config = JsonConvert.DeserializeObject <MasterConfiguration>(new JsMinifier().Minify(File.ReadAllText(fpChoice)));
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("An exception occured while loading the configuration file!");
                Console.WriteLine($"Exception: {exception.Message}");

                // environment.exit swallows this exception for testing purposes.  we want to expose it.
                throw;
            }
        }
Пример #5
0
 /// <summary>
 /// initializes from a preloaded configuration
 /// </summary>
 public static void Initialize(MasterConfiguration configuration)
 {
     Config = configuration;
 }