Ejemplo n.º 1
0
        public static void Init()
        {
            Consumers = new Dictionary <string, Type>();
            Queues    = new List <DACTaskResultConsumerQueue>();
            if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + " \\consumers.xml"))
            {
                try {
                    var doc           = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "\\consumers.xml");
                    var consumerNodes = doc.Root.Element("consumers").Elements();
                    foreach (var node in consumerNodes)
                    {
                        var consumerName = node.Attribute("name").Value;
                        var assembly     = node.Attribute("assembly").Value;
                        var consumerType = node.Attribute("type").Value;
                        var type         = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "\\" + assembly).GetType(consumerType);

                        RegisterConsumer(consumerName, type);
                    }

                    var queuesNodes = doc.Root.Element("queues").Elements("queue");
                    int num         = 0;
                    foreach (var node in queuesNodes)
                    {
                        var consumeType = (node.Attribute("sync") == null || node.Attribute("sync").Value == "true")
                                                          ? ConsumeType.Sync
                                                          : ConsumeType.Async;

                        var queue      = new DACTaskResultConsumerQueue(consumeType);
                        var queueNodes = node.Elements();
                        var consumers  = new List <string>();
                        foreach (var qn in queueNodes)
                        {
                            var name             = qn.Attribute("name").Value;
                            var consumer         = GetConsumer(name);
                            var sensorTypeFilter = qn.Attribute("sensorType");
                            if (sensorTypeFilter != null)
                            {
                                var filterStr       = sensorTypeFilter.Value.Split(',');
                                List <SensorType> l = new List <SensorType>();
                                foreach (var s in filterStr)
                                {
                                    SensorType st;
                                    if (!Enum.TryParse(s.Trim(), true, out st))
                                    {
                                        Log.Warn("queue " + name + " sensorType invalid." + sensorTypeFilter);
                                        break;
                                    }
                                    l.Add(st);
                                }

                                consumer.SensorTypeFilter = l.ToArray();
                            }
                            queue.Enqueue(consumer);
                            consumers.Add(name);
                        }

                        Queues.Add(queue);
                        Log.Debug("queue_" + ++num + ":" + string.Join(",", consumers));
                    }
                } catch (Exception e) {
                    Log.Warn("consumer.xml parse error", e);
                }
            }
            else
            {
                Log.Warn("consumer.xml not found");
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 添加消费者队列(各消费队列之间是并行的)
 /// </summary>
 /// <param name="queue"></param>
 public static void AddComsumerQueue(DACTaskResultConsumerQueue queue)
 {
     Queues.Add(queue);
 }