/// <summary> /// 程序启动 /// </summary> /// <param name="e"></param> protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #region 唯一实例判断 bool isFirstSyncElement; _ = new Mutex(false, AppConst.APP_NAME, out isFirstSyncElement); if (isFirstSyncElement == false) { App.Current.Shutdown(); Environment.Exit(0); return; } else { Process SameAppProc = GetAppProcess(); if (SameAppProc != null) { // 如果找到已有的实例则前置 //Win32.SetForegroundWindow(SameAppProc.MainWindowHandle); // MessageBox.Show("程序已启动."); App.Current.Shutdown(); Environment.Exit(0); return; } } #endregion #region 如果守护进程未启动, 则以管理员启动 StartConsoleService(); //if (!IsAdministrator()) //{ // RunThisAsAdmin(); // return; //} #endregion _notifyIcon = (TaskbarIcon)FindResource("MyNotifyIcon"); //Start HttpServer HttpServer = new SimpleHttpServer(AppDomain.CurrentDomain.BaseDirectory + "\\TodoWeb", "127.0.0.1", 13554); HttpServer.Start(); SimpleMessenger.Default.Subscribe <GeneralMessage>(this, HandleGeneralMessage); SimpleMessenger.Default.Subscribe <NotifyIconViewMessage>(this, HandleSimpleCommand); // 自启动任务 SimpleMessenger.Default.Publish(new NotifyIconViewMessage() { Signal = NotifyIconViewMessage.Signals.SyncTime, Parameter = "Slient" }); //PreloadTodoWindow(); //WindowManager.Single<ToDoComment>().Show(); //todoProcess = Process.Start(AppDomain.CurrentDomain.BaseDirectory + "TodoApp\\TodoApp.exe"); //string command = "dotnet application.dll --urls=http://*:5123"; //Process proc = new System.Diagnostics.Process(); //proc.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "TodoApp\\TodoApp.exe"; ////proc.StartInfo.Arguments = AppDomain.CurrentDomain.BaseDirectory + "TodoApp\\TodoApp.dll"; //proc.StartInfo.UseShellExecute = false; //proc.StartInfo.RedirectStandardOutput = true; //proc.StartInfo.Verb = "runas"; //proc.Start(); //todoProcess = proc; _hook.KeyPressed += new EventHandler <KeyPressedEventArgs>(hook_KeyPressed); try { _hook.RegisterHotKey(ModifierKeys.Control | ModifierKeys.Alt, System.Windows.Forms.Keys.T); } catch { _notifyIcon?.ShowBalloonTip(DateTime.Now.ToShortTimeString(), "快捷键注册失败", BalloonIcon.Info); } }
static void Main() { Console.WriteLine("Starting PirBanka..."); // Initialize variables config = new PirBankaConfig(); db = new DatabaseHelper(config.DbConnectionString); app = new SimpleHttpServer(); // GET endpoints returning HTML and misc foreach (var x in Responses.Misc.Actions) { app.Get(x.Key, x.Value); } foreach (var x in Responses.GetDocs.Actions) { app.Get(x.Key, x.Value); } // endpoints foreach (var x in Responses.Get.Actions) { app.Get(x.Key, x.Value); } foreach (var x in Responses.Post.Actions) { app.Post(x.Key, x.Value); } foreach (var x in Responses.Put.Actions) { app.Put(x.Key, x.Value); } foreach (var x in Responses.Delete.Actions) { app.Delete(x.Key, x.Value); } // AUTH endpoints foreach (var x in Responses.AuthGet.Actions) { app.Get(x.Key, x.Value); } foreach (var x in Responses.AuthPost.Actions) { app.Post(x.Key, x.Value); } foreach (var x in Responses.AuthPut.Actions) { app.Put(x.Key, x.Value); } foreach (var x in Responses.AuthDelete.Actions) { app.Delete(x.Key, x.Value); } // GET endpoints with documentation foreach (var x in Responses.AdminGet.Actions) { app.Get(x.Key, x.Value); } foreach (var x in Responses.AdminPost.Actions) { app.Post(x.Key, x.Value); } foreach (var x in Responses.AdminPut.Actions) { app.Put(x.Key, x.Value); } foreach (var x in Responses.AdminDelete.Actions) { app.Delete(x.Key, x.Value); } // Start listener app.Start(config.ListenGateway, config.ListenPort); }