public override async Task ExecuteAsync()

in sources/Google.Solutions.IapDesktop.Extensions.Session/ToolWindows/Session/ConnectInstanceCommand.cs [75:152]


        public override async Task ExecuteAsync(IProjectModelNode node)
        {
            Debug.Assert(IsAvailable(node));
            Debug.Assert(IsEnabled(node));

            var instanceNode = (IProjectModelInstanceNode)node;
            ISession? session = null;

            //
            // Select node so that tracking windows are updated.
            //
            await this.workspace
                .SetActiveNodeAsync(
                    node,
                    CancellationToken.None)
                .ConfigureAwait(true);

            //
            // Try to activate existing session, if any.
            //
            if (!this.ForceNewConnection &&
                this.sessionBroker.TryActivateSession(instanceNode.Instance, out session))
            {
                //
                // There is an existing session, and it's now active.
                //
                Debug.Assert(session != null);
                Debug.Assert(
                    (instanceNode.IsRdpSupported() && session is IRdpSession) ||
                    (instanceNode.IsSshSupported() && session is ISshSession));
                return;
            }

            //
            // Create new session.
            //
            if (instanceNode.IsRdpSupported())
            {
                var context = await this.sessionContextFactory
                    .CreateRdpSessionContextAsync(
                        instanceNode,
                        this.Flags,
                        CancellationToken.None)
                    .ConfigureAwait(true);

                try
                {
                    session = await this.sessionFactory
                        .CreateSessionAsync(context)
                        .ConfigureAwait(true);
                }
                catch
                {
                    context.Dispose();
                    throw;
                }
            }
            else if (instanceNode.IsSshSupported())
            {
                var context = await this.sessionContextFactory
                    .CreateSshSessionContextAsync(instanceNode, CancellationToken.None)
                    .ConfigureAwait(true);

                try
                {
                    session = await this.sessionFactory
                        .CreateSessionAsync(context)
                        .ConfigureAwait(true);
                }
                catch
                {
                    context.Dispose();
                    throw;
                }
            }

            Debug.Assert(session != null);
        }