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; }
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); }
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); }
private void OnConfigurationPacketAcquired(ConfigurationPacket packet) { if (UpdateConfiguration(packet)) { if (_DroneClient.RequestedState == RequestedState.GetConfiguration) _DroneClient.RequestedState = RequestedState.None; ConfigurationViewModelHelper.UpdateConfigurationSections(_DroneClient.ConfigurationSectionsViewModel, _DroneClient.Configuration); } }
internal bool UpdateConfiguration(ConfigurationPacket packet) { using (var ms = new MemoryStream(packet.Data)) { using (var sr = new StreamReader(ms)) { string line; while ((line = sr.ReadLine()) != null) { UpdateConfigurationLine(line); } } } return true; }
private void OnDataReadCompletion(uint bytesRead, Streams.DataReader reader) { if (reader == null) { return; } uint unreadLength = reader.UnconsumedBufferLength; if (unreadLength == 0) { return; } byte[] buffer = new byte[unreadLength]; reader.ReadBytes(buffer); StringBuilder stringBuffer = new StringBuilder(); stringBuffer.Append(Encoding.UTF8.GetString(buffer, 0, buffer.Length)); Debug.WriteLine("Configuration Brute: " + stringBuffer.ToString()); var packet = new ConfigurationPacket { Timestamp = DateTime.UtcNow.Ticks, Data = buffer }; if (UpdateConfiguration(packet)) { if (_DroneClient.RequestedState == RequestedState.GetConfiguration) _DroneClient.RequestedState = RequestedState.None; ConfigurationViewModelHelper.UpdateConfigurationSections(_DroneClient.ConfigurationSectionsViewModel, _DroneClient.Configuration); } }
private void OnConfigurationPacketAcquired(ConfigurationPacket packet) { if (UpdateConfiguration(packet)) { if (_DroneClient.RequestedState == RequestedState.GetConfiguration) _DroneClient.RequestedState = RequestedState.None; } }