示例#1
0
        private void WriteConfig()
        {
            foreach (var c in this._configFile)
            {
                var root = AppPath.GetRoot();
                var path = Path.Join(root, c.Key);

                // Ensure that the root directory maintains the correct permissions
                ChmodRecursive(root, P0777, P0666);

                // Create directories as needed
                Directory.CreateDirectory(
                    Path.GetDirectoryName(path));

                // Write the file and set its permissions
                File.WriteAllText(path, c.Value);
                ChmodRecursive(root, P0777, P0666);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            var versionFile = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "VERSION");

            Globals.Config.Version = File.ReadAllText(versionFile);

            var version = "OmegaGraf Version: v" + Globals.Config.Version;

            logger.Info("Starting up! " + version);
            Console.WriteLine(Figgle.FiggleFonts.Standard.Render("OmegaGraf"));

            try
            {
                var parsed = Args.Parse <MyArgs>(args);

                if (parsed.Verbose)
                {
                    Log.SetLogLevel(LogLevel.Info);
                }

                if (parsed.Help)
                {
                    ArgUsage.GenerateUsageFromTemplate <MyArgs>().Write();
                    Environment.Exit(0);
                }

                if (parsed.Version)
                {
                    Console.WriteLine(version);
                    Environment.Exit(0);
                }

                if (!string.IsNullOrWhiteSpace(parsed.Socket))
                {
                    Docker.SetDockerURI(parsed.Socket);
                }

                if (parsed.Reset)
                {
                    new Docker().RemoveAllContainers().Wait();
                }

                if (parsed.Overwrite)
                {
                    Globals.Config.Overwrite = true;
                }

                if (parsed.Dev)
                {
                    Globals.Config.Development = true;
                }

                AppPath.SetRoot(parsed.Path);
                logger.Info("Root: " + AppPath.GetRoot());

                if (string.IsNullOrWhiteSpace(parsed.Key))
                {
                    var key = KeyDatabase.CreateKey();
                    Console.WriteLine("Your secure code: " + key);
                }
                else
                {
                    KeyDatabase.CreateKey(parsed.Key);
                }

                var urls =
                    parsed.Host.Length == 0 ? new string[] { "http://0.0.0.0:5000" }
                                            : parsed.Host;

                var host = new WebHostBuilder()
                           .UseKestrel()
                           .UseUrls(urls)
                           .UseStartup <Startup>()
                           .Build();

                host.Run();
            }
            catch (ArgException ex)
            {
                Console.WriteLine(ex.Message);
                ArgUsage.GenerateUsageFromTemplate <MyArgs>().Write();
            }
        }