Beispiel #1
0
        /// <summary>
        /// This is the main entry point for the SHRD host service.
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;

            Globals.InitializeProgram(exePath, "Self Hosted Remote Desktop", true);
            PrivateAccessor.SetStaticFieldValue(typeof(Globals), "errorFilePath", Globals.WritableDirectoryBase + "SHRD_Log.txt");

            FileInfo fiExe = new FileInfo(exePath);

            Environment.CurrentDirectory = fiExe.Directory.FullName;

            System.Windows.Forms.Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomain_UnhandledException;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //byte[] buf = new byte[4];
            //ByteUtil.WriteFloat(5, buf, 0);
            //float f = ByteUtil.ReadFloat(buf, 0);
            //Logger.Info(f.ToString());

            if (Environment.UserInteractive)
            {
                bool cmd = args.Length > 0 && args[0] == "cmd";
                if (cmd || Debugger.IsAttached)
                {
                    ConsoleAppHelper.AllocateConsole();
                    Logger.logType = LoggingMode.Console | LoggingMode.File;
                    Logger.Info("Console environment detected. Logging to console is enabled.");
                    ServiceWrapper.Initialize();
                    ServiceWrapper.Start();
                    do
                    {
                        Console.WriteLine("Type \"exit\" to close");
                    }while (Console.ReadLine().ToLower() != "exit");
                    ServiceWrapper.Stop();
                    return;
                }
                else
                {
                    Logger.logType = LoggingMode.File;
                }

                string             Title           = "SelfHostedRemoteDesktop " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " Service Manager";
                string             ServiceName     = "SelfHostedRemoteDesktop";
                ButtonDefinition   btnStartCmdTest = new ButtonDefinition("Test w/console", btnStartCmdTest_Click);
                ButtonDefinition[] customButtons   = new ButtonDefinition[] { btnStartCmdTest };

                System.Windows.Forms.Application.Run(new ServiceManager(Title, ServiceName, customButtons));
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new SelfHostedRemoteDesktopSvc()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
Beispiel #2
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main()
 {
     if (Environment.UserInteractive)
     {
         ConsoleAppHelper.AllocateConsole();
         Console.WriteLine("Master Server - Self Hosted Remote Desktop");
         Console.WriteLine("User-interactive environment detected.  Running as a console application.");
         try
         {
             ServiceWrapper.Initialize();
             ServiceWrapper.Start();
             Console.WriteLine("Type \"exit\" to close or \"web\" to open local web server.");
             string line;
             do
             {
                 line = Console.ReadLine().ToLower();
                 if (line == "web")
                 {
                     Console.WriteLine("Launching http://127.0.0.1:8088/login");
                     Process.Start("http://127.0.0.1:8088/login");
                 }
                 else if (line == "dev")
                 {
                     ServiceWrapper.settings.devMode = !ServiceWrapper.settings.devMode;
                     ServiceWrapper.settings.Save();
                     Console.WriteLine("Dev mode: " + ServiceWrapper.settings.devMode);
                 }
             }while (line != "exit");
             Console.WriteLine("Stopping...");
         }
         finally
         {
             ServiceWrapper.Stop();
         }
     }
     else
     {
         ServiceBase[] ServicesToRun;
         ServicesToRun = new ServiceBase[]
         {
             new MasterServerSvc()
         };
         ServiceBase.Run(ServicesToRun);
     }
 }