Ejemplo n.º 1
0
        public void SetArgs_ShouldUnderstandOpenArg(string arg)
        {
            ArgumentsHelper.SetArgs(arg);
            Assert.AreEqual(true, ArgumentsHelper.HasConnectionSpecified);
            Assert.AreEqual(2, ArgumentsHelper.SpecifiedConnections.Count());

            // SpecifiedConnections
            var conn1 = ArgumentsHelper.SpecifiedConnections.ElementAt(0);

            Assert.AreEqual(ConnectionType.RDP, conn1.Type);
            Assert.AreEqual(13, conn1.ConnectionId);
            var conn2 = ArgumentsHelper.SpecifiedConnections.ElementAt(1);

            Assert.AreEqual(ConnectionType.SSH, conn2.Type);
            Assert.AreEqual(2, conn2.ConnectionId);
        }
Ejemplo n.º 2
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();
            }
        }