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 }; } }
internal DextopConfig Register(DextopRemote parent, IDextopRemotable remotable, String remoteId = null, bool subRemote = true) { if (remotable == null) throw new ArgumentNullException("remotable"); bool isClientInitiated; if (remoteId == null) { remoteId = Interlocked.Increment(ref nextRemoteId).ToString(); isClientInitiated = parent!=null && parent.IsClientInitiated; } else if (subRemote) { if (parent == null) throw new DextopInternalException(); remoteId = parent.RemoteId + '.' + remoteId; isClientInitiated = parent.IsClientInitiated; } else isClientInitiated = true; var context = new RemotableContext { Remotable = remotable }; var remote = new DextopRemote(Context, remoteId, isClientInitiated); var clientTypeName = DextopApplication.MapTypeName(remotable.GetType()); try { var config = new DextopConfig(); remotable.InitRemotable(remote, config); if (!remote.IsClientInitiated) { DextopConfig remoteProxyConfig; var remoteTypeName = remote.RemoteHostType ?? clientTypeName; if (remoteTypeName != null) { config.Add("alias", remoteTypeName); remoteProxyConfig = new DextopConfig(); config.Add("remote", remoteProxyConfig); } else { remoteProxyConfig = config; } remoteProxyConfig.Add("remoteId", remoteId); remoteProxyConfig.Add("alias", DextopUtil.GetRemotingProxyTypeName(clientTypeName)); if (remote.componentsConfig != null) { remoteProxyConfig.Add("components", remote.componentsConfig); //config not needed anymore - free memory remote.componentsConfig = null; } } if (!remotables.TryAdd(remoteId, context)) throw new DextopInternalException(); return config; } catch { remote.Dispose(); remotable.Dispose(); throw; } }
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 }); } }
internal DextopConfig Register(DextopRemote parent, IDextopRemotable remotable, String remoteId = null, bool subRemote = true) { if (remotable == null) { throw new ArgumentNullException("remotable"); } bool isClientInitiated; if (remoteId == null) { remoteId = Interlocked.Increment(ref nextRemoteId).ToString(); isClientInitiated = parent != null && parent.IsClientInitiated; } else if (subRemote) { if (parent == null) { throw new DextopInternalException(); } remoteId = parent.RemoteId + '.' + remoteId; isClientInitiated = parent.IsClientInitiated; } else { isClientInitiated = true; } var context = new RemotableContext { Remotable = remotable }; var remote = new DextopRemote(Context, remoteId, isClientInitiated); var clientTypeName = DextopApplication.MapTypeName(remotable.GetType()); try { var config = new DextopConfig(); remotable.InitRemotable(remote, config); if (!remote.IsClientInitiated) { DextopConfig remoteProxyConfig; var remoteTypeName = remote.RemoteHostType ?? clientTypeName; if (remoteTypeName != null) { config.Add("alias", remoteTypeName); remoteProxyConfig = new DextopConfig(); config.Add("remote", remoteProxyConfig); } else { remoteProxyConfig = config; } remoteProxyConfig.Add("remoteId", remoteId); remoteProxyConfig.Add("alias", DextopUtil.GetRemotingProxyTypeName(clientTypeName)); if (remote.componentsConfig != null) { remoteProxyConfig.Add("components", remote.componentsConfig); //config not needed anymore - free memory remote.componentsConfig = null; } } if (!remotables.TryAdd(remoteId, context)) { throw new DextopInternalException(); } return(config); } catch { remote.Dispose(); remotable.Dispose(); throw; } }