public async Task <DataPackage> ProcessMessageAsync(DataPackage message, CancellationToken token) { message.NullTest(nameof(message)); if (!message.Headers.TryGetValue("ActionID", out object actionID) || actionID.ToString().IsEmpty()) { throw new MessagePipelineException("The title of the message does not contain ActionID"); } else if (!message.Headers.TryGetValue("UserName", out object UserID) || UserID.ToString().IsEmpty()) { throw new MessagePipelineException("The title of the message does not contain user name"); } _token = token; try { ActionInfo ai = await BuildContext(message); if (ai.AsyncMode) { return(await _actionManager.ExecuteAsync(ai, message)); } else { return(await Task.Run(() => _actionManager.Execute(ai, message))); } } catch (Exception ex) { return(DataPackage.CreateErrorPackage(ex)); } }
public async Task ProcessMessage() { HttpStatusCode resultCode = HttpStatusCode.OK; DataPackage response; bool multipleRowsResult = false; try { ActionInfo ai = await BuildContext(); response = await _actionManager.ExecuteAsync(ai, DataPackage.Parse(await new StreamReader(_context.Request.Body).ReadToEndAsync(), TsJsonFormat.Simple, 8)); multipleRowsResult = ai.MultipleRowsResult; } catch (Exception ex) { response = DataPackage.CreateErrorPackage(ex); resultCode = GetCodeFromException(ex); } _context.Response.StatusCode = (int)resultCode; if (multipleRowsResult && resultCode == HttpStatusCode.OK) { await _context.Response.WriteAsync(response.ToString(), Encoding.UTF8); } else { response.GoDataTop(); await _context.Response.WriteAsync(response.GetRowJSON(), Encoding.UTF8); } }