Exemplo n.º 1
0
 /// <summary>
 /// Runs the given RPC command on the server as soon as possible
 /// and returns the result or throws an <see cref="RpcException"/>.
 /// </summary>
 public async Task <T> ExecuteOnServer <T>(RpcCommand command)
 {
     try {
         // Apply [RpcOptions(...)] from method declaration
         command.ApplyRpcOptionsFromCallStack();
         // Enqueue (and execute)
         serverCache.EnqueueCommand(command);
         // Wait for result until timeout
         return(await command.WaitForResult <T>());
     }
     catch (RpcException ex) {
         // Rethrow RPC exception
         throw;
     }
     catch (Exception ex) {
         throw new RpcException(new RpcFailure(RpcFailureType.Other, ex.Message)); // Wrap any other exception
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Runs the given RPC command on the client with the given <see cref="RpcCommand.TargetPeerID"/>
 /// as soon as possible and returns the result or throws an <see cref="RpcException"/>.
 /// </summary>
 public async Task <T> ExecuteOnClient <T>(RpcCommand command)
 {
     try {
         var clientID = command.TargetPeerID;
         if (clientID.Length == 0)
         {
             throw new Exception("No client ID given");
         }
         // Apply [RpcOptions(...)] from method declaration
         command.ApplyRpcOptionsFromCallStack();
         // Enqueue (and execute)
         clients.GetClient(clientID, commandBacklog).EnqueueCommand(command);
         // Wait for result until timeout
         return(await command.WaitForResult <T>());
     }
     catch (RpcException ex) {
         throw; // Rethrow RPC exception
     }
     catch (Exception ex) {
         throw new RpcException(new RpcFailure(RpcFailureType.Other, ex.Message)); // Wrap any other exception
     }
 }