Exemplo n.º 1
0
        /// <summary>
        /// Process server commands.  Returns TRUE if the application should exit.
        /// </summary>
        async Task <bool> ProcessServerCommands()
        {
            if (Program.ParamControlPipe == "")
            {
                return(false);
            }

            try
            {
                Log.Write("Starting pipe...");
                mProcessManager = new ProcessManager(Program.ParamControlPipe, false);
                Log.Write("Pipe connected");
                await mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CONNECTED);

                while (!mExiting)
                {
                    var command = await mProcessManager.ReadCommandAsync();

                    if (command.StartsWith(ProcessManager.COMMAND_CLOSE))
                    {
                        await mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CLOSING + "@reason=Closed by service");

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("ProcessServerCommands", ex);
            }
            return(false);
        }
Exemplo n.º 2
0
 private void FormDesktopWatcher_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         // Try sending the message, even though the pipe could
         // be closed, transmitting, or not even open yet
         mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CLOSING + "@reason=" + e.CloseReason).Wait(100);
         mProcessManager.Close();
     }
     catch { }
 }
Exemplo n.º 3
0
        async Task ProcessServerCommands()
        {
            try
            {
                mProcessManager = new ProcessManager(Program.ParamControlPipe, false);
                await mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CONNECTED);

                var commandTask = mProcessManager.ReadCommandAsync();

                // Poll for desktop change every POLL_FOR_DESKTOP_CHANGE_MS milliseconds,
                // and close application when COMMAND_CLOSE is received
                while (true)
                {
                    var desktop = Wts.GetDesktopName();
                    if (desktop != mDesktop)
                    {
                        await mProcessManager.SendCommandAsync(desktop);
                    }
                    mDesktop = desktop;

                    if (commandTask.IsCompleted)
                    {
                        var command = commandTask.Result;
                        commandTask = mProcessManager.ReadCommandAsync();
                        if (command.StartsWith(ProcessManager.COMMAND_CLOSE))
                        {
                            await mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CLOSING + "@reason=Closed by service");

                            break;
                        }
                    }
                    commandTask.Wait(POLL_FOR_DESKTOP_CHANGE_MS);
                }
            }
            catch (Exception ex)
            {
                try { mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CLOSING + "@reason=Exception: " + ex.Message + ", Stack: " + ex.StackTrace.Replace("\n", "").Replace("\r", "")).Wait(100); }
                catch { }
            }
        }
Exemplo n.º 4
0
        void ApplicationExit(string reason)
        {
            if (mExiting)
            {
                return;
            }
            mExiting = true;
            try { mHttpServer.Stop(); } catch { }
            try { mBeacon.Stop(); } catch { }

            // Try sending the message, even though the pipe could
            // be closed, transmitting, or not even open yet
            try { mProcessManager.SendCommandAsync(ProcessManager.COMMAND_CLOSING + reason).Wait(100); } catch { }
            try { mProcessManager.Close(); } catch { }
            Application.Exit();
        }