Ejemplo n.º 1
0
        public DatapointsSaver()
        {
            if (_instance == null)
            {
                _instance = this;

                Task.Run(() => ((App)Application.Current).Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    _saveTimer = new DispatcherTimer {
                        Interval = TimeSpan.FromSeconds(SaveIntervalSeconds)
                    };
                    _saveTimer.Tick += SaveBufferedReadings;
                    _saveTimer.Start();
                }));

                _onHardwareChanged = HardwareChanged;
                Messenger.Instance.TablesChanged.Subscribe(_onHardwareChanged);

                _localTask = Task.Run(() => { LoadData(); });
            }
            else
            {
                throw new Exception("You can't initialise more than one datapoint Saver");
            }
        }
Ejemplo n.º 2
0
        private bool disposedValue; // To detect redundant calls

        public Manager()
        {
            lock (_lock)
            {
                if (_mqttBroker == null)
                {
                    _mqttBroker = new MqttBroker();
                    _mqttBroker.Start();
                    _udpMessaging                 = new UDPMessaging();
                    _datapointsSaver              = new DatapointsSaver();
                    _mqttBroker.MessagePublished += MqttMessageRecieved;
                }
                else
                {
                    throw new Exception("You should only instantiate this class once! ");
                }
            }
        }
Ejemplo n.º 3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    _udpMessaging?.Dispose();
                    _datapointsSaver?.Dispose();
                }
                if (_mqttBroker != null)
                {
                    _mqttBroker.MessagePublished -= MqttMessageRecieved;
                    _mqttBroker.Stop();
                }
                _mqttBroker      = null;
                _udpMessaging    = null;
                _datapointsSaver = null;

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.
                disposedValue = true;
            }
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     BlockingDispatcher.Run(() => _saveTimer?.Stop());
     _instance = null;
 }