/// <summary> /// Connects the pipe to the server. /// </summary> /// <param name="cancellationToken">A token to cancel the request.</param> /// <exception cref="IOException">Thrown when the connection fails.</exception> public async Task ConnectAsync(CancellationToken cancellationToken = default) { if (this.State != PipeState.NotOpened) { throw new InvalidOperationException("Can only call ConnectAsync once"); } //this.logger.Log(() => $"Connecting to named pipe '{this.pipeName}' on machine '{this.serverName}'"); if (this.options != null) { this.rawPipeStream = new NamedPipeClientStream(this.serverName, this.pipeName, PipeDirection.InOut, this.options.Value | PipeOptions.Asynchronous, this.impersonationLevel.Value, this.inheritability.Value); } else { this.rawPipeStream = new NamedPipeClientStream(this.serverName, this.pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); } await this.rawPipeStream.ConnectAsync(cancellationToken).ConfigureAwait(false); //this.logger.Log(() => "Connected."); this.rawPipeStream.ReadMode = PipeTransmissionMode.Byte; this.wrappedPipeStream = new PipeStreamWrapper(this.rawPipeStream, this.logger); this.Invoker = new MethodInvoker <TRequesting>(this.wrappedPipeStream, this.messageProcessor); this.messageProcessor.StartProcessing(wrappedPipeStream); }
/// <summary> /// Connects the pipe to the server. /// </summary> /// <param name="cancellationToken">A token to cancel the request.</param> /// <exception cref="IOException">Thrown when the connection fails.</exception> public async Task ConnectAsync(CancellationToken cancellationToken = default) { if (this.State != PipeState.NotOpened) { throw new InvalidOperationException("Can only call ConnectAsync once"); } if (this.pipeName != null) { this.logger.Log(() => $"Connecting to named pipe '{this.pipeName}' on machine '{this.serverName}'"); } else { this.logger.Log(() => $"Connecting to named pipe"); } if (this.rawPipeStream == null) { this.CreatePipe(); } await this.rawPipeStream.ConnectAsync(cancellationToken).ConfigureAwait(false); this.logger.Log(() => "Connected."); this.wrappedPipeStream = new PipeStreamWrapper(this.rawPipeStream, this.logger); this.Invoker = new MethodInvoker <TRequesting>(this.wrappedPipeStream, this.messageProcessor); this.messageProcessor.StartProcessing(wrappedPipeStream); }
/// <summary> /// Ensures the given invoker is not null. /// </summary> /// <typeparam name="TRequesting">The interface to invoke.</typeparam> /// <param name="invoker">The invoker to check.</param> private static void EnsureInvokerNonNull <TRequesting>(IPipeInvoker <TRequesting> invoker) where TRequesting : class { if (invoker == null) { throw new PipeInvokeFailedException("Can only invoke methods after connecting the pipe."); } }
/// <summary> /// Waits for a client to connect to the pipe. /// </summary> /// <param name="cancellationToken">A token to cancel the request.</param> /// <exception cref="IOException">Thrown when the connection fails.</exception> public async Task WaitForConnectionAsync(CancellationToken cancellationToken = default) { if (this.rawPipeStream == null) { this.CreatePipe(); } await this.rawPipeStream.WaitForConnectionAsync(cancellationToken).ConfigureAwait(false); this.logger.Log(() => "Connected to client."); var wrappedPipeStream = new PipeStreamWrapper(this.rawPipeStream, this.logger); this.Invoker = new MethodInvoker <TRequesting>(wrappedPipeStream, this.messageProcessor); var requestHandler = new RequestHandler <THandling>(wrappedPipeStream, this.handlerFactoryFunc); this.messageProcessor.StartProcessing(wrappedPipeStream); }
public HandBrakeScanWorker(IPipeInvoker <IHandBrakeScanWorkerCallback> callback) : base(callback) { }
public WorkerLogger(IPipeInvoker <TCallback> callbackInvoker) { this.callbackInvoker = callbackInvoker; }
public HandBrakeEncodeWorker(IPipeInvoker <IHandBrakeEncodeWorkerCallback> callback) : base(callback) { CurrentWorker = this; }
public HandBrakeWorkerBase(IPipeInvoker <TCallback> callback) { this.CallbackInvoker = callback ?? throw new ArgumentNullException(nameof(callback)); }