Exemplo n.º 1
0
        protected async void btnImportCloudAhoy_Click(object sender, EventArgs e)
        {
            DateTime?dtStart = null;

            if (mfbCloudAhoyStartDate.Date.HasValue())
            {
                dtStart = mfbCloudAhoyStartDate.Date;
            }
            DateTime?dtEnd = null;

            if (mfbCloudAhoyEndDate.Date.HasValue())
            {
                dtEnd = mfbCloudAhoyEndDate.Date;
            }

            string szResult = await CloudAhoyClient.ImportCloudAhoyFlights(Page.User.Identity.Name, !Branding.CurrentBrand.MatchesHost(Request.Url.Host), dtStart, dtEnd).ConfigureAwait(true);

            if (String.IsNullOrEmpty(szResult))
            {
                // Avoid a "Thread was being aborted" (ThreadAbortException).
                Response.Redirect("~/Member/ReviewPendingFlights.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                lblCloudAhoyErr.Text = HttpUtility.HtmlEncode(szResult);
                popupCloudAhoy.Show();
            }
        }
Exemplo n.º 2
0
    protected async void btnImportCloudAhoy_Click(object sender, EventArgs e)
    {
        Profile         pf     = MyFlightbook.Profile.GetUser(User.Identity.Name);
        CloudAhoyClient client = new CloudAhoyClient(!Branding.CurrentBrand.MatchesHost(Request.Url.Host))
        {
            AuthState = pf.CloudAhoyToken
        };
        DateTime?dtStart = null;

        if (mfbCloudAhoyStartDate.Date.HasValue())
        {
            dtStart = mfbCloudAhoyStartDate.Date;
        }
        DateTime?dtEnd = null;

        if (mfbCloudAhoyEndDate.Date.HasValue())
        {
            dtEnd = mfbCloudAhoyEndDate.Date;
        }

        try
        {
            IEnumerable <CloudAhoyFlight> rgcaf = await client.GetFlights(User.Identity.Name, dtStart, dtEnd);

            foreach (CloudAhoyFlight caf in rgcaf)
            {
                PendingFlight pendingflight = caf.ToLogbookEntry() as PendingFlight;
                if (pendingflight != null)
                {
                    pendingflight.Commit();
                }
            }
            // Avoid a "Thread was being aborted" (ThreadAbortException).
            Response.Redirect("~/Member/ReviewPendingFlights.aspx", false);
            Context.ApplicationInstance.CompleteRequest();
        }
        catch (MyFlightbookException ex)
        {
            // Cloudahoy is sending back HTML
            lblCloudAhoyErr.Text = ex.Message;
            popupCloudAhoy.Show();
        }
        catch (MyFlightbookValidationException ex)
        {
            lblCloudAhoyErr.Text = ex.Message;
            popupCloudAhoy.Show();
        }
    }
    protected async void lnkSendCloudAhoy_Click(object sender, EventArgs e)
    {
        m_fd.AltitudeUnits = (FlightData.AltitudeUnitTypes)Convert.ToInt32(cmbAltUnits.SelectedValue, CultureInfo.InvariantCulture);
        m_fd.SpeedUnits    = (FlightData.SpeedUnitTypes)Convert.ToInt32(cmbSpeedUnits.SelectedValue, CultureInfo.InvariantCulture);
        m_fd.FlightID      = CurrentFlightID;

        CloudAhoyClient client = new CloudAhoyClient(!Branding.CurrentBrand.MatchesHost(Request.Url.Host))
        {
            AuthState = Viewer.CloudAhoyToken
        };

        MemoryStream ms = null;

        try
        {
            switch (CurrentFlight.Telemetry.TelemetryType)
            {
            default:
                ms = new MemoryStream();
                m_fd.WriteGPXData(ms);
                break;

            case DataSourceType.FileType.GPX:
            case DataSourceType.FileType.KML:
                ms = new MemoryStream(Encoding.UTF8.GetBytes(CurrentFlight.Telemetry.RawData));
                break;
            }

            ms.Seek(0, SeekOrigin.Begin);
            await client.PutStream(ms, CurrentFlight);

            pnlCloudAhoySuccess.Visible = true;
        }
        catch (MyFlightbookException ex)
        {
            lblCloudAhoyErr.Text = ex.Message;
        }
        finally
        {
            if (ms != null)
            {
                ms.Dispose();
            }
        }
    }