public void MethodA(string A, string B, System.Action<string> done) { var MethodA = new _MethodA { A = A, B = B }; var m = new Message { MethodA = MethodA }; this.Send(m, x => done(x.MethodA.ReturnValue)); }
public Message[] Invoke(Message[] e) { var a = new List<Message>(); foreach (Message v in e) { if (v.ToServerMessageId > 0) { this.Invoke(v); // going back a.Add(v); } else if (v.ToClientMessageId > 0) { this.RemoveToClientPending(v); // invoke smth } } var r = this.MarkPending(); if (r.Length > 0) { //Console.WriteLine(this.ClientName + " will recieve " + r.Length + " server messages"); a.AddRange(r); } return a.ToArray(); }
protected override void Send(Message m, System.Action<Message> done) { MessageId++; var x = new AsyncProxy.Info { m = m, done = done }; x.m.ToClientMessageId = MessageId; //Console.WriteLine("sending message with id : " + x.m.ToClientMessageId + " to " + this.ClientName); Queue.Add(x); }
void RemoveToClientPending(Message m) { foreach (AsyncProxy.Info v in Queue.ToArray()) { if (v.IsPending) if (v.m.ToClientMessageId == m.ToClientMessageId) { if (v.done != null) v.done(m); Queue.Remove(v); } } }
public Message[] Invoke(Message[] m, HttpListenerContext c) { Message[] v = null; lock (this) { CurrentContext = c; v = this.Invoke(m); CurrentContext = null; } return v; }
void Invoke(Message e) { var s = this; var x = from i in typeof(Message.IServer).GetMethods() let allfields = e.GetType().GetFields() let j = allfields.Single(xx => xx.Name == i.Name) let v = j.GetValue(e) where v != null select new {i, j, v}; foreach (var z in x) { MethodInfo zi = z.i; var xvt = z.v.GetType(); var pinfo = zi.GetParameters().Select(i => xvt.GetField(i.Name).GetValue(z.v)).ToArray(); ConsoleColor.DarkCyan.Use( delegate { Console.WriteLine("invoke: " + zi.Name); } ); object retval = null; try { retval = zi.Invoke(s, pinfo); } catch { throw; } var xrt = xvt.GetField(AsyncProxy.ReturnValue); if (xrt != null) xrt.SetValue(z.v, retval); } }
public void CreateExplosionByServer(int x, int y, string text, System.Action done) { var CreateExplosionByServer = new _CreateExplosionByServer { x = x, y = y, text = text}; var m = new Message { CreateExplosionByServer = CreateExplosionByServer }; this.Send(m, h => done()); }
protected virtual void Send(Message m, System.Action<Message> done) { }