void Write(IRpcMail mail, string name, string type, object[] args) { var str = string.Format(DateTime.Now + " " + name + "[" + type + "] " + args.ToDelimitedString()); Console.WriteLine(str); lock(writer) writer.WriteLine(str); }
public void Call(IRpcMail mail) { var func = GetFunction(mail); if (func == null) return; var args = ConvertParams(mail, func.Item2); func.Item2.Call(func.Item1, args); }
private Tuple<object, MethodInfo> GetFunction(IRpcMail mail) { Tuple<object, MethodInfo> func; if (!functions.TryGetValue(mail.Message.Name, out func) || mail.Message.Args.Length != func.Item2.GetParameters().Length - 1) return null; return func; }
private static object[] ConvertParams(IRpcMail mail, MethodInfo func) { var p = func.Parameters(); var args = new object[p.Count]; args[0] = mail; for (int i = 0; i < mail.Message.Args.Length; i++) args[i + 1] = ConvertEx.Convert(mail.Message.Args[i], p[i + 1].ParameterType); return args; }
void GetProcesses(IRpcMail mail) { log.Info("GetProcesses " + mail.From); var actors = Node.World.Actors .Select(n=> new ActorInfo{ Id = n.Id, IsAlive = n.IsAlive, }) .OrderBy(n=>n.IsAlive) .ThenBy(n=>n.Id) .ToArray(); Node.Reply(mail, new[]{actors}); }
void GetConnections(IRpcMail mail) { log.Info("GetConnections " + mail.From); var conn = Node.Router.Connections.ToArray(n=>n.ToString()); Node.Reply(mail, new[]{conn}); }
void Subscribe(IRpcMail mail, Expression<Func<IRpcMail, bool>> subscribe) { }
protected override void HandleMessage(IRpcMail mail) { base.HandleMessage (mail); }