Exemplo n.º 1
0
        public override void Initialize()
        {
            AddNewDeviceCommand = ReactiveCommand.CreateFromTask(CreateNewDevice, ioTHubInfoSelectionService.SelectedObject.Select(iotHub => iotHub != null))
                                  .AddDisposableTo(Disposables);
            DeleteSelectedDeviceCommand = ReactiveCommand.CreateFromTask(DeleteSelectedDevice, ioTDeviceSelectionService.SelectedObject.Select(ioTDeviceInfos => ioTDeviceInfos != null))
                                          .AddDisposableTo(Disposables);

            this.WhenAnyValue(vm => vm.SelectedIoTDeviceInfo)
            .Subscribe(x => ioTDeviceSelectionService.Select(x))
            .AddDisposableTo(Disposables);

            ioTHubInfoSelectionService.SelectedObject
            .Where(iotHub => iotHub != null)
            .ObserveOnDispatcher()
            .Do(_ => Loading = true)
            .Do(devices => IoTDeviceInfos = new IoTDeviceInfo[] {})
            .Do(i => this.hubName         = i.Name)
            .Subscribe()
            .AddDisposableTo(Disposables);

            ioTHubInfoSelectionService.SelectedObject
            .Where(iotHub => iotHub != null)
            .SelectMany(iothub => azureService.GetIoTDevices(iothub.Name))
            .ObserveOnDispatcher()
            .Do(devices => IoTDeviceInfos = devices)
            .Do(_ => Loading = false)
            .LogAndRetryAfterDelay(Logger, TimeSpan.FromSeconds(1), "Error while retrieving devices information")
            .Subscribe()
            .AddDisposableTo(Disposables);

            ReloadCommand = ReactiveCommand.CreateFromTask(Reload, ioTHubInfoSelectionService.SelectedObject.Select(iotHub => iotHub != null))
                            .AddDisposableTo(Disposables);

            MonitorDevice = ReactiveCommand.CreateFromTask <IoTDeviceInfo, Unit>(OpenMonitorDevice)
                            .AddDisposableTo(Disposables);
        }