Ejemplo n.º 1
0
        public bool TryProcess(StatusUpdate update)
        {
            if (_menuService.CurrentMenu?.Setting == null)
            {
                return(false);
            }
            var setting = _menuService.CurrentMenu.Setting;

            var value = update.Text;

            if (!String.IsNullOrEmpty(setting.Format))
            {
                value = setting.Test.Replace(update.Text, setting.Format);
            }
            var v = _status.Status.Settings.AddOrUpdate(setting.Name,
                                                        name =>
            {
                _log.LogDebug($"Creating setting {setting.Name}={value}");
                return(new SettingValue()
                {
                    Item = setting,
                    Value = value,
                    LastModified = DateTime.UtcNow
                });
            },
                                                        (name, existing) =>
            {
                _log.LogDebug($"Updating setting {setting.Name}={value}");
                existing.Item         = setting;
                existing.LastModified = DateTime.UtcNow;
                existing.Value        = value;
                return(existing);
            });

            if (v.LastModified.HasValue && (!_status.LastSavedTime.HasValue ||
                                            _status.LastSavedTime < v.LastModified))
            {
                _status.SaveChanges();
            }

            foreach (var p in Pending.ToArray())
            {
                if (v.Item.Name.Equals(p.Key, StringComparison.InvariantCultureIgnoreCase) && p.Value.Value?.Equals(v.Value, StringComparison.InvariantCultureIgnoreCase) == true)
                {
                    Pending.TryRemove(p.Key, out _);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool TryProcess(StatusUpdate update)
        {
            var processed = false;

            foreach (var sensor in _sensors)
            {
                if (!sensor.TryMatch(update, out var m))
                {
                    continue;
                }
                var value = sensor.Test.Replace(update.Text, sensor.Format);
                _log.LogInformation($"Updating sesnsor {sensor.Name} to {value}");
                var v = _status.Status.Values.AddOrUpdate(sensor.Name,
                                                          name => new SensorValue()
                {
                    Item         = sensor,
                    Value        = value,
                    LastModified = DateTime.UtcNow
                },
                                                          (name, existing) =>
                {
                    existing.Item         = sensor;
                    existing.LastModified = DateTime.UtcNow;
                    existing.Value        = value;
                    return(existing);
                });
                if (v.LastModified.HasValue && (!_status.LastSavedTime.HasValue ||
                                                _status.LastSavedTime < v.LastModified))
                {
                    _status.SaveChanges();
                }

                processed = true;
            }

            return(processed);
        }
Ejemplo n.º 3
0
 public MenuState(MenuNode item, Match match, StatusUpdate status)
 {
     Current   = item;
     TextMatch = match;
     Text      = status;
 }