Ejemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!Disposed)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                var cleanUpTimer = new Action(() =>
                {
                    UdpBroadcastTimer.Stop();
                    UdpBroadcastTimer.Tick -= UDPBroadcast;
                });

                BlockingDispatcher.Run(cleanUpTimer);

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                _udpSocket.Dispose();

                // TODO: set large fields to null.
                _instance = null;

                Disposed = true;
            }
        }
Ejemplo n.º 2
0
 public void Suspend()
 {
     Util.LoggingService.LogInfo("suspending manager", Windows.Foundation.Diagnostics.LoggingLevel.Verbose);
     _mqttBroker?.Stop();
     _udpMessaging?.Dispose();
     _udpMessaging = null;
 }
Ejemplo n.º 3
0
        public UDPMessaging()
        {
            if (_instance != null)
            {
                throw new Exception("Tried to create more than one UDPMessaging Class!");
            }
            Task.Run(() => ((App)Application.Current).Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                UdpBroadcastTimer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(BroadcastIntervalSeconds)
                };
                UdpBroadcastTimer.Tick += UDPBroadcast;
                UdpBroadcastTimer.Start();
            }));

            _udpSocket.Bind(remoteEndPoint);
            //this event is used to give all the parameters to WSystem.net api
            var e      = new SocketAsyncEventArgs();
            var buffer = new byte[1024];

            e.SetBuffer(buffer, 0, buffer.Length);
            e.RemoteEndPoint = remoteEndPoint;
            e.Completed     += ReceiveFromCallback;


            //_udpSocket.ConnectAsync(new SocketAsyncEventArgs());

            if (!_udpSocket.ReceiveFromAsync(e))
            {
                ReceiveFromCallback(_udpSocket, e);
            }

            _instance = this;
        }
Ejemplo n.º 4
0
 public void Suspend()
 {
     Debug.WriteLine("suspending manager");
     _mqttBroker?.Stop();
     _udpMessaging?.Dispose();
     _udpMessaging = null;
     _datapointsSaver.Suspend();
 }
Ejemplo n.º 5
0
 public void Resume()
 {
     Util.LoggingService.LogInfo("resuming manager", Windows.Foundation.Diagnostics.LoggingLevel.Verbose);
     _mqttBroker?.Start();
     if (_udpMessaging == null || _udpMessaging.Disposed)
     {
         _udpMessaging = new UDPMessaging();
     }
 }
Ejemplo n.º 6
0
 public void Resume()
 {
     Debug.WriteLine("resuming manager");
     _mqttBroker?.Start();
     if (_udpMessaging == null || _udpMessaging.Disposed)
     {
         _udpMessaging = new UDPMessaging();
     }
     _datapointsSaver.Resume();
 }
Ejemplo n.º 7
0
        private bool disposedValue; // To detect redundant calls

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

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.
                disposedValue = true;
            }
        }