Example #1
0
    protected async void lnkSaveGoogleDrive_Click(object sender, EventArgs e)
    {
        MyFlightbook.Profile pf = MyFlightbook.Profile.GetUser(Page.User.Identity.Name);
        LogbookBackup        lb = new LogbookBackup(pf);

        if (pf.GoogleDriveAccessToken == null || String.IsNullOrEmpty(pf.GoogleDriveAccessToken.RefreshToken))
        {
            return;
        }

        try
        {
            GoogleDrive gd = new GoogleDrive(pf.GoogleDriveAccessToken);

            await lb.BackupToGoogleDrive(gd).ConfigureAwait(false);

            if (ckIncludeImages.Checked)
            {
                await lb.BackupImagesToGoogleDrive(gd).ConfigureAwait(false);
            }

            // if we are here we were successful, so save the updated refresh token
            pf.GoogleDriveAccessToken = gd.AuthState;
            pf.FCommit();

            lblDropBoxSuccess.Visible = true;
        }
        catch (Exception ex) when(!(ex is OutOfMemoryException))
        {
            ShowDropboxError(ex.Message);
        }
    }
    protected async void lnkSaveGoogleDrive_Click(object sender, EventArgs e)
    {
        MyFlightbook.Profile pf = MyFlightbook.Profile.GetUser(Page.User.Identity.Name);
        LogbookBackup        lb = new LogbookBackup(pf);

        if (pf.GoogleDriveAccessToken == null || String.IsNullOrEmpty(pf.GoogleDriveAccessToken.RefreshToken))
        {
            return;
        }

        try
        {
            GoogleDrive gd = new GoogleDrive(pf.GoogleDriveAccessToken);

            if (await gd.RefreshAccessToken())
            {
                pf.FCommit();
            }

            await lb.BackupToGoogleDrive(gd);

            if (ckIncludeImages.Checked)
            {
                await lb.BackupImagesToGoogleDrive(gd);
            }

            lblDropBoxSuccess.Visible = true;
        }
        catch (MyFlightbookException ex)
        {
            ShowDropboxError(ex.Message);
        }
        catch (System.Net.Http.HttpRequestException ex)
        {
            ShowDropboxError(ex.Message);
        }
        catch (Exception ex)
        {
            ShowDropboxError(ex.Message);
        }
    }
    protected async void lnkSaveOneDrive_Click(object sender, EventArgs e)
    {
        MyFlightbook.Profile pf = MyFlightbook.Profile.GetUser(Page.User.Identity.Name);
        LogbookBackup        lb = new LogbookBackup(pf);

        if (pf.OneDriveAccessToken == null || String.IsNullOrEmpty(pf.OneDriveAccessToken.RefreshToken))
        {
            return;
        }
        try
        {
            OneDrive od = new OneDrive(pf.OneDriveAccessToken);
            await lb.BackupToOneDrive(od);

            if (ckIncludeImages.Checked)
            {
                await lb.BackupImagesToOneDrive(od);
            }

            // if we are here we were successful, so save the updated refresh token
            pf.OneDriveAccessToken.RefreshToken = od.AuthState.RefreshToken;
            pf.FCommit();

            lblDropBoxSuccess.Visible = true;
        }
        catch (OneDriveException ex)
        {
            ShowDropboxError(OneDrive.MessageForException(ex));
        }
        catch (MyFlightbookException ex)
        {
            ShowDropboxError(ex.Message);
        }
        catch (Exception ex)
        {
            ShowDropboxError(ex.Message);
        }
    }