コード例 #1
0
        public static MyPersonalMapData LoadFile(string cheminDacces)
        {
            MyPersonalMapData ret_val = new MyPersonalMapData();;

            try
            {
                if (cheminDacces.Contains(".az"))
                {
                    if (File.Exists(cheminDacces))
                    {
                        BinaryFormatter binFormat = new BinaryFormatter();
                        try
                        {
                            Stream fStream = new FileStream(cheminDacces, FileMode.Open, FileAccess.Read);
                            if (fStream == null)
                            {
                                throw new LoadSaveException("LoadFile fStream == null");
                            }
                            ret_val.Prenom      = (string)binFormat.Deserialize(fStream);
                            ret_val.Nom         = (string)binFormat.Deserialize(fStream);
                            ret_val.Email       = (string)binFormat.Deserialize(fStream);
                            ret_val.Emplacement = cheminDacces;
                            ret_val.SETObservableCollection((ObservableCollection <ICartoObj>)binFormat.Deserialize(fStream));
                            fStream.Close();
                        }
                        catch (Exception e)
                        {
                            throw new LoadSaveException("LoadFile (try/catch de fStream) : Erreur : " + e.Message);
                        }
                    }
                    else
                    {
                        throw new LoadSaveException("LoadFile : le répertoire : " + cheminDacces + " n existe pas !!!");
                    }
                }
                else
                {
                    throw new LoadSaveException("LoadFile : nom de fichier invlaide !!! --> " + cheminDacces);
                }
            }
            catch (Exception e)
            {
                throw new LoadSaveException("LoadFile : Erreur : " + e.Message);
            }
            return(ret_val);
        }
コード例 #2
0
        //output : true si on trouve la personne à l'emplacement demandé, false si on ne la trouve pas
        public static MyPersonalMapData LoadPersonne(MyPersonalMapData personneRecherchee)
        {
            MyPersonalMapData ret_val     = null;
            string            emplacement = @"../../../sauvegarde/";

            try
            {
                if (Directory.Exists(emplacement))
                {
                    Console.WriteLine("DEBUG : LoadObservableCollection : le répertoire {0} existe...", emplacement);
                    string[] listeFicher;
                    listeFicher = Directory.GetFiles(emplacement);
                    if (listeFicher.Length > 0)
                    {
                        for (int i = 0; i < listeFicher.Length; i++)
                        {
                            if (File.Exists(listeFicher[i]))
                            {
                                MyPersonalMapData personneTMP = new MyPersonalMapData();
                                BinaryFormatter   binFormat   = new BinaryFormatter();
                                try
                                {
                                    Stream fStream = new FileStream(listeFicher[i], FileMode.Open, FileAccess.Read);
                                    if (fStream == null)
                                    {
                                        throw new LoadSaveException("LoadPersonne fStream == null");
                                    }
                                    personneTMP.Prenom      = (string)binFormat.Deserialize(fStream);
                                    personneTMP.Nom         = (string)binFormat.Deserialize(fStream);
                                    personneTMP.Email       = (string)binFormat.Deserialize(fStream);
                                    personneTMP.Emplacement = listeFicher[i];
                                    personneTMP.SETObservableCollection((ObservableCollection <ICartoObj>)binFormat.Deserialize(fStream));
                                    fStream.Close();

                                    //Console.WriteLine("DEBUG recherche de personne :");
                                    //Console.WriteLine("path = " + listeFicher[i]);
                                    //Console.WriteLine("personneTMP = \n" + personneTMP.ToString());
                                    //Console.WriteLine("personneRecherchee = \n" + personneRecherchee.ToString());

                                    if (personneTMP.Nom == personneRecherchee.Nom && personneTMP.Prenom == personneRecherchee.Prenom && personneTMP.Email == personneRecherchee.Email)
                                    {
                                        ret_val = personneTMP;
                                        i       = listeFicher.Length;
                                    }
                                }
                                catch (Exception e)
                                {
                                    throw new LoadSaveException("LoadPersonne (try/catch de fStream) : Erreur : " + e.Message);
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new LoadSaveException("LoadObservableCollection : le répertoire" + emplacement + "est vide !!!");
                    }
                }
                else
                {
                    throw new LoadSaveException("LoadObservableCollection : le répertoire" + emplacement + "n existe pas !!!");
                }
            }
            catch (Exception e)
            {
                throw new LoadSaveException("LoadPersonne : Erreur : " + e.Message);
            }

            if (ret_val == null)
            {
                throw new LoadSaveException("LoadPersonne : ret_val == null : personneRecherche pas trouvee :( ");
            }
            return(ret_val);
        }