public GoogleAPIAuthorizationWindow(ViewModel viewModel)
        {
            InitializeComponent();
            _viewModel = viewModel;
            this.DataContext = _viewModel;

            SourceInitialized += GoogleAPIAuthorizationWindow_SourceInitialized;
        }
예제 #2
0
        public async Task<DriveService> GetDriveServiceAsync()
        {
            
            DriveService driveService = default(DriveService);
            //Instantiation of fully linked window and ViewModel (non-MVVM way somehow)
            ViewModel authorizationWindowViewModel = new ViewModel(this._AuthorizeDriveService);
            GoogleAPIAuthorizationWindow authorizationWindow =
                new GoogleAPIAuthorizationWindow(authorizationWindowViewModel);
            authorizationWindowViewModel.ParentWindow = authorizationWindow;

            if (System.IO.File.Exists(_tokenFilePath))
            {
                while (driveService == default(DriveService))
                {
                    try
                    {
                        driveService = await _AuthorizeDriveService();
                    }
                    catch (Exception) //If token has expired or there is no internet connection
                    {
                        //Must be reviewed, as the file may be removed in try block automatically
                        System.IO.File.Delete(_tokenFilePath);
                        driveService = default(DriveService);
                    }
                    //There isn't token file, so call the dialog
                    if (driveService == default(DriveService))
                    {
                        driveService = authorizationWindow.ShowDialog();
                    }
                }
            }
            else //If authorizing through a browser initially
            {
                while (driveService == default(DriveService))
                {
                    try
                    {
                        driveService = authorizationWindow.ShowDialog();
                    }
                    catch (Exception)
                    {
                        //If there is no connection or user cancelled - swallow
                        driveService = default(DriveService);
                    }
                }
            }
            return driveService;
        }
예제 #3
0
 public SignInCommandImplementation(ViewModel viewModel)
 {
     _viewModel = viewModel;
 }
예제 #4
0
 public ExitCommandImplementation(ViewModel viewModel)
 {
     _viewModel = viewModel;
 }