Пример #1
0
        public ContextOrchestrator()
        {
            _ctx = TinyIoCContainer.Current.Resolve<Context>();
            var config = TinyIoCContainer.Current.Resolve<AppConfig>();

            _publishers = new List<socket>();
            _delegateDict = new Dictionary<string, DelegateInfo>();

            _interval = ParameterUtil.Get(config.parameters, "ContextSyncInterval", _interval);
            var msgTypes = GetMessageTypes(MessageNamespace);

            var subDict = new Dictionary<string, socket>();
            foreach (var node in config.nodes)
            {
                foreach (var subscriber in node.subscribers)
                {
                    if (!subDict.ContainsKey(subscriber.msg_type))
                    {
                        subDict.Add(subscriber.msg_type, subscriber);
                    }
                }
            }

            foreach (var node in config.nodes)
            {
                if (node.enabled)
                {
                    foreach (var publisher in node.publishers)
                    {
                        if (subDict.ContainsKey(publisher.msg_type))
                        {
                            var sock = new socket()
                            {
                                host = subDict[publisher.msg_type].host,
                                msg_type = publisher.msg_type,
                                name = publisher.name,
                                port = publisher.port,
                                topic = publisher.topic
                            };
                            _publishers.Add(sock);
                        }
                        else
                        {
                            continue;
                        }

                        if (!_delegateDict.ContainsKey(publisher.msg_type))
                        {
                            var typeFound =
                                msgTypes.FirstOrDefault(s => s.Name == publisher.msg_type);
                            if (typeFound != null)
                            {
                                var methods = typeof (Context).GetMethods();
                                foreach (var method in methods)
                                {
                                    if (method.Name != "Update") continue;
                                    var prms = method.GetParameters();
                                    if (prms.Length > 0)
                                    {
                                        var prmType = prms.FirstOrDefault(s => s.ParameterType == typeFound);
                                        if (prmType != null)
                                        {
                                            _delegateDict.Add(publisher.msg_type,
                                                new DelegateInfo()
                                                {
                                                    DelegateType = CreateDelegate(method, _ctx),
                                                    ArgType = typeFound
                                                });
                                            Log.InfoFormat("Create update delegate for Msg type {0}", publisher.msg_type);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            InitZmq();
        }
Пример #2
0
 public static bool LoadFromFile(string fileName, out socket obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
Пример #3
0
 public static bool Deserialize(string xml, out socket obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
Пример #4
0
 /// <summary>
 /// Deserializes xml markup from file into an socket object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output socket object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out socket obj, out System.Exception exception)
 {
     exception = null;
     obj = default(socket);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Пример #5
0
 /// <summary>
 /// Deserializes workflow markup into an socket object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output socket object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out socket obj, out System.Exception exception)
 {
     exception = null;
     obj = default(socket);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }