/// <summary> /// Updates the starting flight with the specified value in the specified column /// </summary> /// <param name="sfc">The column to read</param> /// <param name="sf">The target starting flight</param> /// <param name="value">The value</param> protected static void SetValueForColumn(StartingFlightColumn sfc, LogbookEntryCore sf, Decimal value) { if (sf == null) { throw new ArgumentNullException(nameof(sf)); } switch (sfc) { case StartingFlightColumn.CFI: sf.CFI = value; break; case StartingFlightColumn.SIC: sf.SIC = value; break; case StartingFlightColumn.PIC: sf.PIC = value; break; case StartingFlightColumn.Total: sf.TotalFlightTime = value; break; } }
private void SetImages(LogbookEntryCore le) { if (this.Master.IsMobileSession()) { mfbIlAirplane.Columns = mfbIlFlight.Columns = 1; } mfbIlFlight.Key = hdnID.Value; mfbIlFlight.Refresh(); mfbIlAirplane.Key = le.AircraftID.ToString(CultureInfo.InvariantCulture); mfbIlAirplane.AltText = le.TailNumDisplay; UserAircraft ua = new UserAircraft(le.User); Aircraft ac = ua.GetUserAircraftByID(le.AircraftID) ?? new Aircraft(le.AircraftID); mfbIlAirplane.DefaultImage = ac.DefaultImage; mfbIlAirplane.Refresh(); List <MFBImageInfo> lst = new List <MFBImageInfo>(mfbIlFlight.Images.ImageArray); lst.AddRange(mfbIlAirplane.Images.ImageArray); imgsliderFlights.Images = lst; imgsliderFlights.Visible = lst.Count > 0; mfbVideoEntry1.Videos.Clear(); foreach (VideoRef vid in le.Videos) { mfbVideoEntry1.Videos.Add(vid); } }
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)); } }
/// <summary> /// Returns the Uri to view a flight (useful for FB/Twitter/Etc.) /// </summary> /// <param name="le">The flight to be shared</param> /// <param name="szHost">Hostname (if not provided, uses current brand)</param> /// <returns></returns> public static Uri ShareFlightUri(LogbookEntryCore le, string szHost = null) { if (le == null) { throw new ArgumentNullException(nameof(le)); } return(String.Format(CultureInfo.InvariantCulture, "~/Public/ViewPublicFlight.aspx/{0}?v={1}", le.FlightID, (new Random()).Next(10000)).ToAbsoluteURL("https", szHost ?? Branding.CurrentBrand.HostName)); }
protected static void SetIgnoreFlagForFlight(LogbookEntryCore le, bool fIgnore) { if (le == null) { throw new ArgumentNullException(nameof(le)); } le.Route = String.Format(CultureInfo.CurrentCulture, "{0}{1}", le.Route.Trim(), fIgnore ? FlightLint.IgnoreMarker : string.Empty); }
protected static string FormatNameForTelemetry(LogbookEntryCore led) { if (led == null) { throw new ArgumentNullException(nameof(led)); } return(DataSourceType.DataSourceTypeFromFileType(led.Telemetry.TelemetryType).DisplayName); }
public CloudAhoyPostFileMetaData(LogbookEntryCore le) : this() { if (le == null) { throw new ArgumentNullException(nameof(le)); } tail = le.TailNumDisplay; remarks = le.Comment; }
/// <summary> /// Initializes the specified starting flight with the values of the decimal edits in the row /// </summary> /// <param name="sf">The starting flight</param> /// <param name="iRow">The row</param> protected void FromRow(LogbookEntryCore sf, int iRow) { int iCol = 0; foreach (StartingFlightColumn sfc in Enum.GetValues(typeof(StartingFlightColumn))) { Controls_mfbDecimalEdit de = (Controls_mfbDecimalEdit)tblStartingFlights.Rows[iRow].FindControl(IDForCell(iRow, iCol)); SetValueForColumn(sfc, sf, de.Value); iCol++; } }
/// <summary> /// Get any pending flights for the specified user /// </summary> /// <param name="szUser">username for whom to retrieve flights</param> /// <returns>An enumerable of flights</returns> static public IEnumerable <PendingFlight> PendingFlightsForUser(string szUser) { List <PendingFlight> lst = new List <PendingFlight>(); DBHelper dbh = new DBHelper("SELECT * FROM pendingflights WHERE username=?user"); dbh.ReadRows((comm) => { comm.Parameters.AddWithValue("user", szUser); }, (dr) => { lst.Add(new PendingFlight(dr)); }); // Sort by date, desc lst.Sort((l1, l2) => { return(LogbookEntryCore.CompareFlights(l1, l2, "Date", System.Web.UI.WebControls.SortDirection.Descending)); }); return(lst); }
/// <summary> /// Updates recent flights for the specified flight, removing it if it is no longer public /// </summary> /// <param name="le"></param> public static void RefreshForFlight(LogbookEntryCore le) { if (le == null) { throw new ArgumentNullException(nameof(le)); } FlightStats fs = CachedStats(); if (fs != null && fs.RecentPublicFlights != null && !le.fIsPublic) { fs.m_lstFlights.RemoveAll(l => l.FlightID == le.FlightID); } }
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(); } } }
protected void AddErrorRow(LogbookEntryCore le, string szContext, int iRow) { if (le == null) { throw new ArgumentNullException(nameof(le)); } if (IsPendingOnly && le.LastError != LogbookEntryCore.ErrorCode.None) // ignore errors if the importer is only pending flights and the error is a logbook validation error (no tail, future date, night, etc.) { return; } // if we're here, we are *either* not pending only *or* we didn't have a logbookentry validation error (e.g., could be malformed row) ErrorContext[iRow] = szContext; // save the context for data bind AddTextRow(plcErrorList, String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.errImportRowHasError, iRow, le.ErrorString), "error"); }
/// <summary> /// Pushes flight data to CloudAhoy /// </summary> /// <param name="s">The KML or GPX stream</param> /// <param name="le">The parent flight (for metadata)</param> public async Task <bool> PutStream(Stream s, LogbookEntryCore le) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (le == null) { throw new ArgumentNullException(nameof(le)); } HttpResponseMessage response = null; using (MultipartFormDataContent form = new MultipartFormDataContent()) { using (StringContent sc = new StringContent(JsonConvert.SerializeObject(new CloudAhoyPostFileMetaData(le)))) { form.Add(sc, "METADATA"); using (StreamContent streamContent = new StreamContent(s)) { form.Add(streamContent, "IMPORT", "data.gpx"); string szResult = string.Empty; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + AuthState.AccessToken); try { using (response = await httpClient.PostAsync(new Uri(FlightsEndpoint), form).ConfigureAwait(false)) { szResult = response.Content.ReadAsStringAsync().Result; response.EnsureSuccessStatusCode(); } } catch (HttpRequestException ex) { throw new MyFlightbookException(ex.Message + " " + response.ReasonPhrase + " " + TextFromHTML(szResult), ex); } } } } } return(true); }
protected static bool CanSpecifyUnitsForTelemetry(LogbookEntryCore led) { if (led == null) { throw new ArgumentNullException(nameof(led)); } switch (led.Telemetry.TelemetryType) { case DataSourceType.FileType.GPX: case DataSourceType.FileType.KML: case DataSourceType.FileType.NMEA: case DataSourceType.FileType.IGC: return(false); default: return(true); } }
/// <summary> /// Pushes flight data to CloudAhoy /// </summary> /// <param name="s">The KML or GPX stream</param> /// <param name="le">The parent flight (for metadata)</param> public async Task <bool> PutStream(Stream s, LogbookEntryCore le) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (le == null) { throw new ArgumentNullException(nameof(le)); } using (MultipartFormDataContent form = new MultipartFormDataContent()) { using (StringContent sc = new StringContent(JsonConvert.SerializeObject(new CloudAhoyPostFileMetaData(le)))) { form.Add(sc, "METADATA"); using (StreamContent streamContent = new StreamContent(s)) { form.Add(streamContent, "IMPORT", "data.gpx"); string szResult = (string)await SharedHttpClient.GetResponseForAuthenticatedUri(new Uri(FlightsEndpoint), AuthState.AccessToken, form, (response) => { string result = string.Empty; try { result = response.Content.ReadAsStringAsync().Result; response.EnsureSuccessStatusCode(); return(result); } catch (HttpRequestException ex) { throw new MyFlightbookException(ex.Message + " " + response.ReasonPhrase + " " + TextFromHTML(result), ex); } }); } } } return(true); }
/// <summary> /// Gets the value from the starting flight in the specified column /// </summary> /// <param name="sfc">the column to read</param> /// <param name="sf">The starting flight</param> /// <returns>The appropriate column value</returns> protected static Decimal GetValueForColumn(StartingFlightColumn sfc, LogbookEntryCore sf) { if (sf == null) { throw new ArgumentNullException(nameof(sf)); } switch (sfc) { case StartingFlightColumn.CFI: return(sf.CFI); case StartingFlightColumn.SIC: return(sf.SIC); case StartingFlightColumn.PIC: return(sf.PIC); case StartingFlightColumn.Total: return(sf.TotalFlightTime); } return(0.0M); }
protected void rptPreview_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } LogbookEntryCore le = (LogbookEntryCore)e.Item.DataItem; PlaceHolder plc = (PlaceHolder)e.Item.FindControl("plcAdditional"); // throw the less used properties into the final column if (le.EngineStart.HasValue()) { AddTextRow(plc, String.Format(CultureInfo.CurrentCulture, "Engine Start: {0}", le.EngineStart.UTCDateFormatString())); } if (le.EngineEnd.HasValue()) { AddTextRow(plc, String.Format(CultureInfo.CurrentCulture, "Engine End: {0}", le.EngineEnd.UTCDateFormatString())); } if (le.FlightStart.HasValue()) { AddTextRow(plc, String.Format(CultureInfo.CurrentCulture, "Flight Start: {0}", le.FlightStart.UTCDateFormatString())); } if (le.FlightEnd.HasValue()) { AddTextRow(plc, String.Format(CultureInfo.CurrentCulture, "Flight End: {0}", le.FlightEnd.UTCDateFormatString())); } if (le.HobbsStart != 0) { AddTextRow(plc, String.Format(CultureInfo.CurrentCulture, "Hobbs Start: {0}", le.HobbsStart)); } if (le.HobbsEnd != 0) { AddTextRow(plc, String.Format(CultureInfo.CurrentCulture, "Hobbs End: {0}", le.HobbsEnd)); } // Add a concatenation of each property to the row as well. foreach (CustomFlightProperty cfp in le.CustomProperties) { AddTextRow(plc, UseHHMM ? cfp.DisplayStringHHMM : cfp.DisplayString); } if (!String.IsNullOrEmpty(le.ErrorString)) { int iRow = e.Item.ItemIndex + 1; if (ErrorContext.ContainsKey(iRow)) { ((Label)e.Item.FindControl("lblRawRow")).Text = ErrorContext[iRow]; e.Item.FindControl("rowError").Visible = true; ((System.Web.UI.HtmlControls.HtmlTableRow)e.Item.FindControl("rowFlight")).Attributes["class"] = "error"; } else { e.Item.FindControl("imgNewOrUpdate").Visible = false; } } if (!le.IsNewFlight && CurrentImporter != null && CurrentImporter.OriginalFlightsToModify.ContainsKey(le.FlightID)) { List <PropertyDelta> lst = new List <PropertyDelta>(CurrentImporter.OriginalFlightsToModify[le.FlightID].CompareTo(le, UseHHMM)); if (lst.Count > 0) { e.Item.FindControl("pnlDiffs").Visible = true; Repeater diffs = (Repeater)e.Item.FindControl("rptDiffs"); diffs.DataSource = lst; diffs.DataBind(); } } }
protected static void AddSuccessRow(LogbookEntryCore le, int iRow) { }