Пример #1
0
        public async void Initialize(Frame frame, WinUI.NavigationView navigationView)
        {
            _frame                   = frame;
            _navigationView          = navigationView;
            _frame.NavigationFailed += (sender, e) =>
            {
                throw e.Exception;
            };
            _frame.Navigated += Frame_Navigated;
            _navigationView.BackRequested += OnBackRequested;
            if (string.IsNullOrEmpty(_applicationDataService.GetSetting <string>("TcpPort")))
            {
                _applicationDataService.SaveSetting("TcpPort", "8273");
            }
            if (string.IsNullOrEmpty(_applicationDataService.GetSetting <string>("UdpPort")))
            {
                _applicationDataService.SaveSetting("UdpPort", "8274");
            }
            _liveTileUpdateService.UpdateTile(_liveTileUpdateService.CreateTile(await _liveTileUpdateService.GetActiveAgendaItem()));
            try
            {
                if (_backgroundTaskService.FindRegistration <LiveTileUpdateBackgroundTask>() == null)
                {
                    await _backgroundTaskService.Register <LiveTileUpdateBackgroundTask>(new TimeTrigger(15, false));
                }
            }
            catch { }
            await _userDatagramService.StartListenerAsync();

            await _transmissionControlService.StartListenerAsync();
        }
Пример #2
0
        public async Task StartListenerAsync()
        {
            try
            {
                _streamSocketListener       = new StreamSocketListener();
                _backgroundTaskRegistration = (BackgroundTaskRegistration)_backgroundTaskService.FindRegistration <SocketActivityTriggerBackgroundTask>();
                if (_backgroundTaskRegistration == null)
                {
                    _backgroundTaskRegistration = await _backgroundTaskService.Register <SocketActivityTriggerBackgroundTask>(new SocketActivityTrigger());
                }
                if (_backgroundTaskRegistration != null)
                {
                    _streamSocketListener.EnableTransferOwnership(_backgroundTaskRegistration.TaskId, SocketActivityConnectedStandbyAction.DoNotWake);
                }
                await _streamSocketListener.BindServiceNameAsync(_applicationDataService.GetSetting <string>("TcpPort"));

                _streamSocketListener.ConnectionReceived += async(s, e) =>
                {
                    using (StreamReader streamReader = new StreamReader(e.Socket.InputStream.AsStreamForRead()))
                    {
                        await ProcessInputStream(e.Socket, await streamReader.ReadLineAsync());
                    }
                };
            }
            catch (Exception ex)
            {
                SocketErrorStatus webErrorStatus = SocketError.GetStatus(ex.GetBaseException().HResult);
            }
            _eventAggregator.GetEvent <PortChangedEvent>().Subscribe(async() =>
            {
                await StartListenerAsync();
            });
        }
Пример #3
0
        private void RegisterClicked(object sender, RoutedEventArgs e)
        {
            var taskName = TaskNameTextBox.Text;

            _backgroundTaskService.Register(taskName, typeof(SimpleBackgroundTask), new TimeTrigger(15, false));
        }
Пример #4
0
        public async Task StartListenerAsync()
        {
            try
            {
                _datagramSocket = new DatagramSocket();
                var window     = CoreWindow.GetForCurrentThread();
                var dispatcher = window.Dispatcher;
                _backgroundTaskRegistration = (BackgroundTaskRegistration)_backgroundTaskService.FindRegistration <SocketActivityTriggerBackgroundTask>();
                if (_backgroundTaskRegistration == null)
                {
                    _backgroundTaskRegistration = await _backgroundTaskService.Register <SocketActivityTriggerBackgroundTask>(new SocketActivityTrigger());
                }
                if (_backgroundTaskRegistration != null)
                {
                    _datagramSocket.EnableTransferOwnership(_backgroundTaskRegistration.TaskId, SocketActivityConnectedStandbyAction.DoNotWake);
                }
                await _datagramSocket.BindServiceNameAsync(_applicationDataService.GetSetting <string>("UdpPort"));

                _datagramSocket.MessageReceived += async(s, e) =>
                {
                    uint stringLength    = e.GetDataReader().UnconsumedBufferLength;
                    var  incomingMessage = e.GetDataReader().ReadString(stringLength);
                    var  package         = JsonConvert.DeserializeObject <Package>(incomingMessage);
                    if (package != null)
                    {
                        switch ((PayloadType)package.PayloadType)
                        {
                        case PayloadType.Discovery:
                            package = new Package()
                            {
                                PayloadType = (int)PayloadType.Room,
                                Payload     = new Room()
                                {
                                    RoomGuid   = _applicationDataService.GetSetting <string>("Guid"),
                                    RoomName   = _applicationDataService.GetSetting <string>("RoomName"),
                                    RoomNumber = _applicationDataService.GetSetting <string>("RoomNumber"),
                                    Occupancy  = _applicationDataService.GetSetting <int>("ActualOccupancy"),
                                    IsIoT      = _iotService.IsIotDevice()
                                }
                            };
                            var json = JsonConvert.SerializeObject(package);
                            await _transmissionControlService.SendStringData(e.RemoteAddress, _applicationDataService.GetSetting <string>("TcpPort"), json);

                            break;

                        case PayloadType.PropertyChanged:
                            break;

                        default:
                            break;
                        }
                    }
                };
            }
            catch (Exception ex)
            {
                SocketErrorStatus webErrorStatus = SocketError.GetStatus(ex.GetBaseException().HResult);
            }

            _eventAggregator.GetEvent <PortChangedEvent>().Subscribe(async() =>
            {
                await StartListenerAsync();
            });
        }