示例#1
0
        static void Main(string[] args)
        {
            System.Threading.Thread.Sleep(1000 * StartupWaitSeconds);
            // Don't mess with ProjectsDirectory if we need to reauth
            if (args.Length == 0)
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                try
                {
                    if (PluginConfig.usefreerdp)
                    {
                        using (var rdp = new FreeRDP.Core.RDP())
                        {
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed initilizing FreeRDP, is Visual C++ Runtime installed ?");
                    // Console.WriteLine("https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads");
                    Console.WriteLine("https://www.microsoft.com/en-us/download/details.aspx?id=40784");
                    return;
                }
            }
            var parentProcess = NativeMethods.GetParentProcessId();

            isService = (parentProcess.ProcessName.ToLower() == "services");
            if (args.Length == 0)
            {
                // System.Threading.Thread.Sleep(1000 * StartupWaitSeconds);
                if (!manager.IsServiceInstalled)
                {
                    //Console.Write("Username (" + NativeMethods.GetProcessUserName() + "): ");
                    //var username = Console.ReadLine();
                    //if (string.IsNullOrEmpty(username)) username = NativeMethods.GetProcessUserName();
                    //Console.Write("Password: "******"";
                    //do
                    //{
                    //    ConsoleKeyInfo key = Console.ReadKey(true);
                    //    if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
                    //    {
                    //        pass += key.KeyChar;
                    //        Console.Write("*");
                    //    }
                    //    else
                    //    {
                    //        if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
                    //        {
                    //            pass = pass.Substring(0, (pass.Length - 1));
                    //            Console.Write("\b \b");
                    //        }
                    //        else if (key.Key == ConsoleKey.Enter)
                    //        {
                    //            break;
                    //        }
                    //    }
                    //} while (true);
                    //manager.InstallService(typeof(Program), new string[] { "username="******"password="******"****** BEGIN");
            if (args.Length > 0)
            {
                if (args[0].ToLower() == "auth" || args[0].ToLower() == "reauth")
                {
                    if (Config.local.jwt != null && Config.local.jwt.Length > 0)
                    {
                        Log.Information("Saving temporart jwt token, from local settings.json");
                        PluginConfig.tempjwt = new System.Net.NetworkCredential(string.Empty, Config.local.UnprotectString(Config.local.jwt)).Password;
                        PluginConfig.wsurl   = Config.local.wsurl;

                        PluginConfig.Save();
                        Config.Save();
                        Console.WriteLine("local  count: " + Config.local.properties.Count);
                        Console.WriteLine("Plugin count: " + PluginConfig.globallocal.properties.Count);
                    }
                    return;
                }
                else if (args[0].ToLower() == "uninstall" || args[0].ToLower() == "u")
                {
                    if (manager.IsServiceInstalled)
                    {
                        manager.UninstallService(typeof(Program));
                    }
                    return;
                }
                else
                {
                    Console.WriteLine("unknown command " + args[0]);
                    Console.WriteLine("try uninstall or reauth ");
                }
                return;
            }
            Console.WriteLine("****** isService: " + isService);
            if (isService)
            {
                System.ServiceProcess.ServiceBase.Run(new MyServiceBase(ServiceName, DoWork));
            }
            else
            {
                DoWork();
            }
        }