Exemplo n.º 1
0
        public void Load()
        {
            Core.res  = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
            Core.sDev = StorageDevice.EndShowSelector(Core.res);
            IAsyncResult result =
                Core.sDev.BeginOpenContainer("Phone", null, null);

            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = Core.sDev.EndOpenContainer(result);

            result.AsyncWaitHandle.Close();
            string filename = "phoneBookContacts.sav";

            if (!container.FileExists(filename))
            {
                container.Dispose();
                return;
            }
            Stream        stream       = container.OpenFile(filename, FileMode.Open);
            XmlSerializer serializer   = new XmlSerializer(typeof(ContactsList));
            ContactsList  contactsList = (ContactsList)serializer.Deserialize(stream);

            for (int i = 0; i < contactsList.name.Length; i++)
            {
                Contact c = new Contact(phone, contactsList.name[i], contactsList.number[i]);
                contacts.Add(c);
            }
            firstStart = contactsList.fStart;
            stream.Close();

            container.Dispose();
        }
Exemplo n.º 2
0
        public void Save()
        {
            Core.res  = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
            Core.sDev = StorageDevice.EndShowSelector(Core.res);
            IAsyncResult result =
                Core.sDev.BeginOpenContainer("Phone", null, null);

            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = Core.sDev.EndOpenContainer(result);

            result.AsyncWaitHandle.Close();

            string filename = "phoneBookContacts.sav";

            if (container.FileExists(filename))
            {
                container.DeleteFile(filename);
            }
            Stream        stream       = container.CreateFile(filename);
            XmlSerializer serializer   = new XmlSerializer(typeof(ContactsList));
            ContactsList  contactsList = new ContactsList();

            contactsList.name   = new string[contacts.Count];
            contactsList.number = new string[contacts.Count];
            for (int i = 0; i < contacts.Count; i++)
            {
                contactsList.name[i]   = contacts[i].name;
                contactsList.number[i] = contacts[i].number;
            }
            contactsList.fStart = firstStart;
            serializer.Serialize(stream, contactsList);
            stream.Close();

            container.Dispose();
        }