コード例 #1
0
 /// <summary>
 /// Executes the given RPC command locally on the client immediately and returns the result.
 /// No exception is thrown, but a <see cref="RpcFailure"/> result is set in case of a failure.
 /// </summary>
 public async Task <RpcCommandResult> ExecuteLocallyNow(RpcCommand command)
 {
     // Do not run the same command twice. If the command with this ID was already
     // executed, return the cached result. If the cache is not available any more, return a
     // obsolete function call failure.
     if (serverCache.GetCachedResult(command.ID) is RpcCommandResult result)
     {
         return(result);
     }
     // Execute the command
     try {
         var runner = new RpcCommandRunner(clientMethods(), null);
         result = await runner.Execute(clientConfig.ClientID, command);
     }
     catch (Exception ex) {
         result = RpcCommandResult.FromFailure(command.ID,
                                               new RpcFailure(RpcFailureType.RemoteException, ex.Message));
     }
     // Cache result, if there was no network problem
     if (false == (result.Failure?.IsNetworkProblem == true))
     {
         serverCache.CacheResult(result);
     }
     return(result);
 }
コード例 #2
0
        /// <summary>
        /// Call this method when the client called the "/rpc/push"-endpoint.
        /// It executes the given RPC command immediately and returns the result.
        /// No exception is thrown, but a <see cref="RpcFailure"/> result is set in case of a failure.
        /// </summary>
        public async Task <RpcCommandResult> OnClientPush(string clientID, RpcCommand command, RpcCommandRunner runner)
        {
            // Do not run the same command twice. If the command with this ID was already
            // executed, return the cached result. If the cache is not available any more, return a
            // obsolete function call failure.
            var client = clients.GetClient(clientID, commandBacklog);

            if (client.GetCachedResult(command.ID) is RpcCommandResult result)
            {
                return(result);
            }
            // Execute the command
            try {
                result = await runner.Execute(clientID, command);
            }
            catch (Exception ex) {
                result = RpcCommandResult.FromFailure(command.ID,
                                                      new RpcFailure(RpcFailureType.RemoteException, ex.Message));
            }
            // Cache result, if there was no network problem
            if (false == (result.Failure?.IsNetworkProblem == true))
            {
                client.CacheResult(result);
            }
            return(result);
        }