private void InternalCallClientMethodAsync(ITwoWayRemotingClient clientObject, string clientUri, string methodName, bool disconnectOnException, params object[] methodArgs) { AsyncMethodInvoker invoker = new AsyncMethodInvoker(InvokeClientMethod); AsyncCallback cleanUp = new AsyncCallback(AsyncDelegateCleanup); IAsyncResult ar = invoker.BeginInvoke(this, clientObject, clientUri, methodName, disconnectOnException, methodArgs, cleanUp, null); }
protected override void OnClientMethodError(ITwoWayRemotingClient clientObject, Exception e) { if (e is System.Net.WebException || e is System.Net.Sockets.SocketException) { // Remove the client and notify the server that the client has disconnected DisconnectClient(clientObject, null, false); } }
public object CallServerMethod(ITwoWayRemotingClient remotingClient, string methodName, params object[] methodArgs) { // Check to see if the client is connected. If it's not, throw a network error. if (!IsClientConnected(remotingClient)) { throw new System.Net.Sockets.SocketException(10061); } if (serverObject != null) { List <object> methodParams = new List <object>(methodArgs); // Create a type array for our params List <Type> paramTypes = new List <Type>(methodArgs.Length); foreach (object param in methodArgs) { paramTypes.Add(param.GetType()); } // See if our method exists System.Reflection.MethodInfo method = serverObject.GetType().GetMethod(methodName, paramTypes.ToArray()); // If it doesn't, see if we should pass in our clientObject as our first param if (method == null) { paramTypes.Insert(0, typeof(ITwoWayRemotingClient)); methodParams.Insert(0, remotingClient); method = serverObject.GetType().GetMethod(methodName, paramTypes.ToArray()); // If it still doesn't exist, try adding our client uri as our first param /*if (method == null) * { * paramTypes[0] = typeof(string); * * try * { * method = serverObject.GetType().GetMethod(methodName, paramTypes.ToArray()); * } * catch * { * } * }*/ } if (method == null) { throw new NotSupportedException("The specified method does not exist on this object"); } return(method.Invoke(serverObject, methodParams.ToArray())); } else { return(null); } }
public TwoWayRemotingClientConnectionInfo(ITwoWayRemotingClient clientObject, string sessionKey) { this.sessionKey = sessionKey; this.clientObject = clientObject; remoteUri = RemotingServices.GetObjectUri((MarshalByRefObject)this.ClientObject); connectionTime = DateTime.Now; }
public void CallClientMethodAsync(ITwoWayRemotingClient clientObject, string methodName, bool disconnectOnException, params object[] methodArgs) { // Get the session ID for the client object TwoWayRemotingClientConnectionInfo ci = GetConnectionInfo(clientObject); if (ci != null) { InternalCallClientMethodAsync(clientObject, ci.RemoteUri, "CallClientMethod", disconnectOnException, ci.SessionKey, methodName, methodArgs); } }
public bool IsClientConnected(ITwoWayRemotingClient clientObject) { if (connectedClients.ContainsKey(GetClientID(clientObject))) { return(true); } else { return(false); } }
private void RemoveClient(ITwoWayRemotingClient clientObject) { string clientID = GetClientID(clientObject); if (connectedClients.ContainsKey(clientID)) { lock (connectedClients) { connectedClients.Remove(clientID); } } }
private TwoWayRemotingClientConnectionInfo GetConnectionInfo(ITwoWayRemotingClient clientObject) { string remoteUri = GetClientID(clientObject); foreach (TwoWayRemotingClientConnectionInfo ci in this.ConnectedClients) { if (ci.RemoteUri == remoteUri) { return(ci); } } return(null); }
private void Initialize(ITwoWayRemotingClient clientObject, string sessionKey, string username, string password) { this.sessionKey = sessionKey; this.username = username; this.password = password; this.clientObject = clientObject; try { clientUri = RemotingServices.GetObjectUri((MarshalByRefObject)clientObject); } catch { } }
public void Connect(ITwoWayRemotingClient remotingClient, string responseChannelName, string sessionKey, string username, string password) { System.Diagnostics.Trace.WriteLine("************** Connecting!!!"); ITwoWayRemotingClient client = (ITwoWayRemotingClient)Activator.GetObject(typeof(ITwoWayRemotingClient), string.Format("{0}", RemotingServices.GetObjectUri((MarshalByRefObject)remotingClient), responseChannelName)); System.Diagnostics.Trace.WriteLine("************** Connecting2"); if (ClientRequestingConnection != null) { TwoWayRemotingConnectionEventArgs e = new TwoWayRemotingConnectionEventArgs(client, sessionKey, username, password); ClientRequestingConnection(this, e); } }
private static void InvokeClientMethod(TwoWayRemotingServerBase server, ITwoWayRemotingClient clientObject, string clientUri, string methodName, bool disconnectOnException, params object[] methodArgs) { // Create a list of our parameter types List <Type> paramTypes = new List <Type>(methodArgs.Length); foreach (object param in methodArgs) { paramTypes.Add(param.GetType()); } System.Reflection.MethodInfo method = clientObject.GetType().GetMethod(methodName, paramTypes.ToArray()); try { System.Net.IPAddress address = (System.Net.IPAddress)System.Runtime.Remoting.Messaging.CallContext.GetData("ClientIP"); System.Diagnostics.Trace.WriteLine("****** Yo: " + server.GetClientID(clientObject)); method.Invoke(clientObject, methodArgs); System.Diagnostics.Trace.WriteLine("*** Done"); } catch (Exception e) { System.Diagnostics.Trace.WriteLine("*** Remoting Error: " + server.GetClientID(clientObject) + "\r\n\r\n" + e.ToString()); if (e.InnerException != null) { if (disconnectOnException) { server.DisconnectClient(clientObject, null, false); } else { server.OnClientMethodError(clientObject, e.InnerException); } } else { if (disconnectOnException) { server.DisconnectClient(clientObject, null, false); } else { server.OnClientMethodError(clientObject, e); } } } }
public void DisconnectClient(ITwoWayRemotingClient clientObject, string reason, bool notifyClient) { if (IsClientConnected(clientObject)) { RemoveClient(clientObject); if (notifyClient) { InternalCallClientMethodAsync(clientObject, GetClientID(clientObject), "OnDisconnected", false, reason); } } if (ClientDisconnected != null) { ClientDisconnected(this, new TwoWayRemotingConnectionEventArgs(clientObject, null)); } }
public void Disconnect(ITwoWayRemotingClient remotingClient, string sessionKey) { DisconnectClient(remotingClient, null, false); }
public void Connect(ITwoWayRemotingClient remotingClient, string responseChannelName, string sessionKey) { Connect(remotingClient, responseChannelName, sessionKey, null, null); }
private static void InvokeClientMethod(TwoWayRemotingServerBase server, ITwoWayRemotingClient clientObject, string clientUri, string methodName, bool disconnectOnException, params object[] methodArgs) { // Create a list of our parameter types List<Type> paramTypes = new List<Type>(methodArgs.Length); foreach (object param in methodArgs) { paramTypes.Add(param.GetType()); } System.Reflection.MethodInfo method = clientObject.GetType().GetMethod(methodName, paramTypes.ToArray()); try { System.Net.IPAddress address = (System.Net.IPAddress)System.Runtime.Remoting.Messaging.CallContext.GetData("ClientIP"); System.Diagnostics.Trace.WriteLine("****** Yo: " + server.GetClientID(clientObject)); method.Invoke(clientObject, methodArgs); System.Diagnostics.Trace.WriteLine("*** Done"); } catch (Exception e) { System.Diagnostics.Trace.WriteLine("*** Remoting Error: " + server.GetClientID(clientObject) + "\r\n\r\n" + e.ToString()); if (e.InnerException != null) { if (disconnectOnException) server.DisconnectClient(clientObject, null, false); else server.OnClientMethodError(clientObject, e.InnerException); } else { if (disconnectOnException) server.DisconnectClient(clientObject, null, false); else server.OnClientMethodError(clientObject, e); } } }
public bool IsClientConnected(ITwoWayRemotingClient clientObject) { if (connectedClients.ContainsKey(GetClientID(clientObject))) return true; else return false; }
public void DisconnectClient(ITwoWayRemotingClient clientObject, string reason, bool notifyClient) { if (IsClientConnected(clientObject)) { RemoveClient(clientObject); if (notifyClient) InternalCallClientMethodAsync(clientObject, GetClientID(clientObject), "OnDisconnected", false, reason); } if (ClientDisconnected != null) ClientDisconnected(this, new TwoWayRemotingConnectionEventArgs(clientObject, null)); }
public void DisconnectClient(ITwoWayRemotingClient clientObject) { DisconnectClient(clientObject, null); }
protected virtual void OnClientMethodError(ITwoWayRemotingClient clientObject, Exception e) { System.Diagnostics.Trace.WriteLine("*** Remoting Error: " + GetClientID(clientObject) + "\r\n\r\n" + e.ToString()); }
public void DisconnectClient(ITwoWayRemotingClient clientObject, string reason) { DisconnectClient(clientObject, reason, true); }
public TwoWayRemotingConnectionEventArgs(ITwoWayRemotingClient clientObject, string sessionKey, string username, string password) { Initialize(clientObject, sessionKey, username, password); }
public TwoWayRemotingConnectionEventArgs(ITwoWayRemotingClient clientObject, string sessionKey) { Initialize(clientObject, sessionKey, null, null); }
public string GetClientID(ITwoWayRemotingClient clientObject) { return RemotingServices.GetObjectUri((MarshalByRefObject)clientObject); }
public object CallServerMethod(ITwoWayRemotingClient remotingClient, string methodName, params object[] methodArgs) { // Check to see if the client is connected. If it's not, throw a network error. if (!IsClientConnected(remotingClient)) throw new System.Net.Sockets.SocketException(10061); if (serverObject != null) { List<object> methodParams = new List<object>(methodArgs); // Create a type array for our params List<Type> paramTypes = new List<Type>(methodArgs.Length); foreach (object param in methodArgs) { paramTypes.Add(param.GetType()); } // See if our method exists System.Reflection.MethodInfo method = serverObject.GetType().GetMethod(methodName, paramTypes.ToArray()); // If it doesn't, see if we should pass in our clientObject as our first param if (method == null) { paramTypes.Insert(0, typeof(ITwoWayRemotingClient)); methodParams.Insert(0, remotingClient); method = serverObject.GetType().GetMethod(methodName, paramTypes.ToArray()); // If it still doesn't exist, try adding our client uri as our first param /*if (method == null) { paramTypes[0] = typeof(string); try { method = serverObject.GetType().GetMethod(methodName, paramTypes.ToArray()); } catch { } }*/ } if (method == null) throw new NotSupportedException("The specified method does not exist on this object"); return method.Invoke(serverObject, methodParams.ToArray()); } else return null; }
private TwoWayRemotingClientConnectionInfo GetConnectionInfo(ITwoWayRemotingClient clientObject) { string remoteUri = GetClientID(clientObject); foreach (TwoWayRemotingClientConnectionInfo ci in this.ConnectedClients) { if (ci.RemoteUri == remoteUri) return ci; } return null; }
public string GetClientID(ITwoWayRemotingClient clientObject) { return(RemotingServices.GetObjectUri((MarshalByRefObject)clientObject)); }