Exemplo n.º 1
0
        public void Test_IpcFake_SafeSerialize()
        {
            Assert.Throws(typeof(ArgumentNullException), () => { IpcFake.SafeSerialize(null); });
            Assert.Throws(typeof(ArgumentNullException), () => { IpcFake.SafeDeserialize(null); });

            string[] args = new string[] { "testA", "testB" };
            string   temp = IpcFake.SafeSerialize(args);

            string[] res = IpcFake.SafeDeserialize(temp);
            Assert.AreEqual(args[0], res[0]);
            Assert.AreEqual(args[1], res[1]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a message to the first instance of the application.
        /// </summary>
        /// <param name="message">The message to send to the first instance of the application. The message must be serializable.</param>
        /// <exception cref="System.InvalidOperationException">The object was constructed with the SingleInstanceTracker(string name) constructor overload, or with the SingleInstanceTracker(string name, SingleInstanceEnforcerRetriever enforcerRetriever) cosntructor overload, with enforcerRetriever set to null.</exception>
        /// <exception cref="SingleInstancing.SingleInstancingException">The SingleInstanceInteractor has failed to send the message to the first application instance. The first instance might have terminated.</exception>
        public void SendMessageToFirstInstance(object message)
        {
            if (fDisposed)
            {
                throw new ObjectDisposedException("The SingleInstanceTracker object has already been disposed.");
            }

            #if IPC_SUPPORTS
            if (fIpcChannel == null)
            {
                throw new InvalidOperationException("The object was constructed with the SingleInstanceTracker(string name) constructor overload, or with the SingleInstanceTracker(string name, SingleInstanceEnforcerRetriever enforcerRetriever) constructor overload, with enforcerRetriever set to null, thus you cannot send messages to the first instance.");
            }

            try
            {
                fProxy.Enforcer.OnMessageReceived(new MessageEventArgs(message));
            }
            catch (Exception ex)
            {
                throw new SingleInstancingException("Failed to send message to the first instance of the application. The first instance might have terminated.", ex);
            }
            #else
            try
            {
                string[] args = message as string[];
                if (args.Length == 0 || string.IsNullOrEmpty(args[0]))
                {
                    IpcFake.Send(AppMessage.RestoreWindow, 0, false);
                }
                else
                {
                    IpcParamEx ipcMsg = new IpcParamEx(IpcFake.CmdSendArgs, IpcFake.SafeSerialize(args));
                    IpcFake.SendGlobalMessage(ipcMsg);
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("SingleInstanceTracker.SendMessageToFirstInstance.2(): " + ex.Message);
            }
            #endif
        }
Exemplo n.º 3
0
        public static void SendMessage(string cmd, string[] args)
        {
            IpcParamEx ipcMsg = new IpcParamEx(cmd, IpcFake.SafeSerialize(args));

            IpcFake.SendMessage(ipcMsg);
        }