protected void lnkViewKML_Click(object sender, EventArgs e) { int id = hdnID.Value.SafeParseInt(-1); if (id <= 0) { return; } LogbookEntry le = new LogbookEntry(id, User.Identity.Name, LogbookEntry.LoadTelemetryOption.LoadAll); if (le == null || String.IsNullOrEmpty(le.FlightData)) { return; } using (FlightData fd = new FlightData()) { fd.ParseFlightData(le.FlightData); if (fd.HasLatLongInfo) { { DataSourceType dst = DataSourceType.DataSourceTypeFromFileType(DataSourceType.FileType.KML); Response.Clear(); Response.ContentType = dst.Mimetype; Response.AddHeader("Content-Disposition", String.Format(CultureInfo.CurrentCulture, "attachment;filename=FlightData{0}.{1}", le.FlightID, dst.DefaultExtension)); fd.WriteKMLData(Response.OutputStream); Response.End(); } } } }
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(); } }
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(); } }