public InterfacePrototype GetSharedClass <InterfacePrototype>(string name, params object[] RemoteArgs) { lock (InitializedClasses) { SyncObject syncObject = null; lock (Requests) { int RequestId = 0; RequestId = GetNextRandomInteger(); while (Requests.ContainsKey(RequestId)) { RequestId = GetNextRandomInteger(); } syncObject = new SyncObject(this); Requests.Add(RequestId, syncObject); Send(new MsgGetSharedClass(name, RemoteArgs, RequestId)); } ReturnResult result = syncObject.Wait <ReturnResult>(null, 30000); //wait for response if (result == null) { throw new Exception("A timeout occured"); } if (result.ExceptionOccured) { throw new Exception(result.exceptionMessage); } if (result.ReturnValue == null) { throw new Exception("The shared class \"" + name + "\" could not be found in the remote client"); } SharedClass c = (SharedClass)result.ReturnValue; c.Client = this; InterfacePrototype tmp = DynClassCreator.CreateDynamicClass <InterfacePrototype>(c); InitializedClasses.Add(c.SharedId, c); return(tmp); } }
public void DisposeSharedClass(object SharedClass) { lock (InitializedClasses) { if (SharedClass == null) { throw new ArgumentNullException("SharedClass"); } Type type = SharedClass.GetType(); FieldInfo[] inf = type.GetFields(); if (inf.Length == 0) { throw new Exception("Invalid Shared Class"); } SharedClass shared = inf[0].GetValue(SharedClass) as SharedClass; if (shared == null) { throw new Exception("Invalid Shared Class"); } if (shared.IsDisposed) { return; } if (InitializedClasses.ContainsKey(shared.SharedId)) { InitializedClasses[shared.SharedId].IsDisposed = true; InitializedClasses[shared.SharedId].InitializedClass = null; InitializedClasses.Remove(shared.SharedId); } Send(new MsgDisposeClass(shared.SharedId)); } }