Ejemplo n.º 1
0
        public void AddConsumer(IStatsConsumer consumer)
        {
            if (consumer == null)
                return;

            _consumers[consumer.Name] = consumer;
        }
Ejemplo n.º 2
0
        public void AddConsumer(IStatsConsumer consumer)
        {
            if (consumer == null)
            {
                return;
            }

            _consumers[consumer.Name] = consumer;
        }
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            var configuration = new StatsSettings {
                IsEnabled = false
            };

            var doc = XDocument.Parse(section.OuterXml);

            var metric = doc.Element("StatsSettings");

            if (metric == null)
            {
                return(configuration);
            }

            var attribute = metric.Attribute("enabled");

            if (attribute != null)
            {
                configuration.IsEnabled = string.Equals(attribute.Value, "true", StringComparison.OrdinalIgnoreCase);
            }


            foreach (var consumer in metric.Elements("consumer"))
            {
                attribute = consumer.Attribute("name");
                if (attribute == null)
                {
                    continue;
                }

                var name = attribute.Value;

                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                attribute = consumer.Attribute("type");
                if (attribute == null)
                {
                    continue;
                }

                var type = attribute.Value;

                if (string.IsNullOrEmpty(type))
                {
                    continue;
                }

                IStatsConsumer consumer_obj = null;
                try
                {
                    Type consumer_type = Type.GetType(attribute.Value);
                    if (consumer_type != null)
                    {
                        consumer_obj = Activator.CreateInstance(consumer_type) as IStatsConsumer;
                    }
                }
                catch {}

                if (consumer_obj == null)
                {
                    continue;
                }

                consumer_obj.Name      = name;
                consumer_obj.IsEnabled = true;

                attribute = consumer.Attribute("enabled");
                if (attribute != null)
                {
                    consumer_obj.IsEnabled = string.Equals(attribute.Value, "true");
                }

                foreach (var setting in consumer.Elements("add").ToDictionary(x => x.Attribute("key").Value, v => v.Attribute("value").Value))
                {
                    consumer_obj.AddSettingProperty(setting.Key, setting.Value);
                }


                try
                {
                    consumer_obj.Configure();
                    configuration.AddConsumer(consumer_obj);
                }
                catch { }
            }

            return(configuration);
        }