Пример #1
0
        public async static Task <bool> PushCloudAhoyFlight(string szUsername, LogbookEntryCore flight, FlightData fd, bool fSandbox)
        {
            if (szUsername == null)
            {
                throw new ArgumentNullException(nameof(szUsername));
            }
            if (flight == null)
            {
                throw new ArgumentNullException(nameof(flight));
            }
            if (fd == null)
            {
                throw new ArgumentNullException(nameof(fd));
            }

            Profile         pf     = Profile.GetUser(szUsername);
            CloudAhoyClient client = new CloudAhoyClient(fSandbox)
            {
                AuthState = pf.CloudAhoyToken
            };
            bool fUseRawData = (flight.Telemetry.TelemetryType == DataSourceType.FileType.GPX || flight.Telemetry.TelemetryType == DataSourceType.FileType.KML);

            using (MemoryStream ms = fUseRawData ? new MemoryStream(Encoding.UTF8.GetBytes(flight.Telemetry.RawData)) : new MemoryStream())
            {
                if (!fUseRawData)
                {
                    fd.WriteGPXData(ms);
                }

                ms.Seek(0, SeekOrigin.Begin);
                return(await client.PutStream(ms, flight));
            }
        }
    protected void btnDownload_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;

        DataSourceType dst       = null;
        Action         writeData = null;

        switch ((DownloadFormat)cmbFormat.SelectedIndex)
        {
        case DownloadFormat.Original:
            string szData = CurrentFlight.FlightData;
            dst       = DataSourceType.BestGuessTypeFromText(szData);
            writeData = () => { Response.Write(szData); };
            break;

        case DownloadFormat.CSV:
            dst       = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.CSV);
            writeData = () => { MyFlightbook.CSV.CsvWriter.WriteToStream(Response.Output, m_fd.Data, true, true); };
            break;

        case DownloadFormat.KML:
            dst       = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.KML);
            writeData = () => { m_fd.WriteKMLData(Response.OutputStream); };
            break;

        case DownloadFormat.GPX:
            dst       = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.GPX);
            writeData = () => { m_fd.WriteGPXData(Response.OutputStream); };
            break;
        }

        if (dst != null && writeData != null)
        {
            Response.Clear();
            Response.ContentType = dst.Mimetype;
            Response.AddHeader("Content-Disposition", String.Format(CultureInfo.CurrentCulture, "attachment;filename=FlightData{0}.{1}", m_fd.FlightID, dst.DefaultExtension));
            writeData();
            Response.End();
        }
    }
Пример #3
0
    protected void DownloadData(LogbookEntry le, FlightData m_fd, int altUnits, int speedUnits, int format)
    {
        if (m_fd == null)
        {
            throw new ArgumentNullException(nameof(m_fd));
        }
        if (le == null)
        {
            throw new ArgumentNullException(nameof(le));
        }

        m_fd.AltitudeUnits = (FlightData.AltitudeUnitTypes)altUnits;
        m_fd.SpeedUnits    = (FlightData.SpeedUnitTypes)speedUnits;
        m_fd.FlightID      = le.FlightID;

        DataSourceType dst       = null;
        Action         writeData = null;

        switch ((DownloadFormat)format)
        {
        case DownloadFormat.Original:
            string szData = le.FlightData;
            dst       = DataSourceType.BestGuessTypeFromText(szData);
            writeData = () => { Response.Write(szData); };
            break;

        case DownloadFormat.CSV:
            dst       = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.CSV);
            writeData = () => { MyFlightbook.CSV.CsvWriter.WriteToStream(Response.Output, m_fd.Data, true, true); };
            break;

        case DownloadFormat.KML:
            dst       = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.KML);
            writeData = () => { m_fd.WriteKMLData(Response.OutputStream); };
            break;

        case DownloadFormat.GPX:
            dst       = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.GPX);
            writeData = () => { m_fd.WriteGPXData(Response.OutputStream); };
            break;
        }

        if (dst != null && writeData != null)
        {
            Response.Clear();
            Response.ContentType = dst.Mimetype;
            Response.AddHeader("Content-Disposition", String.Format(CultureInfo.CurrentCulture, "attachment;filename=FlightData{0}.{1}", m_fd.FlightID, dst.DefaultExtension));
            writeData();
            Response.End();
        }
    }
Пример #4
0
        public async static Task <bool> PushCloudAhoyFlight(string szUsername, LogbookEntryCore flight, FlightData fd, bool fSandbox)
        {
            if (szUsername == null)
            {
                throw new ArgumentNullException(nameof(szUsername));
            }
            if (flight == null)
            {
                throw new ArgumentNullException(nameof(flight));
            }
            if (fd == null)
            {
                throw new ArgumentNullException(nameof(fd));
            }

            Profile         pf     = Profile.GetUser(szUsername);
            CloudAhoyClient client = new CloudAhoyClient(fSandbox)
            {
                AuthState = pf.CloudAhoyToken
            };
            MemoryStream ms = null;

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

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

                ms.Seek(0, SeekOrigin.Begin);
                await client.PutStream(ms, flight).ConfigureAwait(false);

                return(true);
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }
        }
Пример #5
0
 protected void btnMerge_Click(object sender, EventArgs e)
 {
     if (Coordinates != null)
     {
         Coordinates.Sort();
         var dst = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.GPX);
         Response.Clear();
         Response.ContentType = dst.Mimetype;
         Response.AddHeader("Content-Disposition", String.Format(CultureInfo.CurrentCulture, "attachment;filename=MergedData.{0}", dst.DefaultExtension));
         using (FlightData fd = new FlightData())
             fd.WriteGPXData(Response.OutputStream, Coordinates, HasTime, HasAlt, HasSpeed);
         Response.End();
         InitPage();
     }
 }