Пример #1
0
        void BtnGCNMapClick(object sender, EventArgs e)
        {
            Double dLat = Double.MaxValue;
            Double dLon = Double.MaxValue;
            String sLat = "";
            String sLon = "";
            bool   bOK  = ParameterObject.TryToConvertCoordinates(tbGCNCenter.Text, ref sLat, ref sLon);

            if (sLat != CoordConvHMI._sErrorValue)
            {
                dLat = MyTools.ConvertToDouble(sLat);
            }
            if (sLon != CoordConvHMI._sErrorValue)
            {
                dLon = MyTools.ConvertToDouble(sLon);
            }
            if (bOK)
            {
                _daddy.HandlerToDisplayCoordinates(dLat, dLon);
            }
            else
            {
                MessageBox.Show(_sErrTitle, _sErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
 /// <summary>
 /// Check if longitude and latitude in decimal degrees are within valid range
 /// </summary>
 /// <param name="decimal_degrees">longitude or latitude</param>
 /// <param name="bLat">True if latitude</param>
 /// <returns>true if value is correct</returns>
 static public bool CheckLonLatValidity(String decimal_degrees, bool bLat)
 {
     try
     {
         double coord = MyTools.ConvertToDouble(decimal_degrees);
         return(CoordConvHMI.CheckLonLatValidity(coord, bLat));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
 /// <summary>
 /// Check if longitude and latitude in decimal degrees are within valid range
 /// </summary>
 /// <param name="decimal_degrees_lon">longitude in decimal degrees (-180 / +180)</param>
 /// <param name="decimal_degrees_lat">latitude in decimal degrees (-90 / +90)</param>
 /// <returns>true if both values are correct</returns>
 static public bool CheckLonLatValidity(String decimal_degrees_lon, String decimal_degrees_lat)
 {
     try
     {
         double lon = MyTools.ConvertToDouble(decimal_degrees_lon);
         double lat = MyTools.ConvertToDouble(decimal_degrees_lat);
         return(CoordConvHMI.CheckLonLatValidity(lon, lat));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #4
0
        public bool DoIt()
        {
            if (_Daddy != null)
            {
                var caches = _Daddy.GetSelectedCaches();
                if (caches.Count == 0)
                {
                    return(false);
                }

                int nbmodif = 0;
                foreach (Geocache geo in caches)
                {
                    // On cherche un waypoint commencant par FN (final)
                    String code_cherche = "FN" + geo._Code.Substring(2);
                    if (geo._waypoints.ContainsKey(code_cherche))
                    {
                        // On met à jour les coord avec celles de ce waypoint
                        Waypoint wpt = geo._waypoints[code_cherche];

                        geo._Latitude   = wpt._lat;
                        geo._Longitude  = wpt._lon;
                        geo._dLatitude  = MyTools.ConvertToDouble(wpt._lat);
                        geo._dLongitude = MyTools.ConvertToDouble(wpt._lon);
                        geo.UpdateDistanceToHome(_Daddy.HomeLat, _Daddy.HomeLon);
                        _Daddy._iNbModifiedCaches += geo.InsertModification("COORD");
                        nbmodif++;
                    }
                }

                // Better way to do that : only recreate for modified caches
                _Daddy.RecreateVisualElements(caches);

                // On redessine les caches sur la carte !
                if (nbmodif != 0)
                {
                    // On redessine la carte
                    _Daddy.BuildCacheMapNew(_Daddy.GetDisplayedCaches());
                }
                return(true);
            }
            else
            {
                MessageBox.Show("C'est bon !");
                return(false);
            }
        }
Пример #5
0
        void BtnGCNCreateClick(object sender, EventArgs e)
        {
            // On vérifie
            // coordonnées
            Double dLat = Double.MaxValue;
            Double dLon = Double.MaxValue;
            String sLat = "";
            String sLon = "";
            bool   bOK  = ParameterObject.TryToConvertCoordinates(tbGCNCenter.Text, ref sLat, ref sLon);

            if (sLat != CoordConvHMI._sErrorValue)
            {
                dLat = MyTools.ConvertToDouble(sLat);
            }
            if (sLon != CoordConvHMI._sErrorValue)
            {
                dLon = MyTools.ConvertToDouble(sLon);
            }
            if (!bOK)
            {
                DisplayError(lblGCNCentre.Text, _daddy.GetTranslator().GetString("WaypointCoord"), tbGCNCenter.Text, "");
                return;
            }

            // nom
            if (tbGCNName.Text == "")
            {
                DisplayError(lblGCNNom.Text, _daddy.GetTranslator().GetString("lblnotempty"), tbGCNName.Text, "");
                return;
            }

            // radius
            Int32 radius = 0;

            if (!Int32.TryParse(tbGCNRadius.Text, out radius))
            {
                DisplayError(lblGCNRadius.Text, _daddy.GetTranslator().GetString("lblnotnumber"), tbGCNRadius.Text, "");
                return;
            }

            // email
            if ((cbGCNEmails.Visible) && (cbGCNEmails.SelectedIndex == -1))
            {
                DisplayError(lblGCNEmail.Text, _daddy.GetTranslator().GetString("lblvalue"), "", "");
                return;
            }

            String email = "";

            if (cbGCNEmails.Items.Count != 0)
            {
                int pos = cbGCNEmails.SelectedIndex;
                email = cbGCNEmails.Items[pos].ToString();
            }

            // type
            // au moins une croix quelque part...
            // int associé au type de cache, nom du type de cache, liste des commandes POST pour kind of notif
            // Tuple<int, string, List<String>
            // on va créer un dico avec comme clé le type de cache
            Dictionary <String, Tuple <int, string, List <String> > > dicoCreation = new Dictionary <string, Tuple <int, string, List <string> > >();

            // On parcourt toutes les lignes, sauf la première qui correspond aux types
            for (int i = 1; i < lvGCNGrid.Items.Count; i++)
            {
                // On a l'item
                EXListViewItem lvi = (EXListViewItem)(lvGCNGrid.Items[i]);

                // On parcourt ses sous items
                for (int k = 1; k < lvi.SubItems.Count; k++)
                {
                    EXBoolListViewSubItem svi = lvi.SubItems[k] as EXBoolListViewSubItem;
                    if (svi != null)
                    {
                        // On a une valeur checkable
                        if (svi.BoolValue)
                        {
                            // Et elle est checkée !!
                            // On construit ce qu'il nous faut maintenant
                            //msg += listOfCacheTypes[k-1] + " " + listOfCacheTypesId[k-1] + " " + listOfAlloweKindPerCacheType[i-1].Item1 + " " + listOfAlloweKindPerCacheType[i-1].Item2[k-1] + "\r\n";


                            String typeofcache         = listOfCacheTypes[k - 1];
                            int    typeofcacheid       = listOfCacheTypesId[k - 1];
                            String kindofnotifreadable = listOfAlloweKindPerCacheType[i - 1].Item1;
                            String kindofnotifpost     = "ctl00$ContentBody$LogNotify$cblLogTypeList$" + listOfAlloweKindPerCacheType[i - 1].Item2[k - 1];
                            if (dicoCreation.ContainsKey(typeofcache))
                            {
                                // On met à jour la liste des kind of notif
                                Tuple <int, string, List <String> > obj = dicoCreation[typeofcache];
                                obj.Item3.Add(kindofnotifpost);
                            }
                            else
                            {
                                Tuple <int, string, List <String> > obj = new Tuple <int, string, List <string> >(typeofcacheid, typeofcache, new List <string>(new string[] { kindofnotifpost }));
                                dicoCreation.Add(typeofcache, obj);
                            }
                        }
                    }
                }
            }

            if (dicoCreation.Count == 0)
            {
                DisplayError(lblGCNGrid.Text, _daddy.GetTranslator().GetString("lblvalue"), "", "");
                return;
            }

            /*
             * foreach(KeyValuePair<String, Tuple<int, string, List<String>>> pair in dicoCreation)
             * {
             *      Tuple<int, string, List<String>> obj = pair.Value;
             *      msg += obj.Item1.ToString() + " " + obj.Item2 + " -> ";
             *      foreach(String s in obj.Item3)
             *      {
             *              msg += s + " ";
             *      }
             *      msg += "\r\n";
             * }
             * _daddy.MSG(msg);
             * return;
             */

            // On est valide, on peut créer
            _daddy._cacheDetail._gmap.ControlTextLatLon = null;

            // Go création
            CookieContainer cookieJar = _daddy.CheckGCAccount(true, false);
            String          url       = "https://www.geocaching.com/notify/edit.aspx";
            bool            error     = false;

            foreach (KeyValuePair <String, Tuple <int, string, List <String> > > pair in dicoCreation)
            {
                Tuple <int, string, List <String> > obj = pair.Value;
                // On demande la page par défaut pour initialiser une nouvelle demande
                HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
                objRequest.Proxy           = _daddy.GetProxy(); // Là encore, on peut virer le proxy si non utilisé (NULL)
                objRequest.CookieContainer = cookieJar;         // surtout récupérer le container de cookie qui est maintenant renseigné avec le cookie d'authentification
                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                String          post_response;
                using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
                {
                    post_response = responseStream.ReadToEnd();
                    responseStream.Close();
                }
                // On regarde si on a un message de warning
                if (NotificationsManager.CheckWarningMessage(_daddy, post_response))
                {
                    // Shit
                    error = true;
                    break;
                }

                // Une mise à jour pour définir le type de cache
                String post_string = NotificationsManager.GeneratePostString(_daddy, post_response, dLat, dLon, radius, tbGCNName.Text, obj, email, true);
                post_response = NotificationsManager.GeneratePostRequets(_daddy, url, post_string, cookieJar);

                // Une mise à jour pour définir le type de notif
                post_string   = NotificationsManager.GeneratePostString(_daddy, post_response, dLat, dLon, radius, tbGCNName.Text, obj, email, true);
                post_response = NotificationsManager.GeneratePostRequets(_daddy, url, post_string, cookieJar);
                if (NotificationsManager.CheckValidationMessage(_daddy, post_response))
                {
                    // Shit
                    error = true;
                    break;
                }
            }
            if (!error)
            {
                _daddy.MsgActionDone(this);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #6
0
        /// <summary>
        /// Create a list of empty geocaches from an OV2 file from SuperPP.
        /// SuperPP is a geocacher producing OV2 exports for France,
        /// see http://www.geocaching.com/profile/default.aspx?guid=05b50a82-2ae6-404b-958f-f184100acf25
        /// DB will be populated with the following valid attributes:
        /// - Code
        /// - Name
        /// - Type
        /// - Latitude
        /// - Longitude
        /// - Difficulty
        /// - Terrain
        /// </summary>
        /// <param name="con">SQLiteConnection</param>
        /// <param name="cmd">SQLiteCommand</param>
        /// <param name="filename">OV2 file</param>
        /// <param name="sType">Type of Geocache to be created (Traditional, etc...)</param>
        /// <returns>Number of inserted row into DB</returns>
        public int ProcessFileSuperPP(SQLiteConnection con, SQLiteCommand cmd, string filename, string sType)
        {
            int nb = 0;

            string[] data = null;
            try
            {
                if (!File.Exists(filename))
                {
                    return(0);
                }

                // Prepare transaction
                SQLiteTransaction transaction = con.BeginTransaction();

                cmd.CommandText = "INSERT INTO GeocacheLite(Code, Name, Type, Latitude, Longitude, Difficulty, Terrain) VALUES(@Code, @Name, @Type, @Latitude, @Longitude, @Difficulty, @Terrain)";
                cmd.Parameters.AddWithValue("@Code", "");
                cmd.Parameters.AddWithValue("@Name", "");
                cmd.Parameters.AddWithValue("@Type", "");
                cmd.Parameters.AddWithValue("@Latitude", 0.0);
                cmd.Parameters.AddWithValue("@Longitude", 0.0);
                cmd.Parameters.AddWithValue("@Difficulty", "");
                cmd.Parameters.AddWithValue("@Terrain", "");

                FileStream infile = new FileStream(filename, FileMode.Open, FileAccess.Read);
                while (infile.Length != infile.Position)
                {
                    data = readOV2Record(infile);
                    if (data != null)
                    {
                        //for (int i = 0; i < data.Length; i++)
                        // 0 : nom
                        // 1 : latitude
                        // 2 : longitude
                        // data[i]
                        double lon = MyTools.ConvertToDouble(data[2]);
                        double lat = MyTools.ConvertToDouble(data[1]);

                        // Le bon vieux format de SuperPP
                        String code = data[0].Substring(0, data[0].IndexOf(' '));
                        String name = data[0].Substring(data[0].IndexOf(" - ") + 3);
                        int    iend = name.LastIndexOf(" (");
                        if (iend != -1)
                        {
                            name = name.Substring(0, iend);
                        }

                        String D = "1";
                        String T = "1";
                        // On cherche à convertir la D/T
                        try
                        {
                            iend = data[0].LastIndexOf("(");
                            if (iend != -1)
                            {
                                string dt = data[0].Substring(iend);
                                dt = dt.Substring(0, dt.Length - 1);
                                D  = dt.Substring(1, dt.IndexOf('/') - 1).Replace(",", ".");
                                T  = dt.Substring(dt.IndexOf('/') + 1).Replace(",", ".");
                            }
                        }
                        catch (Exception)
                        {
                        }

                        // Insert values using preparedcommands
                        cmd.Parameters["@Code"].Value       = code;
                        cmd.Parameters["@Name"].Value       = name;
                        cmd.Parameters["@Type"].Value       = sType;
                        cmd.Parameters["@Latitude"].Value   = lat;
                        cmd.Parameters["@Longitude"].Value  = lon;
                        cmd.Parameters["@Difficulty"].Value = D;
                        cmd.Parameters["@Terrain"].Value    = T;
                        cmd.ExecuteNonQuery();

                        nb++;
                    }
                }
                infile.Close();

                // en transaction
                transaction.Commit();


                return(nb);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
        /// <summary>
        /// Create a list of empty geocaches from an OV2 file.
        /// Empty geocache will have the following valid attributes:
        /// - Longitude
        /// - Latitude
        /// - Type
        /// - Difficulty (only for SuperPP format)
        /// - Terrain (only for SuperPP format)
        /// All other attributes will have default values.
        /// </summary>
        /// <param name="daddy">Reference to main window (MainWindow instance), used for callback purposes</param>
        /// <param name="filename">OV2 file</param>
        /// <param name="sType">Type of Geocache to be created (Traditional, etc...)</param>
        /// <param name="bFromSuperPP">true if OV2 is generated by SuperPP
        /// SuperPP is a geocacher producing OV2 exports for France,
        /// see http://www.geocaching.com/profile/default.aspx?guid=05b50a82-2ae6-404b-958f-f184100acf25</param>
        /// <returns>List of created geocaches</returns>
        public List <Geocache> ProcessFile(MainWindow daddy, string filename, string sType, bool bFromSuperPP)
        {
            string[] data = null;
            try
            {
                List <Geocache> caches      = new List <Geocache>();
                FileStream      infile      = new FileStream(filename, FileMode.Open, FileAccess.Read);
                int             iIndexCache = 0;
                while (infile.Length != infile.Position)
                {
                    data = readOV2Record(infile);
                    if (data != null)
                    {
                        //for (int i = 0; i < data.Length; i++)
                        // 0 : nom
                        // 1 : latitude
                        // 2 : longitude
                        // data[i]
                        Geocache geo = new Geocache(daddy);
                        geo._Longitude  = data[2].ToString().Replace(",", ".");
                        geo._Latitude   = data[1].ToString().Replace(",", ".");
                        geo._dLongitude = MyTools.ConvertToDouble(geo._Longitude);
                        geo._dLatitude  = MyTools.ConvertToDouble(geo._Latitude);
                        if (bFromSuperPP)
                        {
                            // Le bon vieux format de SuperPP
                            geo._Code = data[0].Substring(0, data[0].IndexOf(' '));
                            String n    = data[0].Substring(data[0].IndexOf(" - ") + 3);
                            int    iend = n.LastIndexOf(" (");
                            if (iend != -1)
                            {
                                n = n.Substring(0, iend);
                            }
                            geo._Name             = n;
                            geo._CacheId          = (daddy._iCacheId++).ToString();
                            geo._OwnerId          = geo._CacheId;
                            geo._Country          = "France";
                            geo._State            = "Unknown";
                            geo._Type             = sType;
                            geo._Available        = "True";
                            geo._Archived         = "False";
                            geo._Url              = "http://coord.info/" + geo._Code;
                            geo._Owner            = "Unknown";
                            geo._PlacedBy         = "Unknown";
                            geo._ShortDescHTML    = "none";
                            geo._ShortDescription = "none";
                            geo._LongDescHTML     = "none";
                            geo._LongDescription  = "none";
                            geo._Hint             = "";
                            geo._DateCreation     = DateTime.Now.ToString(GeocachingConstants._FalseDatePattern);
                            geo._Container        = "Not chosen";

                            // On cherche à convertir la D/T
                            try
                            {
                                iend = data[0].LastIndexOf("(");
                                if (iend != -1)
                                {
                                    string dt = data[0].Substring(iend);
                                    dt     = dt.Substring(0, dt.Length - 1);
                                    geo._D = dt.Substring(1, dt.IndexOf('/') - 1).Replace(",", ".");
                                    geo._T = dt.Substring(dt.IndexOf('/') + 1).Replace(",", ".");
                                }
                                else
                                {
                                    geo._D = "1";
                                    geo._T = "1";
                                }
                            }
                            catch (Exception)
                            {
                                geo._D = "1";
                                geo._T = "1";
                            }
                        }
                        else
                        {
                            // Un format inconnu...
                            String code    = "GC";
                            String subcode = iIndexCache.ToString("X");
                            int    izero   = 5 - subcode.Length;
                            if (izero > 0)
                            {
                                String str = new String('0', izero);
                                code += str;
                            }
                            code += subcode;

                            geo._Code = code;
                            String n = data[0];

                            /*int iend = n.LastIndexOf(" (");
                             * if (iend != -1)
                             *  n = n.Substring(0, iend);*/
                            geo._Name             = n;
                            geo._CacheId          = (daddy._iCacheId++).ToString();
                            geo._OwnerId          = geo._CacheId;
                            geo._Country          = "Unknown";
                            geo._State            = "Unknown";
                            geo._Type             = sType;
                            geo._Available        = "True";
                            geo._Archived         = "False";
                            geo._Url              = "http://coord.info/FAKEGEOCACHE";
                            geo._Owner            = "Unknown";
                            geo._PlacedBy         = "Unknown";
                            geo._ShortDescHTML    = "none";
                            geo._ShortDescription = "none";
                            geo._LongDescHTML     = "none";
                            geo._LongDescription  = "none";
                            geo._Hint             = "";
                            geo._DateCreation     = DateTime.Now.ToString(GeocachingConstants._FalseDatePattern);
                            geo._Container        = "Not chosen";

                            // On cherche à convertir la D/T

                            /*try
                             * {
                             *  iend = data[0].LastIndexOf("(");
                             *  if (iend != -1)
                             *  {
                             *      string dt = data[0].Substring(iend);
                             *      dt = dt.Substring(0, dt.Length - 1);
                             *      geo._D = dt.Substring(1, dt.IndexOf('/') - 1).Replace(",", ".");
                             *      geo._T = dt.Substring(dt.IndexOf('/') + 1).Replace(",", ".");
                             *      if (geo._D == "")
                             *          geo._D = "1";
                             *      if (geo._T == "")
                             *          geo._T = "1";
                             *  }
                             *  else
                             *  {
                             *      geo._D = "1";
                             *      geo._T = "1";
                             *  }
                             * }
                             * catch (Exception)*/
                            {
                                geo._D = "1";
                                geo._T = "1";
                            }
                        }

                        iIndexCache++;
                        caches.Add(geo);
                    }
                }
                return(caches);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #8
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);
            }
        }