コード例 #1
0
        public NewObjectViewModel(ICttObjectTrackingService cttObjectTrackingService, INavigationService navigationService, ISystemTrayService systemTrayService, IMessageBoxService messageBoxService)
        {
            _cttObjectTrackingService = cttObjectTrackingService;
            _navigationService        = navigationService;
            _systemTrayService        = systemTrayService;
            _messageBoxService        = messageBoxService;

            AddObjectCommand = new RelayCommand(() =>
            {
                if (string.IsNullOrWhiteSpace(ObjectId))
                {
                    _messageBoxService.Show("Por favor indique o número do objecto", "Erro");

                    return;
                }

                _systemTrayService.SetProgressIndicator(string.Format("A adicionar: {0}...", ObjectId));

                _cttObjectTrackingService.GetCttObjectTrackingStatus(ObjectId, result =>
                {
                    _systemTrayService.HideProgressIndicator();

                    if (result.Error != null)
                    {
                        _messageBoxService.Show(string.Format("Não foi possível adicionar o objecto \"{0}\"", ObjectId), "Erro");

                        ScanBarcodeCommand.RaiseCanExecuteChanged();
                        AddObjectCommand.RaiseCanExecuteChanged();
                    }
                    else
                    {
                        MessengerInstance.Send <AddObjectMessage>(new AddObjectMessage(_description, result.ETag, result.Data));

                        _navigationService.GoBack();

                        ObjectId = null;
                    }
                }, null);

                ScanBarcodeCommand.RaiseCanExecuteChanged();
                AddObjectCommand.RaiseCanExecuteChanged();
            }, () => !IsBusy);

            ScanBarcodeCommand = new RelayCommand(() =>
            {
                _navigationService.NavigateTo(new Uri("/View/ScanBarcodePage.xaml", UriKind.Relative));
            }, () => !IsBusy);

            MessengerInstance.Register <ScannedBarcodeMessage>(this, message =>
            {
                ObjectId = message.ObjectId;
            });
        }
コード例 #2
0
        private void RefreshNext(IEnumerator <ObjectDetailsViewModel> enumerator)
        {
            if (enumerator.MoveNext())
            {
                var objectModel = enumerator.Current.Model;

                var objectId = objectModel.ObjectId;
                var etag     = objectModel.ETag;

                _systemTrayService.SetProgressIndicator(string.Format("A actualizar: {0}...", objectId));

                _cttObjectTrackingService.GetCttObjectTrackingStatus(objectId, etag, result =>
                {
                    if (result.Error != null)
                    {
                        _systemTrayService.HideProgressIndicator();

                        _messageBoxService.Show(string.Format("Não foi possível actualizar o objecto \"{0}\"", objectId), "Erro");

                        return;
                    }
                    else if (result.StatusCode != System.Net.HttpStatusCode.NotModified)
                    {
                        objectModel.ETag  = result.ETag;
                        objectModel.State = result.Data;
                    }

                    RefreshNext(enumerator);
                }, null);
            }
            else
            {
                enumerator.Dispose();

                _systemTrayService.HideProgressIndicator();

                _model.Save();
            }
        }
コード例 #3
0
        public AuthorizationViewModel(IMainModel mainModel, IGoogleAuthService googleAuthService, IGoogleOAuth2Service googleOAuth2Service, INavigationService navigationService, IMessageBoxService messageBoxService, ISystemTrayService systemTrayService)
        {
            _mainModel = mainModel;
            _googleAuthService = googleAuthService;
            _googleOAuth2Service = googleOAuth2Service;
            _navigationService = navigationService;
            _messageBoxService = messageBoxService;
            _systemTrayService = systemTrayService;

            PageLoadedCommand = new RelayCommand(() =>
            {
                ShowBrowser = true;

                WebBrowserSourceUri = _googleAuthService.GetAuthUri();
            });

            WebBrowserNavigatingCommand = new RelayCommand<NavigatingEventArgs>(e =>
            {
                if (_showBrowser)
                {
                    _systemTrayService.SetProgressIndicator("");
                }

                if (e.Uri == null || e.Uri.Host != "localhost")
                    return;

                ShowBrowser = false;

                WebBrowserSourceUri = new Uri("https://accounts.google.com/Logout");

                var queryString = e.Uri.QueryString();

                ExchangeAuthorizationCode(queryString.GetValue("code"));
            });

            WebBrowserNavigatedCommand = new RelayCommand<NavigationEventArgs>(e =>
            {
                if (_showBrowser)
                {
                    _systemTrayService.HideProgressIndicator();
                }
            });

            WebBrowserNavigationFailedCommand = new RelayCommand<NavigationFailedEventArgs>(e =>
            {
                _systemTrayService.HideProgressIndicator();
            });
        }