예제 #1
0
        public async Task <SessionWithSolution?> TryCreateSessionAsync(string serviceName, Solution solution, object?callbackTarget, CancellationToken cancellationToken)
        {
            var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

            if (connection == null)
            {
                return(null);
            }

            SessionWithSolution?session = null;

            try
            {
                // transfer ownership of the connection to the session object:
                session = await SessionWithSolution.CreateAsync(connection, solution, cancellationToken).ConfigureAwait(false);
            }
            finally
            {
                if (session == null)
                {
                    connection.Dispose();
                }
            }

            return(session);
        }
예제 #2
0
        public async Task <SessionWithSolution?> TryCreateSessionAsync(string serviceName, Solution solution, object?callbackTarget, CancellationToken cancellationToken)
        {
            var connection = await TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);

            if (connection == null)
            {
                return(null);
            }

            return(await SessionWithSolution.CreateAsync(connection, solution, cancellationToken).ConfigureAwait(false));
        }
예제 #3
0
        /// <summary>
        /// Create <see cref="SessionWithSolution"/> for the <paramref name="serviceName"/> if possible.
        /// otherwise, return null.
        /// 
        /// Creating session could fail if remote host is not available. one of example will be user killing
        /// remote host.
        /// </summary>
        public static async Task<SessionWithSolution> TryCreateSessionAsync(
            this RemoteHostClient client, string serviceName, Solution solution, object callbackTarget, CancellationToken cancellationToken)
        {
            var connection = await client.TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false);
            if (connection == null)
            {
                return null;
            }

            return await SessionWithSolution.CreateAsync(connection, solution, cancellationToken).ConfigureAwait(false);
        }