Exemplo n.º 1
0
        // Méthode publique d'instance pour mettre à jour un objet ListeStations avec les 3 stations les plus proches d'une position géographique
        public override String getListeStationsProches(ListeStations laListeStations)
        {
            try
            {                   // création d'un objet XmlReader à partir du flux ; il servira à parcourir le flux XML
                String    strLatitude  = Convert.ToString(laListeStations.PositionLatitude).Replace(",", ".");
                String    strLongitude = Convert.ToString(laListeStations.PositionLongitude).Replace(",", ".");
                String    url          = _adresseHebergeur + _urlListeStationsProches.Replace("LATITUDE", strLatitude).Replace("LONGITUDE", strLongitude);
                XmlReader leDocument   = getDocumentXML(url);

                // vide la liste actuelle des stations
                laListeStations.viderListeStations();

                // démarrer le parcours au premier noeud de type <station>
                leDocument.ReadToFollowing("station");
                do
                {                       // crée un objet vide uneStation
                    Station uneStation = new Station();

                    // valorise l'objet uneStation à partir d'un jeu de balises XML
                    getDonneesStation(leDocument, uneStation);

                    // ajoute la station à l'objet ListeStations
                    laListeStations.ajouteStation(uneStation);
                }while (leDocument.ReadToFollowing("station"));                 // continue au noeud suivant de type <station>

                return("");                                                     // il n'y a pas de problème
            }
            catch (Exception ex)
            {
                return("Erreur : " + ex.Message);                       // il y a un problème
            }
        }
Exemplo n.º 2
0
        //le constructeur
        public FrmStations()
        {
            InitializeComponent();

            laCarte.MapProvider          = GMap.NET.MapProviders.GoogleMapProvider.Instance;
            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
            laCarte.DragButton           = MouseButtons.Left;

            laCarte.Left   = 0;
            laCarte.Top    = 0;
            laCarte.Width  = this.ClientSize.Width;
            laCarte.Height = this.ClientSize.Height;

            leCalqueDesReperesFixes = new GMapOverlay("reperes fixes");
            laCarte.Overlays.Add(leCalqueDesReperesFixes);

            leCalqueDesStations = new GMapOverlay("marqueurs des stations");
            laCarte.Overlays.Add(leCalqueDesStations);

            laCarte.Position = THABOR;
            laCarte.Zoom     = 13;
            afficherReperesFixes();

            laPasserelle = new PasserelleJSON();

            this.laListeStations = new ListeStations();
            msg = laPasserelle.getListeStations(laListeStations);
            if (msg != "")
            {
                MessageBox.Show(msg, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                afficherMarqueurs(null);
            }
        }
Exemplo n.º 3
0
        // Méthode publique d'instance pour mettre à jour un objet ListeStations avec l'ensemble des stations de la ville
        // L'objet ListeStations à mettre à jour est reçu en paramètre
        // Retourne un message d'erreur en cas d'erreur d'exécution, ou une chaine vide si tout s'est bien passé
        public override String getListeStations(ListeStations laListeStations)
        {
            /* Exemple de données obtenues pour une station :
             *      "fields": {
             *          "nom": "R\u00e9publique",
             *          "idstationmetrocorrespondance": "REP",
             *          "adressenumero": "19",
             *          "datemiseservice": "2009-06-22",
             *          "adressevoie": "Quai Lamartine",
             *          "nomcommune": "Rennes",
             *          "idstationproche1": 2,
             *          "possedetpe": "true",
             *          "nombreemplacementstheorique": 30,
             *          "codeinseecommune": "35238",
             *          "coordonnees": [
             *              48.1100259201,
             *              -1.6780371631
             *          ],
             *          "id": 1,
             *          "idstationproche2": 11,
             *          "idstationproche3": 10
             *      },
             */

            // initialisation des variables
            Station uneStation = new Station();
            String  id = "", nom = "", adressenumero = "", adressevoie = "", adresse = "";
            double  latitude = 0, longitude = 0;
            bool    possedetpe = false;

            try
            {
                // création d'un flux en lecture (StreamReader) à partir du service web
                String       url             = _adresseHebergeur + _urlListeStations;
                StreamReader unFluxEnLecture = getFluxEnLecture(url);
                // création d'un objet JsonTextReader à partir du flux ; il servira à parcourir le flux JSON
                JsonTextReader leDocument = getDocumentJson(unFluxEnLecture);

                // vide la liste actuelle des stations
                laListeStations.viderListeStations();

                // lire le document jusqu'à l'élément "fields" avec la méthode privée avancerJusqua
                bool finDocument = avancerJusqua(leDocument, "fields");

                // traiter jusqu'à la fin du document
                while (!finDocument)
                {
                    leDocument.Read();            // lire l'élément suivant
                    switch (leDocument.TokenType) // traiter en fonction du type d'élément
                    {
                    case JsonToken.StartObject:   // l'élément est un début d'objet JSON (donc une station)
                        // on crée un objet vide uneStation
                        uneStation = new Station();
                        break;

                    case JsonToken.PropertyName:             // l'élément est une propriété de l'objet JSON
                        switch (leDocument.Value.ToString()) // traiter en fonction du nom de la propriété
                        {
                        case "id": leDocument.Read();
                            id = leDocument.Value.ToString(); break;

                        case "nom": leDocument.Read();
                            nom = leDocument.Value.ToString(); break;

                        case "adressenumero": leDocument.Read();
                            adressenumero = leDocument.Value.ToString(); break;

                        case "adressevoie": leDocument.Read();
                            adressevoie = leDocument.Value.ToString(); break;

                        case "possedetpe": leDocument.Read();
                            possedetpe = Convert.ToBoolean(leDocument.Value.ToString()); break;

                        case "coordonnees":             // l'élément est un le tableau des coordonnées
                            leDocument.Read();          // lit l'élément début de tableau
                            leDocument.Read();          // lit le premier nombre
                            // (attention à la présence du point décimal à remplacer par virgule)
                            latitude = Convert.ToDouble(leDocument.Value.ToString().Replace(".", ","));
                            leDocument.Read();          // lit le second nombre
                            // (attention à la présence du point décimal à remplacer par virgule)
                            longitude = Convert.ToDouble(leDocument.Value.ToString().Replace(".", ","));
                            break;
                        }     // fin switch interne
                        break;

                    case JsonToken.EndObject:           // l'élément est une fin d'objet JSON (donc une station)
                        // on valorise la station et on l'ajoute à l'objet laListeStations
                        adresse = adressenumero + " " + adressevoie;
                        uneStation.valoriser(id, nom, adresse, latitude, longitude, possedetpe);
                        laListeStations.ajouteStation(uneStation);
                        // lire le document jusqu'à l'élément "fields" avec la méthode privée avancerJusqua
                        finDocument = avancerJusqua(leDocument, "fields");
                        break;
                    } // fin switch externe
                }
                return("");                                      // il n'y a pas de problème, on retourne une chaine vide
            }
            catch (Exception ex)
            {
                return("Erreur : " + ex.Message);        // il y a un problème, on retourne le message d'ereur
            }
        }
Exemplo n.º 4
0
 // Méthode publique d'instance pour mettre à jour un objet ListeStations avec l'ensemble des stations de la ville
 public abstract String getListeStations(ListeStations laListeStations);