Exemplo n.º 1
0
    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;
            }
        }
    }
Exemplo n.º 2
0
    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>
        /// Sets up the specified map manager
        /// </summary>
        /// <param name="mapMgr"></param>
        /// <param name="szRoute"></param>
        /// <param name="PathLatLongArrayID"></param>
        /// <param name="fd">The flight data containing the map.</param>
        /// <returns>True if the data has latlong info and more than one row of data (i.e., is dynamic and can be downloaded</returns>
        protected bool SetUpMapManager(FlightData fd, Controls_mfbGoogleMapMgr mapMgr, string szRoute, string PathLatLongArrayID)
        {
            if (mapMgr == null)
            {
                throw new ArgumentNullException(nameof(mapMgr));
            }
            if (szRoute == null)
            {
                throw new ArgumentNullException(szRoute);
            }
            if (fd == null)
            {
                throw new ArgumentNullException(nameof(fd));
            }

            mapMgr.Map.Airports            = RoutesList(szRoute).Result;
            mapMgr.ShowMarkers             = true;
            mapMgr.Map.Options.PathVarName = PathLatLongArrayID;
            mapMgr.Map.Path = fd.GetPath();
            bool result = fd.HasLatLongInfo && fd.Data.Rows.Count > 1;

            mapMgr.Mode = result ? Mapping.GMap_Mode.Dynamic : Mapping.GMap_Mode.Static;
            return(result);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.SelectedTab = tabID.tabLogbook;

        if (!IsPostBack)
        {
            try
            {
                if (Request.PathInfo.Length > 0)
                {
                    try { CurrentFlightID = Convert.ToInt32(Request.PathInfo.Substring(1), CultureInfo.InvariantCulture); }
                    catch (FormatException) { CurrentFlightID = LogbookEntry.idFlightNone; }
                }
                if (CurrentFlightID == LogbookEntry.idFlightNone)
                {
                    throw new MyFlightbookException("No valid ID passed");
                }

                string szFQParam = util.GetStringParam(Request, "fq");
                if (!String.IsNullOrEmpty(szFQParam))
                {
                    try
                    {
                        Restriction = FlightQuery.FromBase64CompressedJSON(szFQParam);
                        Restriction.Refresh();
                    }
                    catch (ArgumentNullException) { }
                    catch (FormatException) { }
                    catch (JsonSerializationException) { }
                    catch (JsonException) { }
                }

                DetailsTab dtRequested = DetailsTab.Flight;
                if (Enum.TryParse <DetailsTab>(util.GetStringParam(Request, "tabID"), out dtRequested))
                {
                    int iTab = (int)dtRequested;
                    if (AccordionCtrl.Panes[iTab].Visible)
                    {
                        AccordionCtrl.SelectedIndex = iTab;
                    }
                }

                LogbookEntryDisplay led = CurrentFlight = LoadFlight(CurrentFlightID);
                SetUpChart(TelemetryData);
                UpdateChart();
                UpdateRestriction();

                if (Viewer.CloudAhoyToken == null || Viewer.CloudAhoyToken.AccessToken == null)
                {
                    lnkSendCloudAhoy.Visible = false;
                }

                lblOriginalFormat.Text = DataSourceType.DataSourceTypeFromFileType(led.Telemetry.TelemetryType).DisplayName;

                // allow selection of units if units are not implicitly known.
                switch (led.Telemetry.TelemetryType)
                {
                case DataSourceType.FileType.GPX:
                case DataSourceType.FileType.KML:
                case DataSourceType.FileType.NMEA:
                case DataSourceType.FileType.IGC:
                    cmbAltUnits.Enabled = cmbSpeedUnits.Enabled = false;
                    break;

                default:
                    cmbAltUnits.Enabled = cmbSpeedUnits.Enabled = true;
                    break;
                }

                // Bind details - this will bind everything else.
                fmvLE.DataSource = new LogbookEntryDisplay[] { led };
                fmvLE.DataBind();

                // shouldn't happen but sometimes does: GetUserAircraftByID returns null.  Not quite sure why.
                Aircraft ac = (new UserAircraft(led.User).GetUserAircraftByID(led.AircraftID)) ?? new Aircraft(led.AircraftID);
                fmvAircraft.DataSource = new Aircraft[] { ac };
                fmvAircraft.DataBind();

                if (String.IsNullOrEmpty(CurrentFlight.FlightData) && dtRequested != DetailsTab.Aircraft && dtRequested != DetailsTab.Flight)
                {
                    AccordionCtrl.SelectedIndex = (int)DetailsTab.Flight;
                }
            }
            catch (MyFlightbookException ex)
            {
                lblPageErr.Text       = ex.Message;
                AccordionCtrl.Visible = mfbGoogleMapManager1.Visible = pnlMap.Visible = pnlAccordionMenuContainer.Visible = pnlFlightDesc.Visible = false;
                return;
            }

            // for debugging, have a download option that skips all the rest
            if (util.GetIntParam(Request, "d", 0) != 0 && !String.IsNullOrEmpty(CurrentFlight.FlightData))
            {
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                // Give it a name that is the brand name, user's name, and date.  Convert spaces to dashes, and then strip out ANYTHING that is not alphanumeric or a dash.
                string szFilename    = String.Format(CultureInfo.InvariantCulture, "Data{0}-{1}-{2}", Branding.CurrentBrand.AppName, MyFlightbook.Profile.GetUser(Page.User.Identity.Name).UserFullName, DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Replace(" ", "-");
                string szDisposition = String.Format(CultureInfo.InvariantCulture, "inline;filename={0}.csv", System.Text.RegularExpressions.Regex.Replace(szFilename, "[^0-9a-zA-Z-]", ""));
                Response.AddHeader("Content-Disposition", szDisposition);
                Response.Write(CurrentFlight.FlightData);
                Response.End();
                return;
            }
        }
        else
        {
            m_fd.Data = TelemetryData;
            UpdateChart();
        }

        if (Restriction != null && !Restriction.IsDefault)
        {
            mfbFlightContextMenu.EditTargetFormatString = mfbFlightContextMenu.EditTargetFormatString + "?fq=" + HttpUtility.UrlEncode(Restriction.ToBase64CompressedJSONString());
        }
        mfbFlightContextMenu.Flight = CurrentFlight;

        cmbAltUnits.SelectedValue   = ((int)m_fd.AltitudeUnits).ToString(CultureInfo.InvariantCulture);
        cmbSpeedUnits.SelectedValue = ((int)m_fd.SpeedUnits).ToString(CultureInfo.InvariantCulture);
        if (!m_fd.HasDateTime)
        {
            lnkSendCloudAhoy.Visible = false;
        }

        // Set up any maps.
        mfbGoogleMapManager1.Map.Airports    = RoutesList.Result;
        mfbGoogleMapManager1.ShowMarkers     = true;
        mfbGoogleMapManager1.Map.PathVarName = PathLatLongArrayID;
        mfbGoogleMapManager1.Map.Path        = m_fd.GetPath();
        if (m_fd.HasLatLongInfo && m_fd.Data.Rows.Count > 1)
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = true;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = true;
            mfbGoogleMapManager1.Mode = MyFlightbook.Mapping.GMap_Mode.Dynamic;
            pnlMapControls.Visible    = true;
        }
        else
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = false;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = false;
            mfbGoogleMapManager1.Mode = MyFlightbook.Mapping.GMap_Mode.Static;
            pnlMapControls.Visible    = false;
        }
        lnkZoomToFit.NavigateUrl = mfbGoogleMapManager1.ZoomToFitScript;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int idFlight = util.GetIntParam(Request, "id", LogbookEntry.idFlightNone);

        if (idFlight == LogbookEntry.idFlightNone)
        {
            throw new MyFlightbookException("No valid ID passed");
        }

        Master.SelectedTab = tabID.tabLogbook;
        Master.Layout      = MasterPage.LayoutMode.Accordion;

        if (!IsPostBack)
        {
            // On a GET request, discard the cache and regenerate it.
            Session[KeyCacheData(idFlight)]   = null;
            Session[KeyCacheFlight(idFlight)] = null;
        }

        // Set up the object, either from cache or from db
        LoadLogbookEntry(idFlight);

        // for debugging, have a download option that skips all the rest
        if (util.GetIntParam(Request, "d", 0) != 0)
        {
            Response.Clear();
            Response.ContentType = "application/octet-stream";
            // Give it a name that is the brand name, user's name, and date.  Convert spaces to dashes, and then strip out ANYTHING that is not alphanumeric or a dash.
            string szFilename    = String.Format(CultureInfo.InvariantCulture, "Data{0}-{1}-{2}", Branding.CurrentBrand.AppName, MyFlightbook.Profile.GetUser(Page.User.Identity.Name).UserFullName, DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Replace(" ", "-");
            string szDisposition = String.Format(CultureInfo.InvariantCulture, "inline;filename={0}.csv", System.Text.RegularExpressions.Regex.Replace(szFilename, "[^0-9a-zA-Z-]", ""));
            Response.AddHeader("Content-Disposition", szDisposition);
            Response.Write(m_le.FlightData);
            Response.End();
            return;
        }

        LoadData(m_le);

        // Set up any maps.
        mfbGoogleMapManager1.Map.SetAirportList(new AirportList(m_le.Route));
        mfbGoogleMapManager1.ShowMarkers = true;
        if (m_fd.HasLatLongInfo && m_fd.Data.Rows.Count > 1)
        {
            pnlMap.Visible = true;
            mfbGoogleMapManager1.Map.PathVarName             = PathLatLongArrayID;
            mfbGoogleMapManager1.Map.Path                    = m_fd.GetPath();
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = true;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = true;
        }
        else
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = false;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = false;
        }
        lnkZoomToFit.NavigateUrl = mfbGoogleMapManager1.ZoomToFitScript;

        // Compute and store the distances, but only the first time since it doesn't change.
        if (!IsPostBack)
        {
            lblDistance.Text    = m_le.GetPathDistanceDescription(m_fd.ComputePathDistance());
            pnlDistance.Visible = lblDistance.Text.Length > 0;
            lblFlightDate.Text  = m_le.Date.ToShortDateString();
            lblFlightDesc.Text  = String.Format(CultureInfo.CurrentCulture, "{0} {1} {2}", m_le.TailNumDisplay ?? string.Empty, m_le.Route, m_le.Comment);
        }

        UpdateChart();
    }
Exemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.SelectedTab = tabID.tabLogbook;
        Master.Layout      = MasterPage.LayoutMode.Accordion;

        if (!IsPostBack)
        {
            try
            {
                if (Request.PathInfo.Length > 0)
                {
                    try { CurrentFlightID = Convert.ToInt32(Request.PathInfo.Substring(1), CultureInfo.InvariantCulture); }
                    catch (FormatException) { CurrentFlightID = LogbookEntry.idFlightNone; }
                }
                if (CurrentFlightID == LogbookEntry.idFlightNone)
                {
                    throw new MyFlightbookException("No valid ID passed");
                }

                string szFQParam = util.GetStringParam(Request, "fq");
                if (!String.IsNullOrEmpty(szFQParam))
                {
                    try
                    {
                        Restriction = FlightQuery.FromBase64CompressedJSON(szFQParam);
                        Restriction.Refresh();
                    }
                    catch (ArgumentNullException) { }
                    catch (FormatException) { }
                    catch (JsonSerializationException) { }
                    catch (JsonException) { }
                }

                DetailsTab dtRequested = DetailsTab.Flight;
                if (Enum.TryParse <DetailsTab>(util.GetStringParam(Request, "tabID"), out dtRequested))
                {
                    int iTab = (int)dtRequested;
                    if (AccordionCtrl.Panes[iTab].Visible)
                    {
                        AccordionCtrl.SelectedIndex = iTab;
                    }
                }

                LogbookEntryDisplay led = CurrentFlight = LoadFlight(CurrentFlightID);
                SetUpChart(TelemetryData);
                UpdateChart();
                UpdateRestriction();

                // Bind details - this will bind everything else.
                fmvLE.DataSource = new LogbookEntryDisplay[] { led };
                fmvLE.DataBind();
                fmvAircraft.DataSource = new Aircraft[] { new UserAircraft(led.User).GetUserAircraftByID(led.AircraftID) };
                fmvAircraft.DataBind();



                if (String.IsNullOrEmpty(CurrentFlight.FlightData) && dtRequested != DetailsTab.Aircraft && dtRequested != DetailsTab.Flight)
                {
                    AccordionCtrl.SelectedIndex = (int)DetailsTab.Flight;
                }
            }
            catch (MyFlightbookException ex)
            {
                lblPageErr.Text       = ex.Message;
                AccordionCtrl.Visible = mfbGoogleMapManager1.Visible = pnlMap.Visible = pnlAccordionMenuContainer.Visible = pnlFlightDesc.Visible = false;
                return;
            }

            // for debugging, have a download option that skips all the rest
            if (util.GetIntParam(Request, "d", 0) != 0 && !String.IsNullOrEmpty(CurrentFlight.FlightData))
            {
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                // Give it a name that is the brand name, user's name, and date.  Convert spaces to dashes, and then strip out ANYTHING that is not alphanumeric or a dash.
                string szFilename    = String.Format(CultureInfo.InvariantCulture, "Data{0}-{1}-{2}", Branding.CurrentBrand.AppName, MyFlightbook.Profile.GetUser(Page.User.Identity.Name).UserFullName, DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).Replace(" ", "-");
                string szDisposition = String.Format(CultureInfo.InvariantCulture, "inline;filename={0}.csv", System.Text.RegularExpressions.Regex.Replace(szFilename, "[^0-9a-zA-Z-]", ""));
                Response.AddHeader("Content-Disposition", szDisposition);
                Response.Write(CurrentFlight.FlightData);
                Response.End();
                return;
            }
        }
        else
        {
            m_fd.Data = TelemetryData;
            UpdateChart();
        }

        // Set up any maps.
        mfbGoogleMapManager1.Map.Airports    = RoutesList.Result;
        mfbGoogleMapManager1.ShowMarkers     = true;
        mfbGoogleMapManager1.Map.PathVarName = PathLatLongArrayID;
        mfbGoogleMapManager1.Map.Path        = m_fd.GetPath();
        if (m_fd.HasLatLongInfo && m_fd.Data.Rows.Count > 1)
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = true;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = true;
        }
        else
        {
            cmbFormat.Items[(int)DownloadFormat.KML].Enabled = false;
            cmbFormat.Items[(int)DownloadFormat.GPX].Enabled = false;
        }
        lnkZoomToFit.NavigateUrl = mfbGoogleMapManager1.ZoomToFitScript;
    }