public static bool TryUpdate(DroneConfiguration configuration, ConfigurationPacket packet)
        {
            Regex _reKeyValue = new Regex(@"(?<key>\w+:\w+) = (?<value>.*)");
            bool updated = false;
            using (var ms = new MemoryStream(packet.Data))
            using (var sr = new StreamReader(ms))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    Match match = _reKeyValue.Match(line);
                    if (match.Success)
                    {
                        string key = match.Groups["key"].Value;
                        string value = match.Groups["value"].Value;

                        if (configuration.Items.ContainsKey(key))
                            configuration.Items[key] = value;
                        else
                            configuration.Items.Add(key, value);
                    }
                }
            }
            return updated;
        }
 public static bool TryUpdate(DroneConfiguration configuration, ConfigurationPacket packet)
 {
     Regex _reKeyValue = new Regex(@"(?<key>\w+:\w+) = (?<value>.*)");
     bool updated = false;
     using (var ms = new MemoryStream(packet.Data))
     using (var sr = new StreamReader(ms))
     {
         string line;
         while ((line = sr.ReadLine()) != null)
         {
             Match match = _reKeyValue.Match(line);
             if (match.Success)
             {
                 string key = match.Groups["key"].Value;
                 IConfigurationItem item;
                 if (configuration.Items.TryGetValue(key, out item))
                 {
                     string value = match.Groups["value"].Value;
                     if (item.TryUpdate(value))
                     {
                         updated = true;
                     }
                 }
                 else
                 {
                     //Trace.TraceWarning("Configuration key {0} is not supported by parser. Original line: {1}", key, line);
                 }
             }
         }
     }
     return updated;
 }
Beispiel #3
0
 public static void UpdateConfigurationSections(List<ConfigurationSectionViewModel> sections, DroneConfiguration configuration)
 {
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("control"))
         .UpdateItems(GetItems(configuration, configuration.Control, typeof(ControlSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("custom"))
         .UpdateItems(GetItems(configuration, configuration.Custom, typeof(CustomSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("detect"))
         .UpdateItems(GetItems(configuration, configuration.Detect, typeof(DetectSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("general"))
         .UpdateItems(GetItems(configuration, configuration.General, typeof(GeneralSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("gps"))
         .UpdateItems(GetItems(configuration, configuration.Gps, typeof(GpsSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("leds"))
         .UpdateItems(GetItems(configuration, configuration.Leds, typeof(LedsSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("network"))
         .UpdateItems(GetItems(configuration, configuration.Network, typeof(NetworkSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("pic"))
         .UpdateItems(GetItems(configuration, configuration.Pic, typeof(PicSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("syslog"))
         .UpdateItems(GetItems(configuration, configuration.Syslog, typeof(SyslogSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("userbox"))
         .UpdateItems(GetItems(configuration, configuration.Userbox, typeof(UserboxSection)));
     sections.First<ConfigurationSectionViewModel>(section => section.SectionName.Equals("video"))
         .UpdateItems(GetItems(configuration, configuration.Video, typeof(VideoSection)));
 }
        public static bool TryUpdate(DroneConfiguration configuration, ConfigurationPacket packet)
        {
            Regex _reKeyValue = new Regex(@"(?<key>\w+:\w+) = (?<value>.*)");
            bool  updated     = false;

            using (var ms = new MemoryStream(packet.Data))
                using (var sr = new StreamReader(ms))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        Match match = _reKeyValue.Match(line);
                        if (match.Success)
                        {
                            string             key = match.Groups["key"].Value;
                            IConfigurationItem item;
                            if (configuration.Items.TryGetValue(key, out item))
                            {
                                string value = match.Groups["value"].Value;
                                if (item.TryUpdate(value))
                                {
                                    updated = true;
                                }
                            }
                            else
                            {
                                //Trace.TraceWarning("Configuration key {0} is not supported by parser. Original line: {1}", key, line);
                            }
                        }
                    }
                }
            return(updated);
        }
        public static bool TryUpdate(DroneConfiguration configuration, ConfigurationPacket packet)
        {
            Regex _reKeyValue = new Regex(@"(?<key>\w+:\w+) = (?<value>.*)");
            bool  updated     = false;

            using (var ms = new MemoryStream(packet.Data))
                using (var sr = new StreamReader(ms))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        Match match = _reKeyValue.Match(line);
                        if (match.Success)
                        {
                            string key   = match.Groups["key"].Value;
                            string value = match.Groups["value"].Value;

                            if (configuration.Items.ContainsKey(key))
                            {
                                configuration.Items[key] = value;
                            }
                            else
                            {
                                configuration.Items.Add(key, value);
                            }
                        }
                    }
                }
            return(updated);
        }
Beispiel #6
0
        public static DroneConfiguration Parse(string input)
        {
            var configuration = new DroneConfiguration();

            MatchCollection matches = ReKeyValue.Matches(input);
            foreach (Match match in matches)
            {
                string key = match.Groups["key"].Value;
                string value = match.Groups["value"].Value;
                configuration._items.Add(key, value);
            }
            return configuration;
        }
 public static bool TryUpdate2(DroneConfiguration configuration, ConfigurationPacket packet)
 {
     using (var ms = new MemoryStream(packet.Data))
         using (var sr = new StreamReader(ms))
         {
             string line;
             while ((line = sr.ReadLine()) != null)
             {
                 TryUpdateLine(configuration, line);
             }
         }
     return(true);
 }
 public static bool TryUpdate2(DroneConfiguration configuration, ConfigurationPacket packet)
 {
     using (var ms = new MemoryStream(packet.Data))
     using (var sr = new StreamReader(ms))
     {
         string line;
         while ((line = sr.ReadLine()) != null)
         {
             TryUpdateLine(configuration, line);
         }
     }
     return true;
 }
        public static DroneConfiguration Parse(string input)
        {
            var configuration = new DroneConfiguration();

            MatchCollection matches = ReKeyValue.Matches(input);

            foreach (Match match in matches)
            {
                string key   = match.Groups["key"].Value;
                string value = match.Groups["value"].Value;
                configuration._items.Add(key, value);
            }
            return(configuration);
        }
Beispiel #10
0
        private static List<IConfigurationItem> GetItems(DroneConfiguration configuration, object section, Type type)
        {
            List<IConfigurationItem> configurationItems = new List<IConfigurationItem>();

            var configItems = type.GetRuntimeFields()
                .Where(field => field.GetValue(section) is IConfigurationItem);

            foreach (var configItem in configItems)
            {
                configurationItems.Add((IConfigurationItem)configItem.GetValue(section));
            }

            return configurationItems;
        }
Beispiel #11
0
        public static List<ConfigurationSectionViewModel> InitializeConfigurationSections(DroneConfiguration configuration)
        {
            List<ConfigurationSectionViewModel> configurationSections = new List<ConfigurationSectionViewModel>();

            configurationSections.Add(new ConfigurationSectionViewModel("control", GetItems(configuration, configuration.Control, typeof(ControlSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("custom", GetItems(configuration, configuration.Custom, typeof(CustomSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("detect", GetItems(configuration, configuration.Detect, typeof(DetectSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("general", GetItems(configuration, configuration.General, typeof(GeneralSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("gps", GetItems(configuration, configuration.Gps, typeof(GpsSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("leds", GetItems(configuration, configuration.Leds, typeof(LedsSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("network", GetItems(configuration, configuration.Network, typeof(NetworkSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("pic", GetItems(configuration, configuration.Pic, typeof(PicSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("syslog", GetItems(configuration, configuration.Syslog, typeof(SyslogSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("userbox", GetItems(configuration, configuration.Userbox, typeof(UserboxSection))));
            configurationSections.Add(new ConfigurationSectionViewModel("video", GetItems(configuration, configuration.Video, typeof(VideoSection))));

            return configurationSections;
        }
        public static bool TryUpdateLine(DroneConfiguration configuration, string line)
        {
            var result = false;
            Match match = null;// _reKeyValue.Match(line);
            if (match.Success)
            {
                string key = match.Groups["key"].Value;
                string value = match.Groups["value"].Value;

                if (configuration.Items.ContainsKey(key))
                    configuration.Items[key] = value;
                else
                    configuration.Items.Add(key, value);

                result = true;
            }
            return result;
        }
 public static bool TryUpdateLine(DroneConfiguration configuration, string line)
 {
     var result = false;
     Match match = null;// _reKeyValue.Match(line);
     if (match.Success)
     {
         string key = match.Groups["key"].Value;
         IConfigurationItem item;
         if (configuration.Items.TryGetValue(key, out item))
         {
             string value = match.Groups["value"].Value;
             if (item.TryUpdate(value))
             {
                 result = true;
             }
         }
     }
     return result;
 }
        public static bool TryUpdateLine(DroneConfiguration configuration, string line)
        {
            var   result = false;
            Match match  = null;// _reKeyValue.Match(line);

            if (match.Success)
            {
                string             key = match.Groups["key"].Value;
                IConfigurationItem item;
                if (configuration.Items.TryGetValue(key, out item))
                {
                    string value = match.Groups["value"].Value;
                    if (item.TryUpdate(value))
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
        public static bool TryUpdateLine(DroneConfiguration configuration, string line)
        {
            var   result = false;
            Match match  = null;// _reKeyValue.Match(line);

            if (match.Success)
            {
                string key   = match.Groups["key"].Value;
                string value = match.Groups["value"].Value;

                if (configuration.Items.ContainsKey(key))
                {
                    configuration.Items[key] = value;
                }
                else
                {
                    configuration.Items.Add(key, value);
                }

                result = true;
            }
            return(result);
        }
Beispiel #16
0
        public DroneClient()
        {
            _NavigationDataViewModel = new ViewModel.NavigationDataViewModel();
            _configuration = new DroneConfiguration();
            _ConfigurationSectionsViewModel = ConfigurationViewModelHelper.InitializeConfigurationSections(_configuration);

            _CommandWorker = new CommandWorker(this);
            _NavDataWorker = new NavDataWorker(this);
            _ConfigurationWorker = new ConfigurationWorker(this);
            //TODO ajouter le _configurationAcquisitionWorker
            _WatchdogWorker = new WatchdogWorker(this, new WorkerBase[] { _NavDataWorker, _CommandWorker });
        }
Beispiel #17
0
        public void SendChanges(DroneConfiguration configuration)
        {
            KeyValuePair<string, string> item;

            while (configuration.Changes.Count > 0)
            {
                lock (_SyncRoot)
                {
                    if (configuration.Changes.Count > 0)
                        item = configuration.Changes.Dequeue();
                }
                if (!string.IsNullOrEmpty(item.Key))
                {
                    if (string.IsNullOrEmpty(configuration.Custom.SessionId) == false &&
                        string.IsNullOrEmpty(configuration.Custom.ProfileId) == false &&
                        string.IsNullOrEmpty(configuration.Custom.ApplicationId) == false)
                        SendConfigCommand(Command.ConfigIds(configuration.Custom.SessionId, configuration.Custom.ProfileId, configuration.Custom.ApplicationId));

                    SendConfigCommand(Command.Config(item.Key, item.Value));
                }
            }
        }
Beispiel #18
0
        public DroneClient()
        {
            _NavigationDataViewModel = new ViewModel.NavigationDataViewModel();
            _configuration = new DroneConfiguration();

            _CommandWorker = new CommandWorker(this);
            _NavDataWorker = new NavDataWorker(this);
            _ConfigurationWorker = new ConfigurationWorker(this);
            //TODO ajouter le _configurationAcquisitionWorker
            _WatchdogWorker = new WatchdogWorker(this, new WorkerBase[] { _NavDataWorker, _CommandWorker });
            _InputTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(InputTimerElapsedHandler), TimeSpan.FromMilliseconds(1000 / 12));
        }