Beispiel #1
0
        static void Main(string[] args)
        {
            var location  = Assembly.GetEntryAssembly().Location;
            var directory = Path.GetDirectoryName(location);

            try
            {
                //using (StreamWriter debugLogFile = new StreamWriter($"{directory}/Server_Debug.log"))
                {
                    PATH_TO_WATCH = GetArgsValue <string>(args, "--project-path", "").Trim();
                    var portArg        = GetArgsValue <string>(args, "--port", "9759").Trim();
                    var configFilePath = GetArgsValue <string>(args, "--config-path", "").Trim();

                    if (string.IsNullOrEmpty(PATH_TO_WATCH))
                    {
                        Console.WriteLine("Xam.Plugin.LiveSync.Server:");
                        Console.WriteLine("The argument --project-path is required. Set it to the root location where your XAML files are.");
                        Console.ReadKey();
                        return;
                    }

                    //debugLogFile.WriteLine($"{DateTime.Now}: --project-path {PATH_TO_WATCH}");
                    //debugLogFile.WriteLine($"{DateTime.Now}: --config-path {configFilePath}");

                    if (string.IsNullOrEmpty(configFilePath))
                    {
                        HOST = $"{GetIPAddress()}:{portArg}";
                    }
                    else
                    {
                        var hostText = FileHelper.GetFileContent(configFilePath);
                        HOST = hostText;
                    }

                    var hostPort = HOST.Split(":").LastOrDefault();
                    int.TryParse(hostPort, out PORT);

                    //debugLogFile.WriteLine($"{DateTime.Now}: host {HOST}");

                    Console.WriteLine($"Xam.Plugin.LiveSync.Server connected at: {HOST} watching the directory: {PATH_TO_WATCH}");

                    var host = new WebHostBuilder()
                               .UseUrls($"http://*:{PORT}")
                               .UseKestrel()
                               .UseStartup <Startup>()
                               .Build();

                    host.Run();
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter writetext = new StreamWriter($"{directory}/ServerException_{DateTime.Now}.log"))
                {
                    writetext.WriteLine(ex.Message);
                    writetext.WriteLine(ex.StackTrace);

                    if (ex.InnerException != null)
                    {
                        writetext.WriteLine(ex.InnerException.Message);
                        writetext.WriteLine(ex.InnerException.StackTrace);
                    }
                }
            }
        }