Ejemplo n.º 1
0
        public static CustomConfigAttribute CreateConfigAttribute(params string[] values)
        {
            CustomConfigAttribute conf = new CustomConfigAttribute();
            var properties             = typeof(CustomConfigAttribute).GetProperties();

            for (int x = 0; x < values.Length; x++)
            {
                switch (properties[x].Name)
                {
                case nameof(Host):
                    conf.Host = values[x];
                    break;

                case nameof(Interval):
                    conf.Interval = values[x];
                    break;

                case nameof(Protocol):
                    conf.Protocol = values[x];
                    break;

                case nameof(HttpCode):
                    conf.HttpCode = values[x];
                    break;
                }
            }
            return(conf);
        }
Ejemplo n.º 2
0
        private static Dictionary <int, PingerModule.IPinger> GetProtocolsFromConfig(CustomConfigAttribute attribute)
        {
            if (ListProtocols.Any())
            {
                ListProtocols.Clear();
            }
            if (_rootNode == null)
            {
                return(null);
            }
            var items =
                _rootNode.Elements(DataConfiguration)
                .Select(
                    x =>
                    new CustomConfigAttribute()
            {
                Host     = x.Element(nameof(CustomConfigAttribute.Host))?.Value,
                Interval = x.Element(nameof(CustomConfigAttribute.Interval))?.Value,
                Protocol = x.Element(nameof(CustomConfigAttribute.Protocol))?.Value,
                Port     = x.Element(nameof(CustomConfigAttribute.Port))?.Value,
                HttpCode = x.Element(nameof(CustomConfigAttribute.HttpCode))?.Value
            }).ToList();

            for (int x = 0; x < items.Count(); x++)
            {
                ListProtocols.Add(x, ProtocolCreator.CreateProtocol(items[x]));
            }
            return(ListProtocols);
        }
Ejemplo n.º 3
0
        public static CustomConfigAttribute CreateConfigAttribute(Array values)
        {
            CustomConfigAttribute confAttr = new CustomConfigAttribute();
            var properties = confAttr.GetType().GetProperties();
            int index      = 0;

            foreach (var val in values)
            {
                properties.SetValue(val, index);
                index++;
            }
            return(confAttr);
        }
Ejemplo n.º 4
0
 public Boolean SaveInConfig(params string[] values)
 {
     if (!values.Any())
     {
         return(false);
     }
     else
     {
         CustomConfigAttribute at = CustomConfigAttribute.CreateConfigAttribute(values);
         SaveInConfig(at);
         return(true);
     }
 }
Ejemplo n.º 5
0
        private void SaveInConfig(CustomConfigAttribute attribute)
        {
            if (_rootNode == null)
            {
                return;
            }
            XElement dataConfiguration = new XElement(DataConfiguration);

            dataConfiguration.Add(new XElement(nameof(attribute.Host), attribute.Host, new XAttribute("Name", CustomConfigAttribute.GetValueAttribute(nameof(attribute.Host) ?? ""))),
                                  new XElement(nameof(attribute.Interval), attribute.Interval, new XAttribute("Name", CustomConfigAttribute.GetValueAttribute(nameof(attribute.Interval) ?? ""))),
                                  new XElement(nameof(attribute.Protocol), attribute.Protocol, new XAttribute("Name", CustomConfigAttribute.GetValueAttribute(nameof(attribute.Protocol) ?? ""))));
            if (attribute.HttpCode != null)
            {
                dataConfiguration.Add(new XElement(nameof(attribute.HttpCode), attribute.HttpCode, new XAttribute("Name", CustomConfigAttribute.GetValueAttribute(nameof(attribute.HttpCode) ?? ""))));
            }
            else
            if (attribute.Port != null)
            {
                dataConfiguration.Add(new XElement(nameof(attribute.Port), attribute.Port, new XAttribute("Name", CustomConfigAttribute.GetValueAttribute(nameof(attribute.Port) ?? ""))));
            }
            _rootNode.Add(dataConfiguration);
            _rootNode.Save(ConfigFileName);
            Refresh?.Invoke(this, new EventArgs());
        }