async Task <Object> DoUploadClr(RequestFile ru, ExpandoObject prms) { var invoker = new ClrInvoker(); Object result; if (ru.async) { result = await invoker.InvokeAsync(ru.clrType, prms); } else { result = invoker.Invoke(ru.clrType, prms); } return(result); }
async Task ExecuteClrCommand(RequestCommand cmd, ExpandoObject dataToInvoke, Guid apiGuid) { TextWriter writer = Response.Output; if (String.IsNullOrEmpty(cmd.clrType)) { throw new RequestModelException($"clrType must be specified for command '{cmd.command}'"); } var invoker = new ClrInvoker(); invoker.SetRequestInfo(RequestInfo); Object result = null; if (cmd.async) { result = await invoker.InvokeAsync(cmd.clrType, dataToInvoke, apiGuid); } else { result = invoker.Invoke(cmd.clrType, dataToInvoke, apiGuid); } if (result == null) { return; } if (result is String) { _logger.LogApi($"response: {result}", Request.UserHostAddress, apiGuid); writer.Write(result.ToString()); } else if (result is XDocument xDoc) { Response.ContentType = "text/xml"; using (var xmlWriter = XmlWriter.Create(writer)) { xDoc.WriteTo(xmlWriter); } } else { String json = JsonConvert.SerializeObject(result, JsonHelpers.StandardSerializerSettings); _logger.LogApi($"response: {json}", Request.UserHostAddress, apiGuid); writer.Write(json); } }
async Task ExecuteClrCommand(RequestCommand cmd, ExpandoObject dataToExec, TextWriter writer) { if (String.IsNullOrEmpty(cmd.clrType)) { throw new RequestModelException($"clrType must be specified for command '{cmd.command}'"); } var invoker = new ClrInvoker(); Object result; if (cmd.async) { result = await invoker.InvokeAsync(cmd.clrType, dataToExec); } else { result = invoker.Invoke(cmd.clrType, dataToExec); } writer.Write(JsonConvert.SerializeObject(result, StandardSerializerSettings)); }
public async Task <ServerCommandResult> Execute(RequestCommand cmd, ExpandoObject dataToExec) { if (String.IsNullOrEmpty(cmd.clrType)) { throw new RequestModelException($"clrType must be specified for command '{cmd.command}'"); } var invoker = new ClrInvoker(); Object result; if (cmd.async) { result = await invoker.InvokeAsync(cmd.clrType, dataToExec); } else { result = invoker.Invoke(cmd.clrType, dataToExec); } return(new ServerCommandResult(JsonConvert.SerializeObject(result, JsonHelpers.StandardSerializerSettings))); }
async Task ExecuteClrCommand(RequestCommand cmd, ExpandoObject dataToInvoke) { TextWriter writer = Response.Output; if (String.IsNullOrEmpty(cmd.clrType)) { throw new RequestModelException($"clrType must be specified for command '{cmd.command}'"); } var invoker = new ClrInvoker(); Object result = null; if (cmd.async) { result = await invoker.InvokeAsync(cmd.clrType, dataToInvoke); } else { result = invoker.Invoke(cmd.clrType, dataToInvoke); } if (result == null) { return; } if (result is String) { writer.Write(result.ToString()); } else if (result is XDocument xDoc) { Response.ContentType = "text/xml"; using (var xmlWriter = XmlWriter.Create(writer)) { xDoc.WriteTo(xmlWriter); } } else { writer.Write(JsonConvert.SerializeObject(result, BaseController.StandardSerializerSettings)); } }