public static void StopService()
 {
     if (MessageManager != null)
     {
         MessageManager.MessageReceived -= MessageManagerMessageReceived;
         MessageManager.Close();
         MessageManager.Dispose();
         MessageManager = null;
     }
 }
Пример #2
0
        private static void StartedAsAnotherInstance(CommandLineOptions options)
        {
            const string mainContainrName = "low-levelkeys-main";

            var messageContainer = new MessageManager("low-levelkeys-second-instance");
            var exists = messageContainer.CheckMessageContainer(mainContainrName);
            if (exists)
            {
                if (!string.IsNullOrEmpty(options.SendKeys))
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "SENDKEYS " + options.SendKeys);
                    Console.WriteLine(result == CommunicationBridge.ResponseOk ? "Keys sent sucefully" : result);
                }

                if (options.ListKeys)
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "LISTKEYS");
                    Console.WriteLine("ListKeys response:");
                    Console.WriteLine(result);
                }

                if (options.Minimized)
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "SENDTOTRAY");
                    Console.WriteLine(result == CommunicationBridge.ResponseOk ? "Application minimized to tray." : result);
                }

                if (options.Restore)
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "RESTOREWINDOW");
                    Console.WriteLine(result == CommunicationBridge.ResponseOk ? "Application main window restored." : result);
                }

                if (options.StartSocketServer)
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "STARTSOCKETSERVER");
                    Console.WriteLine(result == CommunicationBridge.ResponseOk ? "Socket server started." : result);
                }

                if (options.StopSocketServer)
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "STOPSOCKETSERVER");
                    Console.WriteLine(result == CommunicationBridge.ResponseOk ? "Socket server stopped." : result);
                }

                if (options.Quit)
                {
                    var result = messageContainer.SendMessageAndWaitResponse(mainContainrName, "UNLOADAPPLICATION");
                    Console.WriteLine(result == CommunicationBridge.ResponseOk ? "Application unloaded." : result);
                }

            }
            else
            {
                Console.WriteLine("Another instance of this application is running, but a message container named 'low-levelkeys-main' was not found.");
                Console.WriteLine("No message could be sent to the another instance.");
            }
        }
 public static void StartService()
 {
     MessageManager = new MessageManager("low-levelkeys-main");
     MessageManager.MessageReceived += MessageManagerMessageReceived;
 }