示例#1
0
        DextopRemoteMethodInvokeResult Instantiate(IDextopRemotable target, String[] arguments)
        {
            try
            {
                if (arguments.Length < 1)
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }
                InstantiateOptions options;
                if (arguments[0] != null && arguments[0].StartsWith("{"))
                {
                    options = DextopUtil.Decode <InstantiateOptions>(arguments[0]);
                }
                else
                {
                    options = new InstantiateOptions
                    {
                        subRemote = true,
                        type      = arguments[0]
                    }
                };

                if (options.type == null)
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }

                String config = null;
                if (arguments.Length > 1)
                {
                    config = arguments[1];
                }

                RemotableConstructor c;
                if (options.type == null || !constructorCache.TryGetValue(options.type, out c))
                {
                    throw new InvalidDextopRemoteMethodCallException();
                }
                object[] args;
                if (c.Args == null || c.Args.Length == 0)
                {
                    args = new object[0];
                }
                else if (c.Args.Length == 1 && c.Args[0].ParameterType == typeof(DextopConfig))
                {
                    var rc = DextopUtil.Decode(config, c.Args[0].ParameterType);
                    args = new object[] { rc };
                }
                else
                {
                    args = new object[c.Args.Length];
                    if (config == null)
                    {
                    }
                    else if (config.StartsWith("["))
                    {
                        var argss = DextopUtil.Decode <String[]>(config);
                        for (var i = 0; i < c.Args.Length && i < argss.Length; i++)
                        {
                            args[i] = DextopUtil.DecodeValue(argss[i], c.Args[i].ParameterType);
                        }
                    }
                    else
                    {
                        var configs = DextopUtil.Decode <Dictionary <String, String> >(config) ?? new Dictionary <String, String>();
                        for (var i = 0; i < c.Args.Length; i++)
                        {
                            String argString;
                            if (configs.TryGetValue(c.Args[i].Name, out argString))
                            {
                                args[i] = DextopUtil.Decode(argString, c.Args[i].ParameterType);
                            }
                        }
                    }
                }

                var remotable = (IDextopRemotable)c.ConstructorInfo.Invoke(args);

                try
                {
                    return(new DextopRemoteMethodInvokeResult
                    {
                        Success = true,
                        Result = target.Remote.TrackRemotableComponent(remotable,
                                                                       remoteId: options.remoteId,
                                                                       subRemote: options.subRemote ?? true,
                                                                       own: options.own ?? true
                                                                       )
                    });
                }
                catch
                {
                    remotable.Dispose();
                    throw;
                }
            }
            catch (TargetInvocationException tix)
            {
                return(new DextopRemoteMethodInvokeResult
                {
                    Success = false,
                    Exception = tix.InnerException ?? tix
                });
            }
            catch (Exception ex)
            {
                return(new DextopRemoteMethodInvokeResult
                {
                    Success = false,
                    Exception = ex
                });
            }
        }
示例#2
0
 public static ActionRequest[] Deserialize(String requestData)
 {
     return(requestData.StartsWith("[") ? DextopUtil.Decode <ActionRequest[]>(requestData) : new[] { DextopUtil.Decode <ActionRequest>(requestData) });
 }