private void HandleException(UcwaAppOperationResult result) { switch (result.StatusCode) { case HttpStatusCode.RequestTimeout: // request timed out, may need to readjust the default timeout value TaskCanceledException tcex = result.Exception as TaskCanceledException; ReportError(tcex.Message); break; case HttpStatusCode.Conflict: // duped ack Ids ReportError(result.StatusCode.ToString()); break; case HttpStatusCode.NotFound: // app not exists on server ReportError(result.StatusCode.ToString()); break; default: ReportError(result.Exception.Message); break; } this.Stop(); }
private async void SendButton_Click(object sender, RoutedEventArgs e) { UcwaAppOperationResult result = null; string msg = textBoxImInput.Text.Trim(); if (msg.StartsWith("<") && msg.EndsWith(">")) { result = await this.ucwaApp.Communication.SendMessage(msg, "text/html"); } else { result = await this.ucwaApp.Communication.SendMessage(msg, "text/plain"); } if (result == null) { textBlockStatus.Text = "ERROR: SendMessage returned null result."; } else if (result.Resource != null) { textBlockStatus.Text += Environment.NewLine + result.Resource.OuterXml; } else { textBlockStatus.Text += Environment.NewLine + "SendMessage: " + result.StatusCode.ToString(); } // Show the sent message to self Communication_OnMessageReceived("OK", DateTime.Now.ToString(), msg, this.ucwaApp.Me.DisplayName); }
public async Task <UcwaAppOperationResult> SendMessage(string msg = "Hello, this is a test.", string contentType = "text/plain") { if (operationId == null) { operationId = Guid.NewGuid().ToString(); } UcwaAppOperationResult result = null; if (messaging != null && messaging.sendMessageUri != null) { var uri = messaging.sendMessageUri + "?OperationId=" + operationId; result = await this.ucwaApp.Transport.PostResourceAsync(uri, msg, contentType); } if (messaging != null && messaging.sendMessageUri == null) { result = new UcwaAppOperationResult(HttpStatusCode.BadRequest, new Exception("null sendMessageUri received/cached.")); } else if (messaging == null) { result = new UcwaAppOperationResult(HttpStatusCode.BadRequest, new Exception("null messaging received/cached.")); } return(result); }