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 });
        }
        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
                });
            }
        }