Exemplo n.º 1
0
        public virtual double get_routes_distance(airport source, airport sink)
        {
            KeyValuePair <int, int> Key = new KeyValuePair <int, int>(source.airport_ID, sink.airport_ID);

            return((airports_pair_distance_index.ContainsKey(Key)) ?
                   airports_pair_distance_index[Key] : DISCONNECTED);
        }
Exemplo n.º 2
0
    public static void DeleteDupeUserAirport(string idDelete, string idMap, string szUser, string szType)
    {
        CheckAdmin();

        airport apToDelete = new airport(idDelete, "(None)", 0, 0, szType, string.Empty, 0, szUser);

        if (apToDelete.FDelete(true))
        {
            if (!String.IsNullOrEmpty(szUser))
            {
                DBHelper dbh = new DBHelper("UPDATE flights SET route=REPLACE(route, ?idDelete, ?idMap) WHERE username=?user AND route LIKE CONCAT('%', ?idDelete, '%')");
                if (!dbh.DoNonQuery((comm) =>
                {
                    comm.Parameters.AddWithValue("idDelete", idDelete);
                    comm.Parameters.AddWithValue("idMap", idMap);
                    comm.Parameters.AddWithValue("user", szUser);
                }))
                {
                    throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, "Error mapping from {0} to {1} in flights for user {2}: {3}", idDelete, idMap, szUser, dbh.LastError));
                }
            }
        }
        else
        {
            throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, "Error deleting airport {0}: {1}", apToDelete.Code, apToDelete.ErrorText));
        }
    }
Exemplo n.º 3
0
        public void correct_cost_backward(airport airport)
        {
            List <airport> airports_list = new List <airport>();

            airports_list.Add(airport);

            while (airports_list.Count > 0)
            {
                airport cur_airport = airports_list[0];
                airports_list.RemoveAt(0);
                double cost_of_cur_airport = start_airport_distance_index[cur_airport.airport_ID];

                List <airport> pre_airport_set = graph.get_precedent_airports(cur_airport);
                foreach (airport pre_airport in pre_airport_set)
                {
                    double cost_of_pre_airport = start_airport_distance_index.ContainsKey(pre_airport.airport_ID) ?
                                                 start_airport_distance_index[pre_airport.airport_ID] : GraphAirports.DISCONNECTED;

                    double fresh_cost = cost_of_cur_airport + graph.get_routes_distance(pre_airport, cur_airport);

                    if (cost_of_pre_airport > fresh_cost)
                    {
                        start_airport_distance_index[pre_airport.airport_ID] = fresh_cost;
                        predecessor_index[pre_airport.airport_ID]            = cur_airport;
                        airports_list.Add(pre_airport);
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected void determine_shortest_paths(airport source_airport,
                                                airport sink_airport, bool is_source2sink)
        {
            clear();


            airport end_airport   = is_source2sink ? sink_airport : source_airport;
            airport start_airport = is_source2sink ? source_airport : sink_airport;

            start_airport_distance_index[start_airport.airport_ID] = 0.0;
            start_airport.set_distance(0.0);
            airports_candidate_queue.Add(start_airport);

            while (!airports_candidate_queue.IsEmpty())
            {
                airport cur_candidate = airports_candidate_queue.Poll();

                if (cur_candidate.Equals(end_airport))
                {
                    break;
                }

                determined_airports_set.Add(cur_candidate);

                improve_to_airport(cur_candidate, is_source2sink);
            }
        }
Exemplo n.º 5
0
        private void improve_to_airport(airport airport, bool is_source2sink)
        {
            List <airport> neighbor_airports_list = is_source2sink ?
                                                    graph.get_adjacent_airports(airport) : graph.get_precedent_airports(airport);

            foreach (airport cur_adjacent_airport in neighbor_airports_list)
            {
                if (determined_airports_set.Contains(cur_adjacent_airport))
                {
                    continue;
                }

                double distance = start_airport_distance_index.ContainsKey(airport.airport_ID) ?
                                  start_airport_distance_index[airport.airport_ID] : GraphAirports.DISCONNECTED;

                distance += is_source2sink ? graph.get_routes_distance(airport, cur_adjacent_airport)
                    : graph.get_routes_distance(cur_adjacent_airport, airport);

                if (!start_airport_distance_index.ContainsKey(cur_adjacent_airport.airport_ID) ||
                    start_airport_distance_index[cur_adjacent_airport.airport_ID] > distance)
                {
                    start_airport_distance_index[cur_adjacent_airport.airport_ID] = distance;

                    predecessor_index[cur_adjacent_airport.airport_ID] = airport;

                    cur_adjacent_airport.set_distance(distance);
                    airports_candidate_queue.Add(cur_adjacent_airport);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Generate a new question, increment the current question index
        /// </summary>
        /// <returns></returns>
        public void GenerateQuestion()
        {
            airport[] rgAirportAnswers = new airport[BluffCount + 1];
            CurrentQuestion = new AirportQuizQuestion(rgAirportAnswers, this.Random.Next(BluffCount + 1));

            // set the index of the correct answer
            rgAirportAnswers[CurrentQuestion.CorrectAnswerIndex] = m_rgAirport[m_rgShuffle[this.CurrentQuestionIndex]];

            // fill in the ringers...
            int[] rgBluffs = ShuffleIndex(m_rgAirport.Length);
            for (int i = 0, iBluff = 0; i < BluffCount; i++)
            {
                // see if the airport index of the bluff is the same as the index of the correct answer
                if (rgBluffs[iBluff] == m_rgShuffle[CurrentQuestionIndex])
                {
                    iBluff = (iBluff + 1) % rgBluffs.Length;
                }

                int iResponse = (CurrentQuestion.CorrectAnswerIndex + i + 1) % (BluffCount + 1);

                rgAirportAnswers[iResponse] = m_rgAirport[rgBluffs[iBluff]];

                iBluff = (iBluff + 1) % rgBluffs.Length;
            }

            m_CurrentIndex++;
        }
Exemplo n.º 7
0
    protected airport[] GetUserAirports(string szDefault)
    {
        if (!Page.User.Identity.IsAuthenticated)
        {
            lblDebug.Text = Resources.LocalizedText.AirportGameUnauthenticated;
            return((new AirportList(szDefault)).GetAirportList());
        }

        VisitedAirport[] rgva = VisitedAirport.VisitedAirportsForUser(Page.User.Identity.Name);

        if (rgva.Length < 15)
        {
            lblDebug.Text = Resources.LocalizedText.AirportGameTooFewAirports;
            return(airport.AirportsWithExactMatch(szDefault).ToArray());
        }

        airport[] rgap = new airport[rgva.Length];

        int i = 0;

        foreach (VisitedAirport va in rgva)
        {
            rgap[i++] = va.Airport;
        }

        return(rgap);
    }
Exemplo n.º 8
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (!double.TryParse(txtLat.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double lat) ||
            !double.TryParse(txtLong.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double lon))
        {
            lblErr.Text = Resources.Airports.errInvalidLatLong;
            return;
        }

        bool    fAdmin = (IsAdmin && ckAsAdmin.Checked);
        airport ap     = new airport(txtCode.Text.ToUpper(CultureInfo.InvariantCulture), txtName.Text, lat, lon, cmbType.SelectedValue, cmbType.SelectedItem.Text, 0.0, fAdmin ? string.Empty : Page.User.Identity.Name);

        if (fAdmin && ap.Code.CompareOrdinalIgnoreCase("TBD") == 0)
        {
            lblErr.Text = Resources.Airports.errTBDIsInvalidCode;
            return;
        }

        lblErr.Text = string.Empty;

        if (ap.FCommit(fAdmin, fAdmin))
        {
            // Check to see if this looks like a duplicate - if so, submit it for review
            List <airport> lstDupes = new List <airport>(airport.AirportsNearPosition(ap.LatLong.Latitude, ap.LatLong.Longitude, 20, ap.FacilityTypeCode.CompareCurrentCultureIgnoreCase("H") == 0));
            lstDupes.RemoveAll(a => !a.IsPort || a.Code.CompareCurrentCultureIgnoreCase(ap.Code) == 0 || a.DistanceFromPosition > 3);
            if (lstDupes.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat(CultureInfo.CurrentCulture, "User: {0}, Airport: {1} ({2}) {3} {4}\r\n\r\nCould match:\r\n", ap.UserName, ap.Code, ap.FacilityTypeCode, ap.Name, ap.LatLong.ToDegMinSecString());
                foreach (airport a in lstDupes)
                {
                    sb.AppendFormat(CultureInfo.CurrentCulture, "{0} - ({1}) {2} {3}\r\n", a.Code, a.FacilityTypeCode, a.Name, a.LatLong.ToDegMinSecString());
                }
                util.NotifyAdminEvent("New airport created - needs review", sb.ToString(), ProfileRoles.maskCanManageData);
            }

            initForm();
            Cache.Remove(CacheKeyUserAirports);

            if (!fAdmin || ckShowAllUserAirports.Checked)
            {
                RefreshMyAirports();
            }
            else
            {
                gvMyAirports.DataSource = null;
                gvMyAirports.DataBind();
            }

            if (fAdmin)
            {
                UpdateImportData();
            }
        }
        else
        {
            lblErr.Text = HttpUtility.HtmlEncode(ap.ErrorText);
        }
    }
 protected string ZoomLink(airport ap)
 {
     if (ap == null)
     {
         throw new ArgumentNullException(nameof(ap));
     }
     return(String.Format(System.Globalization.CultureInfo.InvariantCulture, "javascript:{0}.gmap.setCenter(new google.maps.LatLng({1}, {2}));{0}.gmap.setZoom(14);", GoogleMapID, ap.LatLong.LatitudeString, ap.LatLong.LongitudeString));
 }
Exemplo n.º 10
0
        private void CheckAirportIssues(LogbookEntryBase le)
        {
            IEnumerable <string> rgCodes = airport.SplitCodes(le.Route);

            foreach (string szCode in rgCodes)
            {
                if (szCode.StartsWith(airport.ForceNavaidPrefix, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                if (szCode.CompareCurrentCultureIgnoreCase("LOCAL") == 0 || szCode.CompareCurrentCultureIgnoreCase("LCL") == 0)
                {
                    AddIssue(LintOptions.AirportIssues, Resources.FlightLint.warningAirportLocal);
                    continue;
                }

                airport ap = alSubset.GetAirportByCode(szCode);

                if (ap == null)
                {
                    AddIssue(LintOptions.AirportIssues, String.Format(CultureInfo.CurrentCulture, Resources.FlightLint.warningAirportNotFound, szCode));
                }
                else
                {
                    AddConditionalIssue((currentCatClassID == CategoryClass.CatClassID.AMEL || currentCatClassID == CategoryClass.CatClassID.ASEL) && ap.IsSeaport, LintOptions.AirportIssues, String.Format(CultureInfo.CurrentCulture, Resources.FlightLint.warningAirportLandPlaneAtSeaport, szCode));
                    AddConditionalIssue(CategoryClass.IsAirplane(currentCatClassID) && ap.FacilityTypeCode == "H", LintOptions.AirportIssues, String.Format(CultureInfo.CurrentCulture, Resources.FlightLint.warningAirportAirplaneAtHeliport, szCode));
                }
            }

            // Sanity check for speed
            if (le.TotalFlightTime > 0)
            {
                double dist  = alSubset.DistanceForRoute();
                double speed = dist / (double)le.TotalFlightTime;

                AddConditionalIssue(speed > (currentModel.EngineType == MakeModel.TurbineLevel.Piston ? 500 : 1000), LintOptions.AirportIssues, String.Format(CultureInfo.CurrentCulture, Resources.FlightLint.warningAirportUnlikelyImpliedSpeed, speed));
            }

            // Look for missing night takeoffs or landings
            if (rgCodes.Any())
            {
                airport apDep = alSubset.GetAirportByCode(rgCodes.ElementAt(0));
                airport apArr = alSubset.GetAirportByCode(rgCodes.ElementAt(rgCodes.Count() - 1));
                if (apDep != null)
                {
                    AddConditionalIssue(le.FlightStart.HasValue() && !le.CustomProperties.PropertyExistsWithID(CustomPropertyType.KnownProperties.IDPropNightTakeoff) &&
                                        new SolarTools.SunriseSunsetTimes(le.FlightStart, apDep.LatLong.Latitude, apDep.LatLong.Longitude).IsFAANight, LintOptions.AirportIssues, String.Format(CultureInfo.CurrentCulture, Resources.FlightLint.warningAirportMissingNightTakeoff, apDep.Code, le.FlightStart.UTCFormattedStringOrEmpty(false)));
                }
                if (apArr != null)
                {
                    AddConditionalIssue(le.FlightEnd.HasValue() && le.NightLandings == 0 &&
                                        new SolarTools.SunriseSunsetTimes(le.FlightEnd, apArr.LatLong.Latitude, apArr.LatLong.Longitude).IsFAANight, LintOptions.AirportIssues, String.Format(CultureInfo.CurrentCulture, Resources.FlightLint.warningAirportMissingNightLanding, apArr.Code, le.FlightEnd.UTCFormattedStringOrEmpty(false)));
                }
            }
        }
Exemplo n.º 11
0
        public override double get_routes_distance(airport source, airport sink)
        {
            int source_id = source.airport_ID;
            int sink_id   = sink.airport_ID;

            if (rem_airport_id_set.Contains(source_id) || rem_airport_id_set.Contains(sink_id) ||
                rem_route_set.Contains(new KeyValuePair <int, int>(source_id, sink_id)))
            {
                return(GraphAirports.DISCONNECTED);
            }
            return(base.get_routes_distance(source, sink));
        }
Exemplo n.º 12
0
 protected void gvMyAirports_RowDataBound(Object sender, GridViewRowEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         HyperLink l  = (HyperLink)e.Row.FindControl("lnkZoomCode");
         airport   ap = (airport)e.Row.DataItem;
         l.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "javascript:updateForAirport('{0}', '{1}', '{2}', {3}, {4});", ap.Code, ap.Name.Replace("'", "\\'").Replace("\"", "\\\""), ap.FacilityTypeCode, ap.LatLong.LatitudeString, ap.LatLong.LongitudeString);
     }
 }
Exemplo n.º 13
0
 protected void fvClub_ItemUpdating(object sender, FormViewUpdateEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     Page.Validate("valEditClub");
     if (Page.IsValid)
     {
         Club c = ActiveClub ?? new Club();
         c.City            = (string)e.NewValues["City"];
         c.ContactPhone    = (string)e.NewValues["ContactPhone"];
         c.Country         = (string)e.NewValues["Country"];
         c.Description     = Controls_mfbHtmlEdit.FixHtml((string)e.NewValues["Description"]);
         c.HomeAirportCode = (string)e.NewValues["HomeAirportCode"];
         if (!String.IsNullOrEmpty(c.HomeAirportCode))
         {
             AirportList    al  = new AirportList(c.HomeAirportCode);
             List <airport> lst = new List <airport>(al.GetAirportList());
             airport        ap  = lst.FirstOrDefault(a => a.IsPort);
             c.HomeAirportCode = ap == null ? c.HomeAirportCode : ap.Code;
         }
         c.Name          = (string)e.NewValues["Name"];
         c.StateProvince = (string)e.NewValues["StateProvince"];
         c.URL           = (string)e.NewValues["URL"];
         c.ID            = Convert.ToInt32(e.NewValues["ID"], CultureInfo.InvariantCulture);
         c.RestrictEditingToOwnersAndAdmins = Convert.ToBoolean(e.NewValues["RestrictEditingToOwnersAndAdmins"], CultureInfo.InvariantCulture);
         c.IsPrivate = Convert.ToBoolean(e.NewValues["IsPrivate"], CultureInfo.InvariantCulture);
         c.PrependsScheduleWithOwnerName = Convert.ToBoolean(e.NewValues["PrependsScheduleWithOwnerName"], CultureInfo.InvariantCulture);
         c.DeleteNotifications           = (Club.DeleteNoficiationPolicy)Enum.Parse(typeof(Club.DeleteNoficiationPolicy), (string)e.NewValues["DeleteNotifications"]);
         c.DoubleBookRoleRestriction     = (Club.DoubleBookPolicy)Enum.Parse(typeof(Club.DoubleBookPolicy), (string)e.NewValues["DoubleBookRoleRestriction"]);
         c.AddModifyNotifications        = (Club.AddModifyNotificationPolicy)Enum.Parse(typeof(Club.AddModifyNotificationPolicy), (string)e.NewValues["AddModifyNotifications"]);
         c.TimeZone = TimeZoneInfo.FindSystemTimeZoneById((string)e.NewValues["TimeZone.Id"]);
         if (c.IsNew)
         {
             c.Creator = Page.User.Identity.Name;
         }
         if (c.FCommit())
         {
             if (ClubChanged != null)
             {
                 ClubChanged(this, new ClubChangedEventsArgs(ActiveClub));
             }
             this.ActiveClub = c;
         }
         else
         {
             lblErr.Text = c.LastError;
         }
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Returns an array of airports - in order and including duplicates - from the normalized list of airports.
        /// </summary>
        /// <returns></returns>
        public airport[] GetNormalizedAirports()
        {
            ArrayList al = new ArrayList();

            foreach (string sz in m_rgszAirportsNormal)
            {
                airport ap = GetAirportByCode(sz);
                if (ap != null)
                {
                    al.Add(ap);
                }
            }
            return((airport[])al.ToArray(typeof(airport)));
        }
Exemplo n.º 15
0
        public Path update_cost_forward(airport airport)
        {
            double cost = GraphAirports.DISCONNECTED;

            List <airport> adj_vertex_set = graph.get_adjacent_airports(airport);

            if (!start_airport_distance_index.ContainsKey(airport.airport_ID))
            {
                start_airport_distance_index[airport.airport_ID] = GraphAirports.DISCONNECTED;
            }

            foreach (airport cur_airport in adj_vertex_set)
            {
                double distance = start_airport_distance_index.ContainsKey(cur_airport.airport_ID) ?
                                  start_airport_distance_index[cur_airport.airport_ID] : GraphAirports.DISCONNECTED;

                distance += graph.get_routes_distance(airport, cur_airport);

                double cost_of_vertex = start_airport_distance_index[airport.airport_ID];
                if (cost_of_vertex > distance)
                {
                    start_airport_distance_index[airport.airport_ID] = distance;
                    predecessor_index[airport.airport_ID]            = cur_airport;
                    cost = distance;
                }
            }

            Path sub_path = null;

            if (cost < GraphAirports.DISCONNECTED)
            {
                sub_path = new Path();
                sub_path.set_distance(cost);
                List <airport> airports_list = sub_path.get_airports();
                airports_list.Add(airport);

                airport sel_airport = predecessor_index[airport.airport_ID];


                while (predecessor_index.ContainsKey(sel_airport.airport_ID))
                {
                    airports_list.Add(sel_airport);
                    sel_airport = predecessor_index[sel_airport.airport_ID];
                }
                airports_list.Add(sel_airport);
            }

            return(sub_path);
        }
Exemplo n.º 16
0
 protected void gvMyAirports_RowDataBound(Object sender, GridViewRowEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         HyperLink l  = (HyperLink)e.Row.FindControl("lnkZoomCode");
         airport   ap = (airport)e.Row.DataItem;
         l.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "javascript:updateForAirport({0});", JsonConvert.SerializeObject(ap, new JsonSerializerSettings()
         {
             DefaultValueHandling = DefaultValueHandling.Ignore
         }));
     }
 }
Exemplo n.º 17
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        double lat, lon;

        if (!double.TryParse(txtLat.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out lat) ||
            !double.TryParse(txtLong.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out lon))
        {
            lblErr.Text = Resources.Airports.errInvalidLatLong;
            return;
        }

        bool    fAdmin = (IsAdmin && ckAsAdmin.Checked);
        airport ap     = new airport(txtCode.Text.ToUpper(CultureInfo.InvariantCulture), txtName.Text, lat, lon, cmbType.SelectedValue, cmbType.SelectedItem.Text, 0.0, fAdmin ? string.Empty : Page.User.Identity.Name);

        if (fAdmin && ap.Code.CompareOrdinalIgnoreCase("TBD") == 0)
        {
            lblErr.Text = Resources.Airports.errTBDIsInvalidCode;
            return;
        }

        lblErr.Text = "";

        if (ap.FCommit(fAdmin, fAdmin))
        {
            initForm();
            Cache.Remove(CacheKeyUserAirports);

            if (!fAdmin || ckShowAllUserAirports.Checked)
            {
                RefreshMyAirports();
            }
            else
            {
                gvMyAirports.DataSource = null;
                gvMyAirports.DataBind();
            }

            if (fAdmin)
            {
                UpdateImportData();
            }
        }
        else
        {
            lblErr.Text = ap.ErrorText;
        }
    }
Exemplo n.º 18
0
        public static void PopulateAirport(Control plc, airport ap, MatchStatus ms, airport aicBase)
        {
            if (ap == null)
            {
                return;
            }

            if (plc == null)
            {
                throw new ArgumentNullException(nameof(plc));
            }

            Panel p = new Panel();

            plc.Controls.Add(p);
            Label lbl = new Label();

            p.Controls.Add(lbl);
            lbl.Text = ap.ToString();
            p.Controls.Add(new LiteralControl("<br />"));
            if (!StatusIsOK(ms))
            {
                p.CssClass = "notOK";
                Label lblStatus = new Label();
                p.Controls.Add(lblStatus);
                lblStatus.Text      = String.Format(CultureInfo.CurrentCulture, Resources.Admin.ImportAirportStatusTemplate, ms.ToString());
                lblStatus.ForeColor = System.Drawing.Color.Red;
                if (aicBase != null && ap.LatLong != null && aicBase.LatLong != null)
                {
                    Label lblDist = new Label();
                    p.Controls.Add(lblDist);
                    lblDist.Text = String.Format(CultureInfo.CurrentCulture, Resources.Admin.ImportAirportDistanceTemplate, aicBase.DistanceFromAirport(ap));
                }
            }
            HyperLink h = new HyperLink();

            p.Controls.Add(h);
            h.Text        = ap.LatLong.ToDegMinSecString();
            h.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "javascript:updateForAirport({0});", JsonConvert.SerializeObject(ap, new JsonSerializerSettings()
            {
                DefaultValueHandling = DefaultValueHandling.Ignore
            }));
            if (!String.IsNullOrEmpty(ap.UserName))
            {
                p.Controls.Add(new LiteralControl(String.Format(CultureInfo.InvariantCulture, "{0}<br />", ap.UserName)));
            }
        }
        public List <Path> get_shortest_paths(airport source_airport,
                                              airport target_airport, int top_k)
        {
            this.source_airport = source_airport;
            this.target_airport = target_airport;

            _init();
            int count = 0;

            while (has_next() && count < top_k)
            {
                next();
                ++count;
            }

            return(result_list);
        }
        public YenTopKShortestPathsAlg(GraphAirports graph)
        {
            result_list = new List <Path>();
            path_derivation_airport_index = new Dictionary <Path, airport>();
            path_candidates = new PriorityQueue <Path>();

            if (graph == null)
            {
                throw new ArgumentException("A NULL graph object occurs!");
            }

            graph          = new VariableGraph((GraphAirports)graph);
            source_airport = null;
            target_airport = null;

            _init();
        }
        protected void gvEdit_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink l  = (HyperLink)e.Row.FindControl("lnkZoomCode");
                airport   ap = (airport)e.Row.DataItem;
                l.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "javascript:clickAndZoom(new google.maps.LatLng({0}, {1}));", ap.LatLong.Latitude, ap.LatLong.Longitude);

                if (!String.IsNullOrWhiteSpace(ap.Country))
                {
                    e.Row.BackColor = System.Drawing.Color.LightGray;
                }
            }
        }
    protected void RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink lnkZoom    = (HyperLink)e.Row.FindControl("lnkZoom");
            Image     imgAirport = (Image)e.Row.FindControl("imgAirport");
            airport   ap         = (airport)e.Row.DataItem;
            imgAirport.Attributes["onclick"] = lnkZoom.NavigateUrl = ZoomLink(ap);

            HyperLink lnkHotels = (HyperLink)e.Row.FindControl("lnkHotels");
            lnkHotels.NavigateUrl = String.Format(System.Globalization.CultureInfo.InvariantCulture, "http://www.expedia.com/pubspec/scripts/eap.asp?goto=hotsearch&Map=1&lat={0}&long={1}&CityName={2}", ap.LatLong.LatitudeString, ap.LatLong.LongitudeString, HttpUtility.UrlEncode(ap.Name));
            lnkHotels.Text        = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.LocalizedText.AirportServiceHotels, ap.Name);
        }
    }
Exemplo n.º 23
0
        public void import_data()
        {
            Thread t1 = new Thread(getAllroutes);

            t1.Start();
            Thread t2 = new Thread(getAllAirports);

            t2.Start();

            t1.Join();
            t2.Join();



            airports_num = ar.Count;


            for (int i = 0; i < airports_num; ++i)
            {
                airport airport = ar[i];
                airports_list.Add(airport);
                id_airports_index[airport.airport_ID] = airport;
            }


            foreach (airport a in airports_list)
            {
                foreach (route r in fullRoutes)
                {
                    if (r.from_OID == a.airport_ID)
                    {
                        int    start_airport_id     = (int)r.from_OID;
                        int    end_airport_id       = (int)r.to_OID;
                        double distance             = (double)r.distance;
                        KeyValuePair <int, int> Key = new KeyValuePair <int, int>(start_airport_id, end_airport_id);

                        if (!airports_pair_distance_index.ContainsKey(Key))
                        {
                            add_route(start_airport_id, end_airport_id, distance);
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
 private void AddAirportToHashtable(airport ap)
 {
     // segregate airports from navaids by using the navaid prefix as the key if necessary
     // Use priority to store the highest-priority navaid, if multiple found
     if (ap.IsPort)
     {
         m_htAirportsByCode[ap.Code] = ap;
     }
     else
     {
         string szKey = airport.ForceNavaidPrefix + ap.Code;
         // see if a navaid is already there; store the new one only if it is higher priority (lower value) than what's already there.
         m_htAirportsByCode.TryGetValue(szKey, out airport ap2);
         if (ap2 == null || (ap.Priority < ap2.Priority))
         {
             m_htAirportsByCode[szKey] = ap;
         }
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Returns a new AirportList that is a subset of the current ones, using airports out of the array of codes (from NormalizeAirportList)
        /// </summary>
        /// <param name="rgApCodeNormal">The array of airport codes (call NormalizeAirportList on a route to get this)</param>
        /// <param name="fPortsOnly">Indicates whether we should ONLY include ports (vs navaids)</param>
        /// <returns>A new airportList object that is the intersection of the source object and the specified codes</returns>
        private AirportList CloneSubset(string[] rgApCodeNormal, bool fPortsOnly = false)
        {
            AirportList al = new AirportList()
            {
                m_rgAirports         = new List <airport>(),
                m_rgszAirportsNormal = rgApCodeNormal
            };

            foreach (string sz in al.m_rgszAirportsNormal)
            {
                airport ap = GetAirportByCode(sz);
                if (ap != null && (ap.IsPort || !fPortsOnly))
                {
                    al.m_htAirportsByCode[sz] = ap;
                    al.m_rgAirports.Add(ap);
                }
            }
            return(al);
        }
Exemplo n.º 26
0
    //menu airport
    void airportMenu(airport currentPlace, playerToken currentPlayer)
    {
        //buy
        if (currentPlace.Owned == false && currentPlayer.money >= currentPlace.price)
        {
            if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .2f, Screen.width * .2f, Screen.height * .1f), "BUY"))
            {
                currentPlace.Buy(currentPlayer);
                VariableManager.turn = 2;
            }
        }

        //sell
        if (currentPlayer.places.Count > 0)
        {
            if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .4f, Screen.width * .2f, Screen.height * .1f), "SELL"))
            {
                this.yourArray       = new List <bool>(currentPlayer.places.Count);
                this.offSet          = 0;
                VariableManager.turn = 5;
            }
        }
        //surrender
        if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .5f, Screen.width * .2f, Screen.height * .1f), "SURRENDER"))
        {
            currentPlayer.surrender();
        }
        //end turn
        if (VariableManager.turn == 2)
        {
            if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .6f, Screen.width * .2f, Screen.height * .1f), "END TURN"))
            {
                VariableManager.state++;
                if (VariableManager.state == VariableManager.jumlahPlayer)
                {
                    VariableManager.state = 0;
                }
                VariableManager.turn = 0;
            }
        }
    }
Exemplo n.º 27
0
    private static void PopulateAirport(Control plc, airport ap, airportImportCandidate.MatchStatus ms, airport aicBase)
    {
        if (ap == null)
        {
            return;
        }

        Panel p = new Panel();

        plc.Controls.Add(p);
        Label lbl = new Label();

        p.Controls.Add(lbl);
        lbl.Text = ap.ToString();
        p.Controls.Add(new LiteralControl("<br />"));
        if (!airportImportCandidate.StatusIsOK(ms))
        {
            p.BackColor = System.Drawing.Color.LightGray;
            Label lblStatus = new Label();
            p.Controls.Add(lblStatus);
            lblStatus.Text      = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.Admin.ImportAirportStatusTemplate, ms.ToString());
            lblStatus.ForeColor = System.Drawing.Color.Red;
            if (aicBase != null && ap.LatLong != null && aicBase.LatLong != null)
            {
                Label lblDist = new Label();
                p.Controls.Add(lblDist);
                lblDist.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.Admin.ImportAirportDistanceTemplate, aicBase.DistanceFromAirport(ap));
            }
        }
        HyperLink h = new HyperLink();

        p.Controls.Add(h);
        h.Text        = ap.LatLong.ToDegMinSecString();
        h.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "javascript:updateForAirport('{0}', '{1}', '{2}', {3}, {4});", ap.Code, ap.Name.JavascriptEncode(), ap.FacilityTypeCode, ap.LatLong.Latitude, ap.LatLong.Longitude);
        if (!String.IsNullOrEmpty(ap.UserName))
        {
            p.Controls.Add(new LiteralControl(String.Format(CultureInfo.InvariantCulture, "{0}<br />", ap.UserName)));
        }
    }
Exemplo n.º 28
0
        public Path get_shortest_path(airport source_airport, airport sink_airport)
        {
            determine_shortest_paths(source_airport, sink_airport, true);


            List <airport> airports_list = new List <airport>();
            double         distance      = start_airport_distance_index.ContainsKey(sink_airport.airport_ID) ?
                                           start_airport_distance_index[sink_airport.airport_ID] : GraphAirports.DISCONNECTED;

            if (distance != GraphAirports.DISCONNECTED)
            {
                airport cur_airport = sink_airport;
                do
                {
                    airports_list.Add(cur_airport);
                    cur_airport = predecessor_index[cur_airport.airport_ID];
                } while (cur_airport != null && cur_airport != source_airport);

                airports_list.Add(source_airport);
                airports_list.Reverse();
            }
            return(new Path(airports_list, distance));
        }
Exemplo n.º 29
0
        public override List <airport> get_precedent_airports(airport airport)
        {
            List <airport> ret_set = new List <airport>();

            if (!rem_airport_id_set.Contains(airport.airport_ID))
            {
                int            ending_airport_id = airport.airport_ID;
                List <airport> pre_airports_set  = base.get_precedent_airports(airport);
                foreach (airport cur_airport in pre_airports_set)
                {
                    int starting_airport_id = cur_airport.airport_ID;
                    if (rem_airport_id_set.Contains(starting_airport_id) ||
                        rem_route_set.Contains(
                            new KeyValuePair <int, int>(starting_airport_id, ending_airport_id)))
                    {
                        continue;
                    }

                    //
                    ret_set.Add(cur_airport);
                }
            }
            return(ret_set);
        }
Exemplo n.º 30
0
 bool airportPayCheck(airport currentPlace, playerToken currentPlayer)
 {
     if (currentPlace.Owned == false)
     {
         return(true);
     }
     else
     {
         //pay
         if (currentPlayer.money > currentPlace.RentPrice())
         {
             desc = "PAY " + currentPlace.RentPrice();
             if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .1f, Screen.width * .3f, Screen.height * .1f), "PAY"))
             {
                 currentPlace.Pay(currentPlayer);
                 VariableManager.turn = 2;
             }
         }
         //sell
         if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .4f, Screen.width * .3f, Screen.height * .1f), "SELL"))
         {
             this.yourArray       = new List <bool>(currentPlayer.places.Count);
             this.offSet          = 0;
             VariableManager.turn = 5;
         }
         //surrender
         if (currentPlayer.money < currentPlace.RentPrice())
         {
             if (GUI.Button(new Rect(Screen.width * .03f, Screen.height * .5f, Screen.width * .2f, Screen.height * .1f), "SURRENDER"))
             {
                 currentPlayer.surrender();
             }
         }
     }
     return(false);
 }