Example #1
0
 /// <summary>
 /// Check if a cache shall be displayed based on filter definition
 /// </summary>
 /// <param name="cache">Cache to be checked</param>
 /// <returns>true if cache shall be displayed (passes the filter definition)</returns>
 public override bool ToBeDisplayed(Geocache cache)
 {
     if (_od != null)
     {
         if (_od._OfflineData.ContainsKey(cache._Code))
         {
             OfflineCacheData ocd = _od._OfflineData[cache._Code];
             if (ocd._NotDownloaded)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(true);
     }
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigating(WebBrowserNavigatingEventArgs e)
        {
            String url = e.Url.ToString().ToLower();

            if (url.StartsWith("mgmgeo:"))
            {
                String code = url.Replace("mgmgeo:", "");
                code = code.Replace("/", "");
                code = code.ToUpper();
                try
                {
                    Geocache         geo = _daddy._caches[code];
                    OfflineCacheData ocd = null;
                    if (_daddy._od._OfflineData.ContainsKey(geo._Code))
                    {
                        ocd = _daddy._od._OfflineData[geo._Code];
                    }


                    // Truc par défaut
                    _daddy._cacheDetail.LoadPageCache(geo, _daddy._bUseKm, ocd, false, false);
                }
                catch (Exception ex)
                {
                    _daddy.ShowException("", "Cache description", ex);
                }
            }
            else if (url.StartsWith("mgmgeom:"))
            {
                String code = url.Replace("mgmgeom:", "");
                code = code.Replace("/", "");
                code = code.ToUpper();
                try
                {
                    Geocache geo = _daddy._caches[code];
                    TabPage  map = _daddy.ShowCacheMapInCacheDetail();
                    _daddy._cacheDetail._gmap.Position = new PointLatLng(geo._dLatitude, geo._dLongitude);
                    if (map != null)
                    {
                        _daddy._cacheDetail.tabControlCD.SelectTab(map);
                    }
                }
                catch (Exception ex)
                {
                    _daddy.ShowException("", "Display cache on map", ex);
                }
            }
            else if (url.StartsWith("mgmgeomxy:"))
            {
                String xy = url.Replace("mgmgeomxy:", "");
                xy = xy.Replace("/", "");
                xy = xy.ToUpper();
                String[] latlon = xy.Split('#');
                try
                {
                    double  lat = MyTools.ConvertToDouble(latlon[0]);
                    double  lon = MyTools.ConvertToDouble(latlon[1]);
                    TabPage map = _daddy.ShowCacheMapInCacheDetail();
                    _daddy._cacheDetail._gmap.Position = new PointLatLng(lat, lon);
                    if (map != null)
                    {
                        _daddy._cacheDetail.tabControlCD.SelectTab(map);
                    }
                }
                catch (Exception ex)
                {
                    _daddy.ShowException("", "Display coord on maps", ex);
                }
            }
            else
            {
                base.OnNavigating(e);
            }
        }
Example #3
0
        /// <summary>
        /// Rendering method
        /// </summary>
        /// <param name="g">Graphic to render</param>
        public override void OnRender(Graphics g)
        {
            if (_geo != null)
            {
                String imgpath       = _daddy.GetResourcesDataPath() + Path.DirectorySeparatorChar + "Img";
                String imgpath_clean = imgpath.Replace("\\", "/");


                String nameHtml = "";
                if (_geo._Available.ToLower() == "true")
                {
                    nameHtml = _geo._Name.Replace("'", "&#146;");
                }
                else
                {
                    nameHtml = "<span style=\"text-decoration:line-through;\">" + _geo._Name.Replace("'", " ") + "</span>";
                }

                String           stats = "";
                OfflineCacheData ocd   = _geo._Ocd;
                if ((ocd != null) && (ocd.HasStats()))
                {
                    // On a des stats
                    double rating;
                    rating = (_daddy._bUseGCPopularity) ? ocd._dRatingSimple : ocd._dRating;
                    if (rating >= 0)
                    {
                        stats = "	<tr><td><img width=16 height=16 src='"+ imgpath_clean + "/Fav.png'>" + ocd._iNbFavs.ToString() +
                                ",&nbsp;" + _daddy.GetTranslator().GetString("LVRating") + ":&nbsp;" + "</td>" +
                                "		<td>"+
                                "<img src='" + imgpath_clean + "/Ratios/" + "ratio_" + ((int)(ocd._dRating * 100.0)).ToString() + ".png'>" + rating.ToString("0.0%").ToString() + "</td></tr>";
                    }
                    else if (ocd._iNbFavs > 0)
                    {
                        stats = "	<tr><td><img width=16 height=16 src='"+ imgpath_clean + "/Fav.png'>" + ocd._iNbFavs.ToString() + "</td>" +
                                "		<td>&nbsp;</td></tr>";
                    }
                }

                //String theType = "		<img width=16 height=16 src='" + imgpath_clean + "/Type/" + _geo._Type + ".gif'>";
                String theType = "		<img src='"+ imgpath_clean + "/TypeCat/" + _daddy._geocachingConstants.GetDicoTypeSmallIcon()[_geo._Type] + ".png'>";

                if (MyTools.InsensitiveContainsInStringList(GeocachingConstants.GetSupportedCacheTypes(), _geo._Type) == false)
                {
                    theType = "		<img width=16 height=16 src='"+ imgpath_clean + "/Fail.png'>";
                }
                String infpopup =
                    "<body><table border=0>" +
                    "	<tr><td><b>"+
                    theType +
                    "		"+ nameHtml + "</b>" +
                    "	</td>"+
                    "	<td align='right'><h4>"+ _geo._Code + "</h4></td></tr>" +
                    stats +
                    "		<tr><td>"+ _daddy.GetTranslator().GetString("HTMLACacheBy") + ":&nbsp;" + MyTools.RemoveDiacritics(_geo._PlacedBy).Replace("'", " ") + "</td>" +
                    "		<td>"+ _daddy.GetTranslator().GetString("HTMLHidden") + ":&nbsp;" + MyTools.CleanDate(_geo._DateCreation) + "</td></tr>" +
                    "		<tr><td>"+ _daddy.GetTranslator().GetString("HTMLDifficulty") + ":&nbsp;<img src='" + imgpath_clean + "/Star/" + _geo._D + ".gif'></td>" +
                    "		<td>"+ _daddy.GetTranslator().GetString("HTMLTerrain") + ":&nbsp;<img src='" + imgpath_clean + "/Star/" + _geo._T + ".gif'></td></tr>" +
                    "		<tr><td>"+ _daddy.GetTranslator().GetString("HTMLSize") + ":&nbsp;<img src='" + imgpath_clean + "/Size/" + _geo._Container + ".gif'></td>";

                if ((_geo._Ocd != null) && (_geo._Ocd._dAltiMeters != Double.MaxValue))
                {
                    String salti = "";
                    if (_daddy._bUseKm)
                    {
                        salti = String.Format("{0:0.#}", _geo._Ocd._dAltiMeters) + " m";
                    }
                    else
                    {
                        salti = String.Format("{0:0.#}", _geo._Ocd._dAltiMeters * 3.2808399) + " ft";
                    }
                    infpopup += "<td>" + _daddy.GetTranslator().GetString("HTMLAltitude") + ":&nbsp;" + salti + "</td>";
                }
                else
                {
                    infpopup += "<td>&nbsp;</td>";
                }
                infpopup += "</tr></table></body>";

                // A VIRER !!!!!!!!!!
                //_daddy.Log(infpopup);


                Image   img = null;
                CssData css = CssData.Parse("body { font:8pt Tahoma } h3 { color: navy; font-weight:normal; }", true);
                img = HtmlRender.RenderToImage(infpopup, 330, 150, Color.White, css, null, null);

                System.Drawing.Size      st   = img.Size;
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height / 2, st.Width + TextPadding.Width, st.Height + TextPadding.Height);
                rect.Offset(Offset.X, Offset.Y);

                g.DrawImage(img, new Point(rect.X, rect.Y));
            }
        }
Example #4
0
        private void Diagnostics_Load(object sender, EventArgs e)
        {
            try
            {
                _daddy._ThreadProgressBarTitle = _daddy.GetTranslator().GetString("LblDownloadInProgress");
                _daddy.CreateThreadProgressBarEnh();
                // Wait for the creation of the bar
                while (_daddy._ThreadProgressBar == null)
                {
                    Thread.Sleep(10);
                    Application.DoEvents();
                }
                _daddy._ThreadProgressBar.progressBar1.Maximum = 31;
                _daddy._ThreadProgressBar.lblWait.Text         = "Performing diagnostics...";

                ListViewItem item = null;
                int          nb   = 0;

                // Proxy ?
                if (_daddy.GetProxy() != null)
                {
                    CreateEntry("OK", "Proxy status", "Defined");
                }
                else
                {
                    CreateEntry("OK", "Proxy status", "Undefined");
                }

                // Internet access ?
                if (_daddy.CheckInternetAccess())
                {
                    CreateEntry("OK", "Internet access", "Available");
                }
                else
                {
                    CreateEntry("KO", "Internet access", "Not available");
                }

                // GC account ?
                String cryptedpass = ConfigurationManager.AppSettings["ownerpassword"];
                String username    = ConfigurationManager.AppSettings["owner"];
                if (username != "")
                {
                    CreateEntry("OK", "Geocaching login", "Filled");
                }
                else
                {
                    CreateEntry("KO", "Geocaching login", "Empty");
                }

                if (cryptedpass != "")
                {
                    CreateEntry("OK", "Geocaching password", "Filled");
                }
                else
                {
                    CreateEntry("KO", "Geocaching password", "Empty");
                }

                CookieContainer cookie = null;
                if ((username != "") && (cryptedpass != ""))
                {
                    cookie = _daddy.CheckGCAccount(true, true);
                    if (cookie != null)
                    {
                        CreateEntry("OK", "Geocaching authentication", "Success");
                    }
                    else
                    {
                        CreateEntry("KO", "Geocaching authentication", "Error during authentication");
                    }
                }
                else
                {
                    CreateEntry("KO", "Geocaching authentication", "Login and/or password empty");
                }

                // MGM websites
                String        urlupdate = ConfigurationManager.AppSettings["urlupdate"];
                List <string> urls      = urlupdate.Split(';').ToList <string>();
                foreach (String url in urls)
                {
                    try
                    {
                        String rep = MyTools.GetRequest(new Uri(url), _daddy.GetProxy(), 2000);
                        if (rep != "")
                        {
                            CreateEntry("OK", "MGM website", "Available: " + url);
                        }
                        else
                        {
                            CreateEntry("KO", "MGM website", "Not available: " + url);
                        }
                    }
                    catch
                    {
                        item = CreateEntry("KO", "MGM website availability", "Not available: " + url);
                    }
                }

                // PQ download ?
                if (cookie == null)
                {
                    CreateEntry("KO", "Pocket Queries download", "User not authenticated");
                }
                else
                {
                    String        html = _daddy.GetPQDownloadHTML(cookie);
                    PQDownloadHMI pq   = new PQDownloadHMI(_daddy);
                    nb = pq.Populate(html, true);
                    if (nb != 0)
                    {
                        CreateEntry("OK", "Pocket Queries download", "Available PQs: " + nb.ToString());
                    }
                    else
                    {
                        CreateEntry("KO", "Pocket Queries download", "Available PQs: " + nb.ToString());
                    }
                }


                // Images
                OfflineCacheData ocd    = new OfflineCacheData();
                WebClient        client = new WebClient();
                client.Proxy = _daddy.GetProxy();
                string         htmlCode = client.DownloadString("http://coord.info/GC2MQGF");
                DownloadWorker dwnd     = new DownloadWorker(_daddy);
                dwnd.GetImageFromParsingImpl(ocd, false, htmlCode);
                String s = "";
                nb = 0;
                List <string> images = new List <string>();
                foreach (KeyValuePair <String, OfflineImageWeb> paire in ocd._ImageFilesSpoilers)
                {
                    OfflineImageWeb oid = paire.Value;
                    s += oid._name + ";";
                    images.Add(oid._name);
                    nb++;
                }
                // ;;;
                if (nb == 4)
                {
                    if (
                        (images[0] == "[SPOILER] Cache") &&
                        //(images[1] == "Départ du sentier / Start of the trail") && // les accents peuvent faire chier
                        (images[2] == "Le Saule Pleureur / The Weeping Willow") &&
                        (images[3] == "Le Saule Pleureur / The Weeping Willow")
                        )
                    {
                        CreateEntry("OK", "Image/Spoilers download", "Good count and names");
                    }
                    else
                    {
                        CreateEntry("KO", "Image/Spoilers download", "Bad names");
                    }
                }
                else
                {
                    CreateEntry("KO", "Image/Spoilers download", "Bad count");
                }

                // Completion d'une cache
                if (cookie == null)
                {
                    CreateEntry("KO", "Cache update", "User not authenticated");
                }
                else
                {
                    htmlCode = _daddy.GetCacheHTMLFromClientImpl("http://coord.info/GCX076", cookie);
                    Geocache geo = new Geocache(_daddy);
                    DataForStatsRetrieval dataforstats = new DataForStatsRetrieval();
                    dataforstats.cookieJar          = cookie;
                    dataforstats.firstQuestion      = false;
                    dataforstats.inbmissed          = 0;
                    dataforstats.stopScoreRetrieval = false;
                    nb = _daddy._iNbModifiedCaches;
                    _daddy.CompleteCacheFromHTML(geo, htmlCode, null, dataforstats, true);
                    _daddy._iNbModifiedCaches = nb;
                    if (CheckCacheContent(geo))
                    {
                        CreateEntry("OK", "Cache update", "General success");
                    }
                    else
                    {
                        CreateEntry("KO", "Cache update", "General failure");
                    }
                }

                _daddy.KillThreadProgressBarEnh();
            }
            catch (Exception exc)
            {
                _daddy.KillThreadProgressBarEnh();
                _daddy.ShowException("", _daddy.GetTranslator().GetString("FMenuDiagnostics"), exc);
            }
        }