Esempio n. 1
0
 public SensorTriggerViewModel(Sensor sensor, SensorTrigger model)
 {
     this.sensor = sensor;
     Model       = model;
     Comparer    = model.Comparer;
     IsEnabled   = sensor.Triggers.Any(t => t.id == model.Id);
 }
Esempio n. 2
0
        private bool MatchTrigger(IPlatformMessage message, NetworkEvent evt, SensorTrigger info, ref bool textTriggered, ref bool measurementTriggered)
        {
            if (!this.VerifySensorTrigger(message, info))
            {
                return(false);
            }

            evt.Actions.Add(NetworkEventType.MessageTriggered);

            if (!textTriggered && info.IsTextTrigger)
            {
                textTriggered = true;
                this.EnqueueToTriggerService(message);
            }
            else if (!measurementTriggered && !info.IsTextTrigger)
            {
                measurementTriggered = true;
                this.EnqueueToTriggerService(message);
            }

            if (textTriggered && measurementTriggered)
            {
                this.m_logger.LogDebug($"Skipping trigger for {message.SensorID}: already queued");
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        private bool VerifySensorTrigger(IPlatformMessage message, SensorTrigger info)
        {
            if (!info.HasActions)
            {
                this.m_logger.LogDebug($"Skipping message from sensor {message.SensorID}: no actions available");
                return(false);
            }

            return((!info.IsTextTrigger || message.Type == MessageType.Message) && (info.IsTextTrigger || message.Type == MessageType.Measurement));
        }
Esempio n. 4
0
 public Task <SensorTrigger> SetSensorTrigger(SensorTrigger trigger)
 {
     if (trigger.Id == 0)
     {
         db.Insert(trigger);
     }
     else
     {
         db.Update(trigger);
     }
     return(Task.FromResult(trigger));
 }
        private async Task ReloadSensors(CancellationToken token)
        {
            this.m_logger.LogInformation("Starting sensor reload at {reloadStart}", DateTime.UtcNow);

            using var scope = this.m_provider.CreateScope();
            var routingRepo = scope.ServiceProvider.GetRequiredService <IRoutingRepository>();

            var sw          = Stopwatch.StartNew();
            var sensorTask  = routingRepo.GetSensorsAsync(token);
            var triggerTask = routingRepo.GetTriggerInfoAsync(token);

            var sensors = await sensorTask.ConfigureAwait(false);

            var dict = sensors.ToDictionary(k => k.ID, v => v);

            this.m_logger.LogDebug("Finished loading sensors in {ms}ms.", sw.ElapsedMilliseconds);

            var rawTriggers = await triggerTask.ConfigureAwait(false);

            var triggers = rawTriggers.ToList();

            this.m_logger.LogDebug("Finished loading trigger routes in {ms}ms.", sw.ElapsedMilliseconds);

            this.m_logger.LogInformation("Bulk loaded {sensorCount} sensors.", dict.Count);
            this.m_logger.LogInformation("Bulk loaded {triggerCount} trigger routes.", triggers.Count);

            foreach (var info in triggers)
            {
                var route = new SensorTrigger {
                    HasActions    = info.ActionCount > 0,
                    IsTextTrigger = info.TextTrigger
                };

                var loaded = dict.TryGetValue(info.SensorID, out var sensor);

                if (!loaded || sensor == null)
                {
                    this.m_logger.LogWarning("Found trigger route for a non-existing sensor. Sensor ID: {sensorID}.", info.SensorID.ToString());
                    continue;
                }

                sensor.TriggerInformation ??= new List <SensorTrigger>();
                sensor.TriggerInformation.Add(route);
            }

            this.m_cache.Load(dict.Values);
            sw.Stop();
            this.m_logger.LogInformation("Finished sensor reload at {reloadEnd}. Reload took {duration}ms.", DateTime.UtcNow, sw.ElapsedMilliseconds);
        }
Esempio n. 6
0
    // METHODS ------------------------------------------------------------------------------------

    #region Monobehaviours

    protected void Awake()
    {
        if (Main != null)
        {
            Destroy(gameObject);
            return;
        }

        Main = this;
        Debug.Log("<color='purple'>SensorTrigger</color>: Set <i>" + this.name +
                  "</i> as Main trigger. Set to <b>" +
                  ((destroyAfterScene) ? "destroy" : "persist") +
                  "</b> on scene end.");

        if (!destroyAfterScene)
        {
            DontDestroyOnLoad(this);
        }
    }
Esempio n. 7
0
 public Task <SensorTrigger> DeleteSensorTrigger(SensorTrigger trigger)
 {
     db.Delete(trigger);
     return(Task.FromResult(trigger));
 }
Esempio n. 8
0
 public static void SensorToDocumentString(DocumentString document, Sensor sensor, SensorTrigger trigger)
 {
     document.TriggerValue    = trigger.Value.ToString();
     document.TriggerComparer = trigger.Comparer.ToString();
     document.Id          = sensor.Id.ToString();
     document.FaultState  = sensor.FaultState.ToString();
     document.DeviceState = sensor.DeviceState.ToString();
     document.Value       = sensor.Value.ToString();
     document.Unit        = sensor.Unit;
     document.Value       = sensor.Value.ToString();
     document.DangerHi    = sensor.DangerHi.ToString();
     document.DangerLo    = sensor.DangerLo.ToString();
     document.RangeMax    = sensor.RangeMax.ToString();
     document.RangeMin    = sensor.RangeMin.ToString();
 }