//method called when the asynchronous method is complete public static void TheCallBack(IAsyncResult result) { RemoteMethodDelegate remDel = (RemoteMethodDelegate)((AsyncResult)result).AsyncDelegate; IRemoteObject output = remDel.EndInvoke(result); Console.WriteLine(output.Name); }
/// <summary> /// /// </summary> /// <param name="parameters"></param> public static void GetItemList(object parameters) { if (Items.Count == 0) { if (_wwwObject == null) { _wwwObject = Gateway.GetSender(shopGateway); } _wwwObject.Call(ServerClass, GetListMethod, new Hashtable { { KeyParameters, parameters } }, OnRecivedItemlist); } else { OnRecivedItemlist(new Hashtable { { KeyList, Items }, { KeyParameters, parameters } } ); } }
static void Main(string[] args) { HttpChannel channel = new HttpChannel(); ChannelServices.RegisterChannel(channel); Console.WriteLine("Acqu. Rem. Instance"); IRemoteFactory fact = (IRemoteFactory)Activator.GetObject( typeof(IRemoteFactory), "http://localhost:1234/factory.soap"); Console.WriteLine("Client.Main(): Acquiring object from factory"); IRemoteObject obj1 = fact.getNewInstance(); Console.WriteLine("Client.Main(): Sleeping one second"); System.Threading.Thread.Sleep(1000); Console.WriteLine("Client.Main(): Setting value"); try { obj1.setValue(42); } catch (Exception e) { Console.WriteLine("Client.Main(). EXCEPTION \n{0}", e.Message); } Console.ReadLine(); }
static void Main(string[] args) { //configure remoting - only needed for factory method RemotingConfiguration.Configure("client.exe.config"); //use activation IRemoteObject iro = (IRemoteObject)Activator.GetObject(typeof(IRemoteObject), "tcp://localhost:8085/RemoteObjects/RemoteImplementation.rem"); Console.WriteLine(iro.Name); //Use Factory BusinessObjectFactories.RemoteObjectFactory rof = new BusinessObjectFactories.RemoteObjectFactory(); IRemoteObject iro2 = rof.GetRemoteObject(); Console.WriteLine(iro2.Name); //Asynchronous remote method call AsyncCallback RemoteCallback = new AsyncCallback(TheCallBack); RemoteMethodDelegate remDelegate = new RemoteMethodDelegate(rof.GetRemoteObject); IAsyncResult RemAr = remDelegate.BeginInvoke(RemoteCallback, null); //do work here while the asynchronous method executes //wait for the asynchronous method to finish RemAr.AsyncWaitHandle.WaitOne(); Console.WriteLine("Press 'Enter' to exit"); Console.ReadLine(); }
private object ValueFromUnserializableValue(IRemoteObject remoteObject, string unserializableValue) { if ( remoteObject.Type == RemoteObjectType.Bigint && decimal.TryParse(remoteObject.UnserializableValue.Replace("n", string.Empty), out decimal decimalValue)) { return(new BigInteger(decimalValue)); } switch (unserializableValue) { case "-0": return(-0); case "NaN": return(double.NaN); case "Infinity": return(double.PositiveInfinity); case "-Infinity": return(double.NegativeInfinity); default: throw new PlaywrightSharpException("Unsupported unserializable value: " + unserializableValue); } }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { RegistrationRequest registrationRequest = request as RegistrationRequest; ServerSideTokenIdentity identity = token.info as ServerSideTokenIdentity; try { if (identity.LastlyFetchedUser != null) { return(new RegistrationResponse { Successfulness = false, Message = "Ne mozes se registrovati dok si ulogovan" }); } UserLogic.RegisterUser(registrationRequest.Username, registrationRequest.Password); return(new RegistrationResponse { Successfulness = true }); } catch (InvalidLogicDataException e) { return(new RegistrationResponse { Successfulness = false, Message = e.Message }); } }
private CallFunctionArgument ToCallArgument(IRemoteObject remoteObject) => new CallFunctionArgument { Value = remoteObject.Value, UnserializableValue = RemoteObject.GetUnserializableValueFromRaw(remoteObject.UnserializableValue), ObjectId = remoteObject.ObjectId, };
private static void SendQuit() { if (_www == null) { _www = Gateway.GetSender(chatGateway); } _www.Call(targetClassName, quitMessageName, null); _querySended = false; }
private static void SendChangeRoom(int newRoomId) { _querySended = true; if (_www == null) { _www = Gateway.GetSender(chatGateway); } _www.Call(targetClassName, changeRoomName, newRoomId, RecivedRoom); }
internal override IJSHandle CreateHandle(IRemoteObject remoteObject) { if (Frame.Page.Delegate.IsElementHandle(remoteObject)) { return(new ElementHandle(this, remoteObject)); } return(base.CreateHandle(remoteObject)); }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { var queueResponse = request as QueueExitResponse; Console.WriteLine("Odgovor na zahtev za izlazak iz reda:"); Console.WriteLine($"Uspesnost: {queueResponse.Successfulness}\nPoruka: {queueResponse.Message}"); return(null); }
private static void SendEntry(Hashtable info) { _querySended = true; if (_www == null) { _www = Gateway.GetSender(chatGateway); } _www.Call(targetClassName, entryMethodName, info, RecivedEntry); }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { LoginResponse loginResponse = request as LoginResponse; Console.WriteLine("Odgovor na zahtev za prijavljivanje:"); Console.WriteLine($"Uspesnost: {loginResponse.Successfulness}\nPoruka: {loginResponse.Message}"); return(null); }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { CardListRequest cardListRequest = request as CardListRequest; if (cardListRequest.Version == null || cardListRequest.Version != m_cardList.Vesion) { return(m_newListResponse); } return(m_upToDateResponse); }
private void HandleRequest(MessageWrapper messageWrapper) { IRemoteObject request = SeriabilityUtils.ByteArrayToObject <IRemoteObject>(messageWrapper.Message); IRemoteObject response = GetRequestMapper().Handle(messageWrapper.UserToken, request); if (response != null) { Sender.Send(messageWrapper.UserToken, response); } }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { try { GAME_MANAGER.MarkUserAsReadyForGame(token); } catch (MatchmakingException ex) { Console.WriteLine("Matchmaking exception while marking as ready: " + ex.Message); } return(null); }
private static void SendChat(ChatMessage msg) { if (_chatEntries) { _querySended = true; msg.id = _lastMessageId; if (_www == null) { _www = Gateway.GetSender(chatGateway); } _www.Call(targetClassName, chatMessageName, msg, RecivedChat); } }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <param name="userLogin"></param> /// <param name="userPassword"></param> /// <param name="info"></param> /// <param name="gateway"></param> public static void Register(string userName, string userLogin, string userPassword, Dictionary <string, string> info, GatewayType gateway) { SendedRequest = true; var ht = new Hashtable { { KeyName, userName }, { KeyLogin, userLogin }, { KeyPassword, userPassword }, { KeyData, info } }; if (_www == null) { _www = Gateway.GetSender(gateway); } _www.Call(ServerClass, RegisterMethod, ht, OnReg); }
/// <summary> /// Start logout.You can set additional info for send to server. You can set gateway /// </summary> /// <param name="userId"></param> /// <param name="data"></param> /// <param name="gateway"></param> public static void Logout(int userId, Dictionary <string, object> data, GatewayType gateway) { SendedRequest = true; var ht = new Hashtable { { KeyId, userId }, { KeyData, data } }; if (_www == null) { _www = Gateway.GetSender(gateway); } _www.Call(ServerClass, LogoutMethod, ht, OnOut); }
public void DoSomething(IRemoteObject usethis) { Console.WriteLine("MyWorkerObject.doSomething(): called"); Console.WriteLine("MyWorkerObject.doSomething(): Will now call " + "getValue() on the remote obj."); int tmp = usethis.GetValue(); Console.WriteLine("MyWorkerObject.doSomething(): current value of " + "the remote obj.; {0}", tmp); Console.WriteLine("MyWorkerObject.doSomething(): changing value to 70"); usethis.SetValue(70); }
static void Main(string[] args) { String filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; RemotingConfiguration.Configure(filename); IRemoteFactory fact = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory)); IRemoteObject cao = fact.CreateInstance(); IRemoteSponsorFactory sf = (IRemoteSponsorFactory)RemotingHelper.CreateProxy(typeof(IRemoteSponsorFactory)); InstanceSponsor sp = sf.CreateSponsor(); EnsureKeepAlive keepalive = new EnsureKeepAlive(sp); ILease le = (ILease)((MarshalByRefObject)cao).GetLifetimeService(); le.Register(sp); try { Console.WriteLine("{0} CLIENT: Calling DoSomething()", DateTime.Now); cao.DoSomething(); } catch (Exception e) { Console.WriteLine(" --> EX: Timeout in first call\n{0}", e.Message); } Console.WriteLine("{0} CLIENT: Sleeping for 6 seconds", DateTime.Now); Thread.Sleep(6000); try { Console.WriteLine("{0} CLIENT: Calling DoSomething()", DateTime.Now); cao.DoSomething(); } catch (Exception e) { Console.WriteLine(" --> EX: Timeout in second call\n{0}", e.Message); } Console.WriteLine("{0} CLIENT: Unregistering sponsor", DateTime.Now); le.Unregister(sp); keepalive.StopKeepAlive(); Console.WriteLine("Finished ... press <return> to exit"); Console.ReadLine(); Console.ReadLine(); }
public static void ServerSide() { Console.WriteLine("ServerSide...."); TcpChannel ch2 = (TcpChannel)Helper.GetChannel(2233, true); ChannelServices.RegisterChannel(ch2, false); IRemoteObject objRemoteRef = (IRemoteObject)Activator.GetObject( typeof(IRemoteObject), "tcp://127.0.0.1:2333/M"); while (true) { string x = Console.ReadLine(); objRemoteRef.GetData(x); } }
/// <summary> /// Start login/captcha verification. You can send additional parameters and gateway. /// </summary> /// <param name="login"></param> /// <param name="password"></param> /// <param name="captcha"></param> /// <param name="data"></param> /// <param name="gateway"></param> public static void Login(string login, string password, string captcha, Dictionary <string, object> data, GatewayType gateway) { SendedRequest = true; var ht = new Hashtable { { KeyLogin, login }, { KeyPassword, password }, { KeyCaptcha, captcha }, { KeyData, data } }; if (_www == null) { _www = Gateway.GetSender(gateway); } _www.Call(ServerClass, LoginMethod, ht, OnLog); }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject remoteObject) { Dictionary <Type, RequestHandler> handleMapper = GetMapperDictionary(); if (handleMapper == null) { throw new InvalidOperationException(); } RequestHandler handler; if (handleMapper.TryGetValue(remoteObject.GetType(), out handler)) { return(handler.Handle(token, remoteObject)); } return(InvalidTypeRepsonse(remoteObject)); }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { CardListResponse cardListResponse = request as CardListResponse; if (cardListResponse.UpToDate) { Console.WriteLine("Imam najnoviju verziju!"); } else { CardList cardList = cardListResponse.CardList; Console.WriteLine("Stigla nova lista karata, verzija: " + cardList.Vesion); } return(null); }
private void _loadType(Assembly asm) { Type type = asm.GetTypes().FirstOrDefault(t => typeof(IRemoteObject).IsAssignableFrom(t) && t.IsClass); if (type == default(Type)) { throw new Exception("Failed to load remote type in " + asm.FullName); } else { _instance = Activator.CreateInstance(type) as IRemoteObject; if (_instance == null) { throw new Exception("Failed to create class instance for " + asm.FullName); } } }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { #if UNITY_EDITOR try { #endif Handle(request as T); #if UNITY_EDITOR } catch (Exception e) { executionQueue.Add(() => Debug.Log("Izuzetak: " + e.Message)); } #endif return(null); }
public void RunTestComplexParamsInOut(IRemoteObject testerSurrogate) { ArrayList list = new ArrayList(); list.Add(new Complex(11, "first")); list.Add(new Complex(22, "second")); byte[] bytes = new byte [100]; for (byte n = 0; n < 100; n++) { bytes[n] = n; } StringBuilder sb = new StringBuilder("hello from client"); Complex c; Complex r = testerSurrogate.ComplexParamsInOut(ref list, out c, bytes, sb, "third"); Assert.IsNotNull(r, "ReturnValue is null"); Assert.IsNotNull(c, "c is null"); Assert.IsNotNull(list, "list is null"); Assert.IsTrue(list.Count == 3, "Invalid list count"); Assert.IsNotNull(list[0], "list[0] is null"); Assert.IsNotNull(list[1], "list[1] is null"); Assert.IsNotNull(list[2], "list[2] is null"); Assert.IsNotNull(bytes, "bytes is null"); Assert.IsNotNull(sb, "sb is null"); Assert.AreEqual(33, r.Id, "ReturnValue.Id"); Assert.AreEqual("third@" + remoteDomId, r.Name, "ReturnValue.Name"); Assert.AreEqual(33, c.Id, "c.Id"); Assert.AreEqual("third@" + remoteDomId, c.Name, "c.Name"); Assert.AreEqual(33, ((Complex)list[2]).Id, "list[2].Id"); Assert.AreEqual("third@" + remoteDomId, ((Complex)list[2]).Name, "list[2].Name"); Assert.AreEqual(22, ((Complex)list[1]).Id, "list[1].Id"); Assert.AreEqual("second", ((Complex)list[1]).Name, "list[1].Name"); Assert.AreEqual(11, ((Complex)list[0]).Id, "list[0].Id"); Assert.AreEqual("first", ((Complex)list[0]).Name, "list[0].Name"); Assert.AreEqual("hello from client", sb.ToString(), "sb"); for (int n = 0; n < 100; n++) { Assert.AreEqual(n + 1, bytes[n], "bytes[" + n + "]"); } }
private object GetValueFromRemoteObject <T>(IRemoteObject remoteObject) { string unserializableValue = remoteObject.UnserializableValue; if (unserializableValue != null) { return(ValueFromUnserializableValue(remoteObject, unserializableValue)); } object value = remoteObject.Value; if (value == null) { return(default(T)); } return(((JsonElement)remoteObject.Value).ToObject <T>()); }
public IRemoteObject Handle(AsyncUserToken token, IRemoteObject request) { LoginRequest loginRequest = request as LoginRequest; ServerSideTokenIdentity identity = token.info as ServerSideTokenIdentity; try { return(TryToLogin(identity, loginRequest.Username, loginRequest.Password)); } catch (InvalidLogicDataException e) { return(new LoginResponse { Successfulness = false, Message = e.Message }); } }
public void RunTestComplexParams (IRemoteObject testerSurrogate) { ArrayList list = new ArrayList (); list.Add (new Complex (11,"first")); Complex c = new Complex (22,"second"); Complex r = testerSurrogate.ComplexParams (list, c, "third"); Assert.IsNotNull (r, "ReturnValue is null"); Assert.IsNotNull (r.Child, "ReturnValue.Child is null"); Assert.IsNotNull (r.Child.Child, "ReturnValue.Child.Child is null"); Assert.AreEqual (33, r.Id, "ReturnValue.Id"); Assert.AreEqual ("third@"+remoteDomId, r.Name, "ReturnValue.Name"); Assert.AreEqual (22, r.Child.Id, "ReturnValue.Child.Id"); Assert.AreEqual ("second", r.Child.Name, "ReturnValue.Child.Name"); Assert.AreEqual (11, r.Child.Child.Id, "ReturnValue.Child.Child.Id"); Assert.AreEqual ("first", r.Child.Child.Name, "ReturnValue.Child.Child.Name"); }
public void RunTestProcessContextData (IRemoteObject testerSurrogate) { CallContext.FreeNamedDataSlot ("clientData"); CallContext.FreeNamedDataSlot ("serverData"); CallContext.FreeNamedDataSlot ("mustNotPass"); // First step ContextData cdata = new ContextData (); cdata.data = "hi from client"; cdata.id = 1123; cdata.testStep = 1; CallContext.SetData ("clientData", cdata); CallContext.SetData ("mustNotPass", "more data"); testerSurrogate.ProcessContextData (); cdata = CallContext.GetData ("clientData") as ContextData; Assert.IsNotNull (cdata, "clientData is null"); Assert.AreEqual ("hi from client", cdata.data, "clientData.data"); Assert.AreEqual (1123, cdata.id, "clientData.id"); cdata = CallContext.GetData ("serverData") as ContextData; Assert.IsNotNull (cdata, "serverData is null"); Assert.AreEqual ("hi from server", cdata.data, "serverData.data"); Assert.AreEqual (3211, cdata.id, "serverData.id"); string mdata = CallContext.GetData ("mustNotPass") as string; Assert.IsNotNull (mdata, "mustNotPass is null"); Assert.AreEqual ("more data", mdata, "mustNotPass"); // Second step. Test that exceptions return the call context. CallContext.FreeNamedDataSlot ("clientData"); CallContext.FreeNamedDataSlot ("serverData"); cdata = new ContextData (); cdata.data = "hi from client"; cdata.id = 1123; cdata.testStep = 2; CallContext.SetData ("clientData", cdata); try { testerSurrogate.ProcessContextData (); Assert.IsTrue (false, "Exception not thrown"); } catch (Exception ex) { if (ex.InnerException != null) ex = ex.InnerException; if (ex.Message != "exception from server") throw; } cdata = CallContext.GetData ("clientData") as ContextData; Assert.IsNotNull (cdata, "clientData is null (2)"); Assert.AreEqual ("hi from client", cdata.data, "clientData.data (2)"); Assert.AreEqual (1123, cdata.id, "clientData.id (2)"); mdata = CallContext.GetData ("mustNotPass") as string; Assert.IsNotNull (mdata, "mustNotPass is null"); Assert.AreEqual ("more data", mdata, "mustNotPass"); }
// // The tests runners // public void RunTestSimple (IRemoteObject testerSurrogate) { Assert.AreEqual (130772 + remoteDomId, testerSurrogate.Simple (), "ReturnValue"); }
public void RunTestPrimitiveParams (IRemoteObject testerSurrogate) { Assert.AreEqual ("11-22-L-SG@"+remoteDomId, testerSurrogate.PrimitiveParams (11, 22, 'L', "SG"), "ReturnValue"); }
public void RunTestPrimitiveParamsInOut (IRemoteObject testerSurrogate) { int a2, a1 = 9876543; float b2, b1 = 82437.83f; char c2, c1 = 's'; string d2, d1 = "asdASDzxcZXC"; string res = testerSurrogate.PrimitiveParamsInOut (ref a1, out a2, ref b1, out b2, 9821, ref c1, out c2, ref d1, out d2); Assert.AreEqual ("9876543-82437.83-s-asdASDzxcZXC@" + remoteDomId, res, "ReturnValue"); Assert.AreEqual (12345678, a2, "a2"); Assert.AreEqual (53455.345f, b2, "b2"); Assert.AreEqual ('g', c2, "c2"); Assert.AreEqual ("sfARREG$5345DGDfgY7656gDFG>><<dasdasd", d2, "d2"); Assert.AreEqual (65748392, a1, "a1"); Assert.AreEqual (98395.654f, b1, "b1"); Assert.AreEqual ('l', c1, "c1"); Assert.AreEqual ("aasbasbdyhasbduybo234243", d1, "d1"); }
public void RunTestComplexParamsInOut (IRemoteObject testerSurrogate) { ArrayList list = new ArrayList (); list.Add (new Complex (11,"first")); list.Add (new Complex (22,"second")); byte[] bytes = new byte [100]; for (byte n=0; n<100; n++) bytes[n] = n; StringBuilder sb = new StringBuilder ("hello from client"); Complex c; Complex r = testerSurrogate.ComplexParamsInOut (ref list, out c, bytes, sb, "third"); Assert.IsNotNull (r, "ReturnValue is null"); Assert.IsNotNull (c, "c is null"); Assert.IsNotNull (list, "list is null"); Assert.IsTrue (list.Count == 3, "Invalid list count"); Assert.IsNotNull (list[0], "list[0] is null"); Assert.IsNotNull (list[1], "list[1] is null"); Assert.IsNotNull (list[2], "list[2] is null"); Assert.IsNotNull (bytes, "bytes is null"); Assert.IsNotNull (sb, "sb is null"); Assert.AreEqual (33, r.Id, "ReturnValue.Id"); Assert.AreEqual ("third@"+remoteDomId, r.Name, "ReturnValue.Name"); Assert.AreEqual (33, c.Id, "c.Id"); Assert.AreEqual ("third@"+remoteDomId, c.Name, "c.Name"); Assert.AreEqual (33, ((Complex)list[2]).Id, "list[2].Id"); Assert.AreEqual ("third@"+remoteDomId, ((Complex)list[2]).Name, "list[2].Name"); Assert.AreEqual (22, ((Complex)list[1]).Id, "list[1].Id"); Assert.AreEqual ("second", ((Complex)list[1]).Name, "list[1].Name"); Assert.AreEqual (11, ((Complex)list[0]).Id, "list[0].Id"); Assert.AreEqual ("first", ((Complex)list[0]).Name, "list[0].Name"); Assert.AreEqual ("hello from client and from server", sb.ToString (), "sb"); for (int n=0; n<100; n++) Assert.AreEqual (n+1, bytes[n], "bytes["+n+"]"); }
public void RunTestProcessContextData (IRemoteObject testerSurrogate) { CallContext.FreeNamedDataSlot ("clientData"); CallContext.FreeNamedDataSlot ("serverData"); CallContext.FreeNamedDataSlot ("mustNotPass"); ContextData cdata = new ContextData (); cdata.data = "hi from client"; cdata.id = 1123; CallContext.SetData ("clientData", cdata); CallContext.SetData ("mustNotPass", "more data"); testerSurrogate.ProcessContextData (); cdata = CallContext.GetData ("clientData") as ContextData; Assert.IsNotNull (cdata, "clientData is null"); Assert.AreEqual ("hi from client", cdata.data, "clientData.data"); Assert.AreEqual (1123, cdata.id, "clientData.id"); cdata = CallContext.GetData ("serverData") as ContextData; Assert.IsNotNull (cdata, "serverData is null"); Assert.AreEqual ("hi from server", cdata.data, "serverData.data"); Assert.AreEqual (3211, cdata.id, "serverData.id"); string mdata = CallContext.GetData ("mustNotPass") as string; Assert.IsNotNull (mdata, "mustNotPass is null"); Assert.AreEqual ("more data", mdata, "mustNotPass"); }