/// <inheritdoc /> public async Task <IProtocol> ExecuteAsync( GetProtocolOp operation) { var syncResult = this.Execute(operation); var result = await Task.FromResult(syncResult); return(result); }
/// <summary> /// Executes a void operation asynchronously using a protocol returned by a specified protocol factory. /// </summary> /// <param name="protocolFactory">The protocol factory.</param> /// <param name="operation">The operation.</param> /// <returns> /// A task. /// </returns> public static async Task GetProtocolAndExecuteViaReflectionAsync( this IAsyncReturningProtocol <GetProtocolOp, IProtocol> protocolFactory, IOperation operation) { if (protocolFactory == null) { throw new ArgumentNullException(nameof(protocolFactory)); } var getProtocolOp = new GetProtocolOp(operation); var protocol = await protocolFactory.ExecuteAsync(getProtocolOp); await protocol.ExecuteViaReflectionAsync(operation); }
/// <summary> /// Executes a void operation synchronously using a protocol returned by a specified protocol factory. /// </summary> /// <param name="protocolFactory">The protocol factory.</param> /// <param name="operation">The operation.</param> public static void GetProtocolAndExecuteViaReflection( this ISyncReturningProtocol <GetProtocolOp, IProtocol> protocolFactory, IOperation operation) { if (protocolFactory == null) { throw new ArgumentNullException(nameof(protocolFactory)); } var getProtocolOp = new GetProtocolOp(operation); var protocol = protocolFactory.Execute(getProtocolOp); protocol.ExecuteViaReflection(operation); }
/// <inheritdoc /> public IProtocol Execute( GetProtocolOp operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } var getProtocolOp = new GetProtocolOp(operation.Operation, MissingProtocolStrategy.ReturnNull); IProtocol result = null; foreach (var protocolFactory in this.protocolFactoriesToUseInOrder) { result = protocolFactory.Execute(getProtocolOp); if (result != null) { break; } } if (result != null) { return(result); } else if (operation.MissingProtocolStrategy == MissingProtocolStrategy.Throw) { throw new OpExecutionFailedException(Invariant($"There is no protocol registered for the specified operation: '{operation.Operation.GetType().ToStringReadable()}'."), operation); } else if (operation.MissingProtocolStrategy == MissingProtocolStrategy.ReturnNull) { return(null); } else { throw new NotSupportedException(Invariant($"This {nameof(MissingProtocolStrategy)} is not supported: {operation.MissingProtocolStrategy}.")); } }
/// <inheritdoc /> public IProtocol Execute( GetProtocolOp operation) { if (operation == null) { throw new ArgumentNullException(nameof(operation)); } var operationType = operation.Operation.GetType(); // ReSharper disable once InconsistentlySynchronizedField if (!this.operationTypeToGetProtocolFuncMap.TryGetValue(operation.Operation.GetType(), out var getProtocolFunc)) { if (operation.MissingProtocolStrategy == MissingProtocolStrategy.Throw) { throw new OpExecutionFailedException(Invariant($"There is no protocol registered for the specified operation: '{operationType.ToStringReadable()}'."), operation); } else if (operation.MissingProtocolStrategy == MissingProtocolStrategy.ReturnNull) { return(null); } else { throw new NotSupportedException(Invariant($"This {nameof(MissingProtocolStrategy)} is not supported: {operation.MissingProtocolStrategy}.")); } } var result = getProtocolFunc(); if (result == null) { throw new InvalidOperationException(Invariant($"The func to get the protocol for the following specified operation returned null: '{operationType.ToStringReadable()}'.")); } return(result); }