protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.State != AjaxControlToolkit.AjaxFileUploadState.Success) { return; } using (FlightData fd = new FlightData()) { if (fd.ParseFlightData(System.Text.Encoding.UTF8.GetString(e.GetContents()))) { if (fd.HasLatLongInfo) { Coordinates.AddRange(fd.GetTrajectory()); HasTime = HasTime && fd.HasDateTime; HasAlt = HasAlt && fd.HasAltitude; HasSpeed = HasSpeed && fd.HasSpeed; } } else { lblErr.Text = fd.ErrorString; } } e.DeleteTemporaryData(); }
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 btnViewAntipodes_Click(object sender, EventArgs e) { if (!FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength > 0) { return; } byte[] rgbytes = new byte[FileUpload1.PostedFile.ContentLength]; FileUpload1.PostedFile.InputStream.Read(rgbytes, 0, FileUpload1.PostedFile.ContentLength); FileUpload1.PostedFile.InputStream.Close(); using (FlightData fdOriginal = new FlightData()) { if (fdOriginal.ParseFlightData(System.Text.Encoding.UTF8.GetString(rgbytes))) { LatLong[] rgStraight = fdOriginal.GetPath(); LatLong[] rgAntipodes = new LatLong[rgStraight.Length]; for (int i = 0; i < rgStraight.Length; i++) { rgAntipodes[i] = rgStraight[i].Antipode; } mfbGMapStraight.Map.Path = rgStraight; mfbGMapReconstituded.Map.Path = rgAntipodes; pnlMaps.Visible = true; } } }
protected void CropInRange(LogbookEntryBase le, string clipMin, string clipMax) { if (le == null) { throw new ArgumentNullException(nameof(le)); } int dataStart = (int)Math.Truncate((Convert.ToDouble(clipMin, CultureInfo.InvariantCulture) / DataCropRange) * Math.Max(DataPointCount - 1, 0)); int dataEnd = (int)Math.Truncate((Convert.ToDouble(clipMax, CultureInfo.InvariantCulture) / DataCropRange) * Math.Max(DataPointCount - 1, 0)); if (dataEnd <= dataStart) { dataEnd = dataStart + 1; } if ((dataStart == 0 && dataEnd == 0) || dataEnd >= DataPointCount) { ResetCrop(le); return; } TelemetryReference tr = le.Telemetry; tr.MetaData.DataStart = dataStart; tr.MetaData.DataEnd = dataEnd; using (FlightData fd = new FlightData()) { fd.ParseFlightData(le); tr.RecalcGoogleData(fd); } tr.Commit(); Response.Redirect(Request.RawUrl); }
protected void mfbMFUFlightImages_GeotagPhoto(object sender, PositionEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.TimeStamp == null || !e.TimeStamp.HasValue || e.ExpectedPosition != null) { return; } string szData = mfbFlightInfo1.Telemetry; if (szData == null) { return; } using (FlightData fd = new FlightData()) { if (fd.ParseFlightData(szData) && fd.HasDateTime && fd.HasLatLongInfo) { e.ExpectedPosition = Position.Interpolate(e.TimeStamp.Value, fd.GetTrajectory()); } } }
protected void btnDownload_Click(object sender, EventArgs e) { using (FlightData fd = new FlightData() { FlightID = CurrentFlightID }) { fd.ParseFlightData(CurrentFlight.FlightData); DownloadData(CurrentFlight, fd, Convert.ToInt32(cmbAltUnits.SelectedValue, CultureInfo.InvariantCulture), Convert.ToInt32(cmbSpeedUnits.SelectedValue, CultureInfo.InvariantCulture), cmbFormat.SelectedIndex); } }
/// <summary> /// Returns a KML respresentation of all of the flights represented by the specified query /// </summary> /// <param name="fq">The flight query</param> /// <param name="s">The stream to which to write</param> /// <param name="error">Any error</param> /// <param name="lstIDs">The list of specific flight IDs to request</param> /// <returns>KML string for the matching flights.</returns> public static void AllFlightsAsKML(FlightQuery fq, Stream s, out string error, IEnumerable <int> lstIDs = null) { if (fq == null) { throw new ArgumentNullException(nameof(fq)); } if (String.IsNullOrEmpty(fq.UserName) && (lstIDs == null || !lstIDs.Any())) { throw new MyFlightbookException("Don't get all flights as KML for an empty user!!"); } if (lstIDs != null) { fq.EnumeratedFlights = lstIDs; } // Get the master airport list AirportList alMaster = AllFlightsAndNavaids(fq); using (KMLWriter kw = new KMLWriter(s)) { kw.BeginKML(); error = LookAtAllFlights( fq, LogbookEntryCore.LoadTelemetryOption.LoadAll, (le) => { if (le.Telemetry.HasPath) { using (FlightData fd = new FlightData()) { try { fd.ParseFlightData(le.Telemetry.RawData, le.Telemetry.MetaData); if (fd.HasLatLongInfo) { kw.AddPath(fd.GetTrajectory(), String.Format(CultureInfo.CurrentCulture, "{0:d} - {1}", le.Date, le.Comment), fd.SpeedFactor); return; } } catch (Exception ex) when(!(ex is OutOfMemoryException)) { } // eat any error and fall through below } } // No path was found above. AirportList al = alMaster.CloneSubset(le.Route); kw.AddRoute(al.GetNormalizedAirports(), String.Format(CultureInfo.CurrentCulture, "{0:d} - {1}", le.Date, le.Route)); }, lstIDs != null && lstIDs.Any()); kw.EndKML(); } }
protected void ResetCrop(LogbookEntryBase le) { if (le == null) { throw new ArgumentNullException(nameof(le)); } TelemetryReference tr = le.Telemetry; tr.MetaData.DataEnd = tr.MetaData.DataStart = null; using (FlightData fd = new FlightData()) { fd.ParseFlightData(le); tr.RecalcGoogleData(fd); } tr.Commit(); Response.Redirect(Request.RawUrl); }
protected async void lnkSendCloudAhoy_Click(object sender, EventArgs e) { using (FlightData fd = new FlightData() { FlightID = CurrentFlightID }) { try { fd.ParseFlightData(CurrentFlight.FlightData); pnlCloudAhoySuccess.Visible = await PushToCloudahoy(Page.User.Identity.Name, CurrentFlight, fd, Convert.ToInt32(cmbAltUnits.SelectedValue, CultureInfo.InvariantCulture), Convert.ToInt32(cmbSpeedUnits.SelectedValue, CultureInfo.InvariantCulture), !Branding.CurrentBrand.MatchesHost(Request.Url.Host)).ConfigureAwait(false); } catch (MyFlightbookException ex) { lblCloudAhoyErr.Text = ex.Message; } } }
/// <summary> /// Returns the current flight data. /// </summary> protected TelemetryDataTable DataTableForFlightData(FlightData fd) { if (fd == null) { return(null); } LogbookEntryDisplay led = CurrentFlight; if (fd.NeedsComputing) { if (!fd.ParseFlightData(led) && (lblErr.Text = fd.ErrorString.Replace("\r\n", "<br />")).Length > 0) { pnlErrors.Visible = true; } } HasLatLong = fd.HasLatLongInfo; // remember this status for when we don't have the flight data object directly. return(fd.Data); }
protected void gvData_RowCommand(object sender, CommandEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } int index = Convert.ToInt32(e.CommandArgument, System.Globalization.CultureInfo.InvariantCulture); TelemetryReference ted = BoundData[index]; LogbookEntry le = new LogbookEntry(); le.FLoadFromDB(ted.FlightID.Value, Page.User.Identity.Name, LogbookEntry.LoadTelemetryOption.LoadAll, true); if (e.CommandName == "MapEm") { using (FlightData fd = new FlightData()) { if (fd.ParseFlightData(le.FlightData)) { mfbGMapStraight.Map.Path = fd.GetPath(); mfbGMapReconstituded.Map.Path = ted.GoogleData.DecodedPath(); pnlMaps.Visible = true; } } } else if (e.CommandName == "FromFlights") { le.Telemetry.Compressed = 0; // no longer know the compressed le.MoveTelemetryFromFlightEntry(); UpdateElement(index, le.Telemetry); } else if (e.CommandName == "ToFlights") { le.MoveTelemetryToFlightEntry(); UpdateElement(index, le.Telemetry); } }
/// <summary> /// Loads the data for the specified flight, parsing the CSV file, and thus initializing m_fd. This is cached, so it's OK to call multiple times. /// </summary> /// <param name="idFlight">ID of the flight with data to load</param> protected void LoadData(LogbookEntry le) { if (le == null) { throw new ArgumentNullException("le"); } string szCacheKey = KeyCacheData(le.FlightID); TelemetryDataTable dt = (TelemetryDataTable)Session[szCacheKey]; if (dt != null) { m_fd.Data = dt; } if (m_fd.NeedsComputing) { if (!m_fd.ParseFlightData(le.FlightData) && (lblErr.Text = m_fd.ErrorString.Replace("\r\n", "<br />")).Length > 0) { pnlErrors.Visible = true; } if (m_fd.Data != null) { Session[szCacheKey] = m_fd.Data; // cache the results. // now set up the chart cmbXAxis.Items.Clear(); cmbYAxis1.Items.Clear(); cmbYAxis2.Items.Clear(); cmbYAxis2.Items.Add(new ListItem(Resources.FlightData.GraphNoData, "")); cmbYAxis2.SelectedIndex = 0; foreach (DataColumn dc in m_fd.Data.Columns) { KnownColumn kc = KnownColumn.GetKnownColumn(dc.Caption); if (kc.Type.CanGraph()) { cmbXAxis.Items.Add(new ListItem(kc.FriendlyName, kc.Column)); } if (kc.Type == KnownColumnTypes.ctDec || kc.Type == KnownColumnTypes.ctFloat || kc.Type == KnownColumnTypes.ctInt) { cmbYAxis1.Items.Add(new ListItem(kc.FriendlyName, kc.Column)); cmbYAxis2.Items.Add(new ListItem(kc.FriendlyName, kc.Column)); } } // Select a date or time column for the X axis if possible; if not, select "SAMPLES" if (cmbXAxis.Items.Count > 0) { if (m_fd.Data.Columns["DATE"] != null) { cmbXAxis.SelectedValue = "DATE"; } else if (m_fd.Data.Columns["TIME"] != null) { cmbXAxis.SelectedValue = "TIME"; } else if (m_fd.Data.Columns["SAMPLE"] != null) { cmbXAxis.SelectedValue = "SAMPLE"; } else { cmbXAxis.SelectedIndex = 0; } } // if there is something numeric for the Y axis, select it. Otherwise, default to the first item. if (cmbYAxis1.Items.Count > 0) { cmbYAxis1.SelectedIndex = 0; } foreach (ListItem li in cmbYAxis1.Items) { KnownColumn kc = KnownColumn.GetKnownColumn(li.Value); if (kc.Type != KnownColumnTypes.ctDateTime && kc.Type != KnownColumnTypes.ctLatLong && kc.Column != "SAMPLE") { cmbYAxis1.SelectedValue = kc.Column; break; } } } } }