static void runTestNode() { var node = new Node("0.0.0.0:8883", "127.0.0.1:1890"); var pipeline = node.sys.GetPipeline(null, "this/node"); while (pipeline.IsVaild) { var line = Console.ReadLine(); if (string.IsNullOrEmpty(line) == false) { if (line == "exit") { break; } var cmds = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); var dict = new MsgPack.MessagePackObjectDictionary(); dict["cmd"] = (UInt16)AllPet.Module.CmdList.Local_Cmd; var list = new MsgPack.MessagePackObject[cmds.Length]; for (var i = 0; i < cmds.Length; i++) { list[i] = cmds[i]; } dict["params"] = list; pipeline.Tell(new MsgPack.MessagePackObject(dict)); } } node.sys.Dispose(); }
public static async Task Test() { var system = AllPet.Pipeline.PipelineSystem.CreatePipelineSystemV1(new AllPet.Common.Logger()); system.RegistModule("hello", new Hello()); //actor习惯,连注册这个活都丢线程池,我这里简化一些 system.RegistModule("hello2", new Hello2()); //actor习惯,连注册这个活都丢线程池,我这里简化一些 system.Start(); var actor = system.GetPipeline(null, "this/hello"); { var dict = new MsgPack.MessagePackObjectDictionary(); dict["abc"] = 1; dict["aaa"] = "hello world."; var list = new MsgPack.MessagePackObject[] { "heelo", "hello", "hello" }; dict["array"] = list; var obj = new MsgPack.MessagePackObject(dict); actor.Tell(obj); } while (true) { Console.Write("5.localobj>"); var line = Console.ReadLine(); if (line == "exit") { //不能这样粗暴关闭的,关闭应该由actor内部发起 system.Dispose(); break; } MsgPack.MessagePackObject obj = new MsgPack.MessagePackObject[] { "heelo", "hello", "hello" };; actor.TellLocalObj(obj); } }
private static MsgPack.MessagePackObject? TryGetValueFromDictionary(MsgPack.MessagePackObjectDictionary dict, string key) { if (dict.TryGetValue(key, out var value)) { return(value); } return(null); }
static MapAttr convertFromMsgPackObjectDictionary(MsgPack.MessagePackObjectDictionary mpobj) { MapAttr t = new MapAttr(); MsgPack.MessagePackObjectDictionary.Enumerator e = mpobj.GetEnumerator(); while (e.MoveNext()) { MsgPack.MessagePackObject key = e.Current.Key; MsgPack.MessagePackObject val = e.Current.Value; t.put(key.AsString(), convertFromMsgPackObject(val)); } return(t); }
void NodeCmd(string[] words = null) { var pipeline = this.GetPipeline("this/node"); var dict = new MsgPack.MessagePackObjectDictionary(); dict["cmd"] = (UInt16)AllPet.Module.CmdList.Local_Cmd; var list = new MsgPack.MessagePackObject[words.Length - 1]; for (var i = 1; i < words.Length; i++) { list[i - 1] = words[i]; } dict["params"] = list; pipeline.Tell(new MsgPack.MessagePackObject(dict)); }
static MsgPack.MessagePackObject convertToMsgPackObject(object v) { Type t = v.GetType(); if (t.Equals(typeof(MapAttr))) { MapAttr ht = v as MapAttr; IDictionaryEnumerator e = ht.GetEnumerator(); MsgPack.MessagePackObjectDictionary d = new MsgPack.MessagePackObjectDictionary(); while (e.MoveNext()) { d.Add(new MsgPack.MessagePackObject(e.Key as string), convertToMsgPackObject(e.Value)); } return(new MsgPack.MessagePackObject(d)); } else if (t.Equals(typeof(ListAttr))) { ListAttr al = v as ListAttr; IEnumerator e = al.GetEnumerator(); System.Collections.Generic.IList <MsgPack.MessagePackObject> l = new System.Collections.Generic.List <MsgPack.MessagePackObject>(); while (e.MoveNext()) { l.Add(convertToMsgPackObject(e.Current)); } return(new MsgPack.MessagePackObject(l)); } else if (t.Equals(typeof(bool))) { return(new MsgPack.MessagePackObject((bool)v)); } else if (t.Equals(typeof(string))) { return(new MsgPack.MessagePackObject((string)v)); } else { Debug.Assert(false, "Unknwon type: " + t.Name); return(new MsgPack.MessagePackObject()); } }
static void Main(string[] args) { logger = new AllPet.Common.Logger(); logger.Warn("Allpet.Node v0.001 Peer 01"); var config = new Config(logger); //init current path. //把当前目录搞对,怎么启动都能找到dll了 var lastpath = System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location);; Console.WriteLine("exepath=" + lastpath); Environment.CurrentDirectory = lastpath; var system = AllPet.Pipeline.PipelineSystem.CreatePipelineSystemV1(new AllPet.Common.Logger()); var config_node = config.GetJson("config.json", ".ModulesConfig.Node") as JObject; if (Config.IsOpen(config_node)) { system.RegistModule("node", new AllPet.Module.Module_Node(logger, config_node)); } else { logger.Error("cant find config for node"); return; } system.OpenNetwork(new AllPet.peer.tcp.PeerOption() { }); var endpoint = config.GetIPEndPoint("config.json", ".ListenEndPoint"); if (endpoint != null && endpoint.Port != 0) { try { system.OpenListen(endpoint); } catch (Exception err) { logger.Error("listen error:" + err.ToString()); } } system.Start(); //等待cli结束才退出 var pipeline = system.GetPipeline(null, "this/node"); while (pipeline.IsVaild) { var line = Console.ReadLine(); if (string.IsNullOrEmpty(line) == false) { if (line == "exit") { break; } var cmds = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); var dict = new MsgPack.MessagePackObjectDictionary(); dict["cmd"] = (UInt16)AllPet.Module.CmdList.Local_Cmd; var list = new MsgPack.MessagePackObject[cmds.Length]; for (var i = 0; i < cmds.Length; i++) { list[i] = cmds[i]; } dict["params"] = list; pipeline.Tell(new MsgPack.MessagePackObject(dict)); } } system.Dispose(); }