Пример #1
0
        public DextopApiInvocationResult Invoke(string action, string[] arguments, DextopFormSubmit form)
        {
            var method = controller.GetType().GetMethod(action);

            if (method == null)
            {
                throw new DextopException("Cannot find method '{0}' in controller type '{1}'.", action, controller.GetType());
            }

            var parameters = method.GetParameters();
            var p          = new object[parameters.Length];

            int offset = form == null ? 0 : 1;

            if (form != null)
            {
                p[0] = form;
            }

            for (var i = 0; i < Math.Min(p.Length, arguments.Length); i++)
            {
                p[i + offset] = DextopUtil.DecodeValue(arguments[i], parameters[i + offset].ParameterType);
            }

            try
            {
                var value = method.Invoke(controller, p);
                return(DextopApiInvocationResult.Success(value));
            }
            catch (Exception ex)
            {
                return(DextopApiInvocationResult.Exception(ex));
            }
        }
Пример #2
0
        internal DextopApiInvocationResult Invoke(String action, DextopFormSubmit form, params String[] arguments)
        {
            var invoker = CreateActionInvoker(action, arguments);
            var result  = invoker.Invoke(action, arguments, form);

            return(result);
        }
Пример #3
0
        public DextopApiInvocationResult Invoke(string action, string[] arguments, DextopFormSubmit form)
        {
            var method = controller.GetType().GetMethod(action);
            if (method == null)
                throw new DextopException("Cannot find method '{0}' in controller type '{1}'.", action, controller.GetType());

            var parameters = method.GetParameters();
            var p = new object[parameters.Length];

            int offset = form == null ? 0 : 1;
            
            if (form != null)
                p[0] = form;
            
            for (var i = 0; i < Math.Min(p.Length, arguments.Length); i++)
                p[i + offset] = DextopUtil.DecodeValue(arguments[i], parameters[i + offset].ParameterType);

            try
            {
                var value = method.Invoke(controller, p);
                return DextopApiInvocationResult.Success(value);
            }            
            catch (Exception ex)
            {
                return DextopApiInvocationResult.Exception(ex);
            }
        }
Пример #4
0
        public string SubmitForm(DextopFormSubmit form)
        {
            var data = form.DecodeForm<Form>();

            if (data.Picture == null)
                throw new DextopErrorMessageException("No file specified.");

            return String.Format("Hi {0}, your picture has been saved.", data.Name);
        }
Пример #5
0
 string UploadFile(DextopFormSubmit form)
 {
     if (form.Files.Count == 1)
     {
         var file = form.Files.Values.First();
         return(String.Format("You have just uploaded the {1:0,0} bytes long file named '{0}'.", file.FileName, file.FileLength));
     }
     throw new InvalidOperationException("No file recieved!");
 }
Пример #6
0
 string UploadFile(DextopFormSubmit form)
 {
     if (form.Files.Count == 1)
     {
         var file = form.Files.Values.First();
         return String.Format("You have just uploaded the {1:0,0} bytes long file named '{0}'.", file.FileName, file.FileLength);
     }
     throw new InvalidOperationException("No file recieved!");
 }
        public DextopRemoteMethodInvokeResult Invoke(IDextopRemotable target, string methodName, string[] arguments, DextopFormSubmit form)
        {
            if (methodName == "Instantiate" && arguments.Length>0)
                return Instantiate(target, arguments);

            if (methodName == "Dispose")
            {
                try
                {
                    target.Dispose();
                    return new DextopRemoteMethodInvokeResult { Success = true };
                }
                catch (Exception ex)
                {
                    return new DextopRemoteMethodInvokeResult { Success = false, Exception = ex };
                }
            }

            try
            {
                var type = target.GetType();
                var method = GetMethod(type, methodName);
                ++method.InvokeCount;
                int offset = form == null ? 0 : 1;
                object[] args = new object[method.Args.Length];
                if (form != null)
                    args[0] = form;
                if (arguments.Length + offset != method.Args.Length)
                    throw new DextopException("Invalid number of arguments for a remote method call.");
                for (var i = 0; i < arguments.Length; i++)
                    args[i + offset] = DextopUtil.DecodeValue(arguments[i], method.Args[i + offset]);
                var result = method.MethodInfo.Invoke(target, args);
                return new DextopRemoteMethodInvokeResult
                {
                    Success = true,
                    Result = result
                };
            }
            catch (TargetInvocationException tix)
            {
                return new DextopRemoteMethodInvokeResult
                {
                    Success = false,
                    Exception = tix.InnerException ?? tix
                };
            }
            catch (Exception ex)
            {
                return new DextopRemoteMethodInvokeResult
                {
                    Success = false,
                    Exception = ex
                };
            }
        }
        public string SubmitForm(DextopFormSubmit form)
        {
            var data = form.DecodeForm <Form>();

            if (data.Picture == null)
            {
                throw new DextopErrorMessageException("No file specified.");
            }

            return(String.Format("Hi {0}, your picture has been saved.", data.Name));
        }
Пример #9
0
        Request[] GetUploadRequest(HttpContext context)
        {
            var files = new Dictionary <String, DextopFile>();

            for (var i = 0; i < context.Request.Files.Count; i++)
            {
                if (context.Request.Files[i].ContentLength > 0)
                {
                    var fi = new FileInfo(context.Request.Files[i].FileName);
                    files.Add(context.Request.Files.AllKeys[i], new DextopFile
                    {
                        FileStream    = context.Request.Files[i].InputStream,
                        FileLength    = context.Request.Files[i].ContentLength,
                        FileName      = fi.Name,
                        FileExtension = fi.Extension,
                        ContentType   = context.Request.Files[i].ContentType
                    });
                }
            }

            List <String> parameters = new List <string>();

            parameters.Add(context.Request.Form["_apiControllerType"]);
            parameters.Add(context.Request.Form["_apiScope"]);
            parameters.Add(context.Request.Form["_apiMethod"]);
            parameters.Add(context.Request.Form["_apiArguments"]);

            var formSumbit = new DextopFormSubmit
            {
                Files           = files,
                Context         = context,
                FieldValuesJSON = context.Request["_apiFieldValues"]
            };

            var request = new Request
            {
                tid         = int.Parse(context.Request.Form["extTID"]),
                action      = context.Request.Form["extAction"],
                method      = context.Request.Form["extMethod"],
                type        = context.Request.Form["extType"],
                FormSubmit  = formSumbit,
                data        = parameters.ToArray(),
                RequestType = RequestType.FormSubmit
            };

            return(new[] { request });
        }
Пример #10
0
        Request[] GetUploadRequest(HttpContext context)
        {
            var files = new Dictionary<String, DextopFile>();
            for (var i = 0; i < context.Request.Files.Count; i++)
            {
                if (context.Request.Files[i].ContentLength > 0)
                {
                    var fi = new FileInfo(context.Request.Files[i].FileName);
                    files.Add(context.Request.Files.AllKeys[i], new DextopFile
                    {
                        FileStream = context.Request.Files[i].InputStream,
                        FileLength = context.Request.Files[i].ContentLength,
                        FileName = fi.Name,
                        FileExtension = fi.Extension,
                        ContentType = context.Request.Files[i].ContentType
                    });
                }
            }

            List<String> parameters = new List<string>();
            parameters.Add(context.Request.Form["_rcpId"]);
            parameters.Add(context.Request.Form["_rcpMethod"]);
            parameters.Add(context.Request.Form["_rcpArguments"]);

            var formSumbit = new DextopFormSubmit
            {
                Files = files,
                Context = context,
                FieldValuesJSON = context.Request["_rcpFieldValues"]
            };

            var request = new Request
            {
                tid = int.Parse(context.Request.Form["extTID"]),
                action = context.Request.Form["extAction"],
                method = context.Request.Form["extMethod"],
                type = context.Request.Form["extType"],
                FormSubmit = formSumbit,
                data = parameters.ToArray(),
                RequestType = RequestType.FormSubmit
            };

            return new[] { request };
        }
Пример #11
0
 internal DextopApiInvocationResult Invoke(String action, DextopFormSubmit form, params String[] arguments)
 {
     var invoker = CreateActionInvoker(action, arguments);
     var result = invoker.Invoke(action, arguments, form);
     return result;
 }