Ejemplo n.º 1
0
        private void StartInfluxDBMeasurementsCollector()
        {
            lock (influxDBMeasurementsCollectorLock)
            {
                bool recreate = (influxDBMeasurementsCollector == null) || (!influxDBMeasurementsCollector.LoginInformation.Equals(pluginConfig.DBLoginInformation));

                if (recreate)
                {
                    collectionShutdownToken?.Cancel();
                    collectionShutdownToken = new CancellationTokenSource();
                    if (pluginConfig.DBLoginInformation.IsValid)
                    {
                        influxDBMeasurementsCollector = new InfluxDBMeasurementsCollector(pluginConfig.DBLoginInformation);
                        influxDBMeasurementsCollector.Start(pluginConfig.DevicePersistenceData.Values,
                                                            CancellationTokenSource.CreateLinkedTokenSource(collectionShutdownToken.Token, ShutdownCancellationToken).Token);
                    }
                }
                else
                {
                    influxDBMeasurementsCollector.UpdatePeristenceData(pluginConfig.DevicePersistenceData.Values);
                }

                RecordTrackedDevices().Wait();
            }
        }
Ejemplo n.º 2
0
        private async Task StartInfluxDBMeasurementsCollector()
        {
            using (var sync = await influxDBMeasurementsCollectorLock.EnterAsync(ShutdownCancellationToken))
            {
                bool recreate = (influxDBMeasurementsCollector == null) ||
                                (!influxDBMeasurementsCollector.LoginInformation.Equals(pluginConfig.DBLoginInformation));

                if (recreate)
                {
                    if (pluginConfig.DBLoginInformation.IsValid)
                    {
                        influxDBMeasurementsCollector?.Dispose();
                        influxDBMeasurementsCollector = new InfluxDBMeasurementsCollector(pluginConfig.DBLoginInformation, ShutdownCancellationToken);
                        influxDBMeasurementsCollector.Start(pluginConfig.DevicePersistenceData.Values);
                    }
                }
                else
                {
                    influxDBMeasurementsCollector.UpdatePeristenceData(pluginConfig.DevicePersistenceData.Values);
                }
            }

            // do not leave thread to avoid leaving thread as it can delay startup
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
            await RecordTrackedDevices();

#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
        }
Ejemplo n.º 3
0
        private static async Task RecordDeviceValue(InfluxDBMeasurementsCollector collector, IHSApplication HS, DeviceClass device)
        {
            if (device != null)
            {
                int  deviceRefId = device.get_Ref(HS);
                bool notValid    = HS.get_DeviceInvalidValue(deviceRefId);
                if (!notValid)
                {
                    double deviceValue  = device.get_devValue(HS);
                    string deviceString = HS.DeviceString(deviceRefId);
                    if (string.IsNullOrWhiteSpace(deviceString))
                    {
                        deviceString = HS.DeviceVSP_GetStatus(deviceRefId, deviceValue, ePairStatusControl.Status);
                    }
                    Trace.WriteLine(Invariant($"Recording Device Ref Id: {deviceRefId} with [{deviceValue}] & [{deviceString}]"));

                    DateTime lastChange = device.get_Last_Change(HS);

                    RecordData recordData = new RecordData(deviceRefId,
                                                           deviceValue,
                                                           deviceString,
                                                           device.get_Name(HS),
                                                           device.get_Location(HS),
                                                           device.get_Location2(HS),
                                                           lastChange);

                    await collector.Record(recordData).ConfigureAwait(false);
                }
                else
                {
                    Trace.TraceWarning(Invariant($"Not recording Device Ref Id: {deviceRefId} as it has invalid value."));
                }
            }
        }