Example #1
0
        public void Activate_ShouldNotThrow()
        {
            var processCommander = new ProcessCommander
            {
                ConnectionRequest = ConnectionRequest.Singleton
            };

            Assert.DoesNotThrow(() => processCommander.Activate());
        }
Example #2
0
        public void Invoke_ShouldEnqueueConnectionInfoToConnectioRequest()
        {
            var processCommander = new ProcessCommander
            {
                ConnectionRequest = ConnectionRequest.Singleton
            };

            processCommander.Invoke(Models.ConnectionType.RDP, 800);
            processCommander.Invoke(Models.ConnectionType.SSH, 900);
            Assert.AreEqual(2, ConnectionRequest.Singleton.Queue.Count);
            var(type, id) = ConnectionRequest.Singleton.Queue.Dequeue();
            Assert.AreEqual(Models.ConnectionType.RDP, type);
            Assert.AreEqual(800, id);
            (type, id) = ConnectionRequest.Singleton.Queue.Dequeue();
            Assert.AreEqual(Models.ConnectionType.SSH, type);
            Assert.AreEqual(900, id);
        }
Example #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ArgumentsHelper.SetArgs(e.Args);
            base.OnStartup(e);

            // Local method to enqueue connections specified with command-line argument
            bool EnqueueOpenRequestedConnections(IProcessCommander processCommander)
            {
                if (!ArgumentsHelper.HasConnectionSpecified)
                {
                    return(false);
                }
                foreach (var conn in ArgumentsHelper.SpecifiedConnections)
                {
                    MyLogger.Log($"Connection (Type: {conn.Type}, Id: {conn.ConnectionId}) has been enqueued.");
                    processCommander.Invoke(conn.Type, conn.ConnectionId);
                }
                return(true);
            }

            if (SingleAppInstanceHelper.TryStart())
            {
                // Boot as an IPC host
                var service = new ProcessCommander
                {
                    ConnectionRequest = ConnectionRequest.Singleton,
                };
                var serviceHost = IPCService.OpenServiceHost(service);
                EnqueueOpenRequestedConnections(service);
            }
            else
            {
                // Boot as an IPC client
                var channel = IPCService.CreateServiceChannel();
                if (!EnqueueOpenRequestedConnections(channel))
                {
                    MyLogger.Log("Shutting down because another application instance has already run...");
                }
                channel.Activate();
                // Shutdown after activate the primary window
                Shutdown();
            }
        }