Example #1
0
        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);
        }
Example #2
0
        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));
        }
Example #4
0
        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)));
        }
Example #5
0
        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));
            }
        }