public async Task <AppServiceResponseStatus> SendMessageAsync(ValueSet valueSet) { if (serverStream == null) { return(AppServiceResponseStatus.Failure); } try { var guid = Guid.NewGuid().ToString(); valueSet.Add("RequestID", guid); var serialized = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Dictionary <string, object>(valueSet))); await serverStream.WriteAsync(serialized, 0, serialized.Length); return(AppServiceResponseStatus.Success); } catch (System.IO.IOException) { // Pipe is disconnected ServiceClosed?.Invoke(this, EventArgs.Empty); this.Cleanup(); } catch (Exception ex) { App.Logger.Warn(ex, "Error sending request on pipe."); } return(AppServiceResponseStatus.Failure); }
public AppServiceConnectionWrapper(AppServiceConnection connection) { connection.RequestReceived += (s, e) => RequestReceived?.Invoke(this, new AppServiceRequestReceivedEventArgsWrapper(e)); connection.ServiceClosed += (s, e) => ServiceClosed?.Invoke(this, new AppServiceClosedEventArgsWrapper(e)); }
private void OnServiceClosed() { ServiceClosed?.Invoke(this, EventArgs.Empty); }