/// <summary> /// Executes a <see cref="WuRemoteCall"/> on the <see cref="IWuEndpoint"/> for this view model. /// </summary> /// <param name="call">Call to execute.</param> /// <param name="param">Call parameter.</param> protected async Task <WuRemoteCallResult> ExecuteRemoteCallAsync(WuRemoteCall call, object param) { if (call == null) { throw new ArgumentNullException(nameof(call)); } IWuEndpoint endpoint; if (TryGetEndpoint(out endpoint)) { try { Log.Debug($"Execute remote call async: {call.GetType().Name}, Param: {param?.ToString()}"); return(await call.CallAsync(endpoint, param)); } catch (Exception e) { Log.Error($"Execute remote call async failed: {call.GetType().Name}, Param: {param?.ToString()}", e); return(new WuRemoteCallResult(endpoint, call, false, e, null)); } } else { return(new WuRemoteCallResult(endpoint, call, false, null, "The remote service is not longer available.")); } }
/// <summary> /// Executes a <see cref="WuRemoteCall"/> on the <see cref="IWuEndpoint"/> for this view model. /// </summary> /// <param name="call">Call to execute.</param> /// <param name="param">Call parameter.</param> /// <param name="onCompletion">Called when the async operation completes.</param> protected async void ExecuteRemoteCallAsync(WuRemoteCall call, object param, Action <WuRemoteCallResult> onCompletion) { if (call == null) { throw new ArgumentNullException(nameof(call)); } var result = await ExecuteRemoteCallAsync(call, param); onCompletion?.Invoke(result); }
public WuEndpointCommand(WuRemoteCall remoteCall, Func <IEnumerable <IWuEndpoint> > wuEndpointSelector) { if (remoteCall == null) { throw new ArgumentNullException(nameof(remoteCall)); } if (wuEndpointSelector == null) { throw new ArgumentNullException(nameof(wuEndpointSelector)); } RemoteCall = remoteCall; WuEndpointSelector = wuEndpointSelector; }