/// <summary> /// Create <see cref="KeepAliveSession"/> 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 <KeepAliveSession> TryCreateKeepAliveSessionAsync( this RemoteHostClient client, string serviceName, object callbackTarget, CancellationToken cancellationToken) { var connection = await client.TryCreateConnectionAsync(serviceName, callbackTarget, cancellationToken).ConfigureAwait(false); if (connection == null) { return(null); } return(new KeepAliveSession(client, connection, serviceName, callbackTarget)); }
/// <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)); }
public static async Task <bool> TryRunRemoteAsync( this RemoteHostClient client, string serviceName, string targetName, IReadOnlyList <object> arguments, CancellationToken cancellationToken) { using (var connection = await client.TryCreateConnectionAsync(serviceName, cancellationToken).ConfigureAwait(false)) { if (connection == null) { // can't create Connection. RemoteHost seems not responding for some reasons such as OOP gone. return(false); } await connection.InvokeAsync(targetName, arguments, cancellationToken).ConfigureAwait(false); return(true); } }
/// <summary> /// Create <see cref="RemoteHostClient.Connection"/> for the <paramref name="serviceName"/> if possible. /// otherwise, return null. /// /// Creating connection could fail if remote host is not available. one of example will be user killing /// remote host. /// </summary> public static Task <RemoteHostClient.Connection> TryCreateConnectionAsync( this RemoteHostClient client, string serviceName, CancellationToken cancellationToken) => client.TryCreateConnectionAsync(serviceName, callbackTarget: null, cancellationToken: cancellationToken);