Esempio n. 1
0
        private void SaveSetting()
        {
            //throw new System.NotImplementedException();

            #region zhucebiao
            //RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("SoftWare", true);
            //RegistryKey SQKey = softwareKey.CreateSubKey("SQPress");
            //RegistryKey selfWindowsKey = SQKey.CreateSubKey("selfWindowsKey");
            //selfWindowsKey.SetValue("BackColor", (object)BackColor.ToKnownColor());
            //selfWindowsKey.SetValue("Red", (object)(int)BackColor.R);
            //selfWindowsKey.SetValue("Green", (object)(int)BackColor.G);
            //selfWindowsKey.SetValue("Blue", (object)(int)BackColor.B);
            //selfWindowsKey.SetValue("Width", (object)Width);
            //selfWindowsKey.SetValue("Height", (object)Height);
            //selfWindowsKey.SetValue("X", (object)DesktopLocation.X);
            //selfWindowsKey.SetValue("Y", (object)DesktopLocation.Y);
            //selfWindowsKey.SetValue("WindowState", (object)WindowState.ToString());

            //softwareKey.Close();
            //SQKey.Close();
            //selfWindowsKey.Close();
            #endregion

            #region ISO
            IsolatedStorageFile iso         = IsolatedStorageFile.GetUserStoreForDomain();
            var isoStream                   = new IsolatedStorageFileStream("SelfPlace.xml", FileMode.Create, FileAccess.ReadWrite);
            System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(isoStream, Encoding.Default);
            writer.Formatting = System.Xml.Formatting.Indented;


            writer.WriteStartDocument();
            writer.WriteStartElement("Settings");

            writer.WriteStartElement("Width");
            writer.WriteValue(this.Width);
            writer.WriteEndElement();

            writer.WriteStartElement("Height");
            writer.WriteValue(this.Height);
            writer.WriteEndElement();

            writer.WriteStartElement("X");
            writer.WriteValue(this.DesktopLocation.X);
            writer.WriteEndElement();

            writer.WriteStartElement("Y");
            writer.WriteValue(this.DesktopLocation.Y);
            writer.WriteEndElement();

            writer.WriteEndElement();

            writer.Flush();
            writer.Close();

            isoStream.Close();
            iso.Close();
            #endregion
        }
Esempio n. 2
0
        public void CreateFile()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            // Make sure we are actually creating it, by first removing it in case it already exists
            if (isf.FileExists("file-a"))
            {
                isf.DeleteFile("file-a");
            }

            IsolatedStorageFileStream isf_stream = isf.CreateFile("file-a");

            isf_stream.Close();
            Assert.AreEqual(true, isf.FileExists("file-a"), "#A0");

            // Re-open the file that is already created, so we make sure we are passing
            // the proper FileOpen
            isf_stream = isf.CreateFile("file-a");
            isf_stream.Close();

            try
            {
                isf.CreateFile(null);
                Assert.Fail("#Exc1");
            }
            catch (ArgumentNullException)
            {
            }

            try
            {
                isf.CreateFile("random-dir/fileb");
                Assert.Fail("#Exc2");
            }
            catch (DirectoryNotFoundException)
            {
            }

            isf.Close();
            try
            {
                isf.CreateFile("file-b");
                Assert.Fail("#Exc3");
            }
            catch (InvalidOperationException)
            {
            }

            isf.Dispose();
            try
            {
                isf.CreateFile("file-a");
                Assert.Fail("#Exc4");
            }
            catch (ObjectDisposedException)
            {
            }
        }
Esempio n. 3
0
 private void newUser_Click(object sender, RoutedEventArgs e)
 {
     if (unametxt.Text != "")
     {
         blkuname.Visibility = Visibility.Visible;
         if (!isoStore.DirectoryExists("PCGuardian/users/" + unametxt.Text))
         {
             if (passtxt.Password == cpasstxt.Password && passtxt.Password != "")
             {
                 nomatch.Visibility = Visibility.Collapsed;
                 String location = "PCGuardian/users/" + unametxt.Text;
                 isoStore.CreateDirectory(location);
                 isoStore.CreateDirectory(location + "/blocked");
                 String passwd = location + "/passwd.txt";
                 using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(passwd, FileMode.CreateNew, isoStore))
                 {
                     using (StreamWriter writer = new StreamWriter(isoStream))
                     {
                         writer.WriteLine(passtxt.Password);
                         writer.Close();
                     }
                     isoStream.Close();
                 }
                 isoStore.Close();
                 Application app = Application.Current;
                 app.Properties["uname"] = unametxt.Text;
                 this.NavigationService.Navigate(new newUserBlock());
             }
             else if (passtxt.Password == "" || cpasstxt.Password == "")
             {
                 blkpass.Visibility = Visibility.Visible;
             }
             else
             {
                 passtxt.Password   = "";
                 cpasstxt.Password  = "";
                 nomatch.Visibility = Visibility.Visible;
             }
         }
         else
         {
             exist.Visibility = Visibility.Visible;
         }
     }
 }
		public void MoveDirectory ()
		{
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
			// Mare sure to remove them if they exist already
			if (isf.DirectoryExists ("subdir"))
				isf.DeleteDirectory ("subdir");
			if (isf.DirectoryExists ("subdir-new"))
				isf.DeleteDirectory ("subdir-new");

			isf.CreateDirectory ("subdir");
			Assert.AreEqual (true, isf.DirectoryExists ("subdir"), "#A0");

			isf.MoveDirectory ("subdir", "subdir-new");
			Assert.AreEqual (false, isf.DirectoryExists ("subdir"), "#A1");
			Assert.AreEqual (true, isf.DirectoryExists ("subdir-new"), "#A2");

			try {
				isf.MoveDirectory (String.Empty, "subdir-new-new");
				Assert.Fail ("#Exc1");
			} catch (ArgumentException) {
			}

			try {
				isf.MoveDirectory ("  ", "subdir-new-new");
				Assert.Fail ("#Exc2");
			} catch (ArgumentException) {
			}

			try {
				isf.MoveDirectory ("doesntexist", "subdir-new-new");
				Assert.Fail ("#Exc3");
			} catch (DirectoryNotFoundException) {
			}

			try {
				isf.MoveDirectory ("doesnexist/doesntexist", "subdir-new-new");
				Assert.Fail ("#Exc4");
			} catch (DirectoryNotFoundException) {
			}

			try {
				isf.MoveDirectory ("subdir-new", "doesntexist/doesntexist");
				Assert.Fail ("#Exc5");
			} catch (DirectoryNotFoundException) {
			}

			// Out of storage dir
			try {
				isf.MoveDirectory ("subdir-new", "../../subdir-new");
				Assert.Fail ("#Exc6");
			} catch (IsolatedStorageException) {
			}

			isf.Remove ();
			isf.Close ();
			isf.Dispose ();
		}
 private void CloseContainer()
 {
     if (m_container != null)
     {
         m_container.Close();
         m_container.Dispose();
         m_container = null;
     }
 }
        public void GetUserStoreForDomain_Administer()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain();

            Read(isf);
            Write(isf);
            isf.Dispose();
            isf.Close();
        }
Esempio n. 7
0
 public virtual void RemovePlugin(string name)
 {
     plugins.Remove(name);
     using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         store.DeleteFile(name + ".yml");
         store.Close();
     }
 }
        public void GetMachineStoreForAssembly_Administer()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForAssembly();

            Read(isf);
            Write(isf);
            isf.Dispose();
            isf.Close();
        }
        public void GetMachineStoreForDomain_Pass()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetMachineStoreForDomain();

            Read(isf);
            Write(isf);
            isf.Dispose();
            isf.Close();
        }
        public void GetUserStoreForAssembly_Pass()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            Read(isf);
            Write(isf);
            isf.Dispose();
            isf.Close();
        }
Esempio n. 11
0
 private void logout_Click(object sender, RoutedEventArgs e)
 {
     isoStore.DeleteFile("PCGuardian/temp/loggedin.txt");
     MyFunctions.deleteExplorer();
     MyFunctions.blockfolder(isoStore, "PCGuardian/guest/blocked/1party");
     MyFunctions.blockfolder(isoStore, "PCGuardian/guest/blocked/2party");
     isoStore.Close();
     this.NavigationService.Navigate(new startup());
 }
        public void GetUserStoreForDomain_Roaming_Pass()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain();

            Read(isf);
            Write(isf);
            isf.Dispose();
            isf.Close();
        }
Esempio n. 13
0
        private void confirm_Click(object sender, RoutedEventArgs e)
        {
            String location = "PCGuardian/admin/uname.txt";

            using (IsolatedStorageFileStream isoStreamuname = new IsolatedStorageFileStream(location, FileMode.Open, isoStore))
            {
                using (StreamReader readeruname = new StreamReader(isoStreamuname))
                {
                    String saveduname = readeruname.ReadLine();
                    if (saveduname == unametxt.Text)
                    {
                        location = "PCGuardian/admin/passwd.txt";
                        using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(location, FileMode.Open, isoStore))
                        {
                            using (StreamReader reader = new StreamReader(isoStream))
                            {
                                String savedPasswd = reader.ReadLine();
                                if (savedPasswd == passtxt.Password)
                                {
                                    reader.Close();
                                    readeruname.Close();
                                    isoStreamuname.Close();
                                    isoStream.Close();
                                    Application app = Application.Current;
                                    MyFunctions.DeleteDirectoryRecursively(isoStore, ("PCGuardian/users/" + app.Properties["uname"]));
                                    isoStore.Close();
                                    this.NavigationService.Navigate(new adminPortal());
                                }
                                else
                                {
                                    nomatch.Visibility = Visibility.Visible;
                                }
                            }
                        }
                    }
                    else
                    {
                        nomatch.Visibility = Visibility.Visible;
                    }
                }
            }
        }
 public void Dispose()
 {
     // Dispose managed resources
     if (_isoStore != null)
     {
         lock (_isoStore)
         {
             _isoStore.Close();
         }
     }
 }
Esempio n. 15
0
        public void DirectoryExists()
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();

            isf.CreateDirectory("subdir");
            isf.CreateDirectory("subdir/subdir2");
            isf.CreateDirectory("subdir3");

            Assert.AreEqual(true, isf.DirectoryExists("subdir/"), "#A0");
            Assert.AreEqual(true, isf.DirectoryExists("subdir/subdir2/"), "#A1");
            Assert.AreEqual(true, isf.DirectoryExists("subdir3"), "#A2");
            Assert.AreEqual(true, isf.DirectoryExists(String.Empty), "#A3");               // Weird
            Assert.AreEqual(false, isf.DirectoryExists("subdir99"), "#A4");
            Assert.AreEqual(false, isf.DirectoryExists("../../subdir"), "#A5");
            Assert.AreEqual(false, isf.DirectoryExists("*"), "#A5");
            Assert.AreEqual(false, isf.DirectoryExists("subdir*"), "#A6");

            isf.DeleteDirectory("subdir3");
            Assert.AreEqual(false, isf.DirectoryExists("subdir3"), "#B0");

            isf.DeleteDirectory("subdir/subdir2");
            isf.DeleteDirectory("subdir");

            try {
                isf.DirectoryExists(null);
                Assert.Fail("#Exc1");
            } catch (ArgumentNullException) {
            }

            isf.Close();
            try {
                isf.DirectoryExists("subdir");
                Assert.Fail("#Exc2");
            } catch (InvalidOperationException) {
            }

            isf.Dispose();
            try {
                isf.DirectoryExists("subdir");
                Assert.Fail("#Exc3");
            } catch (ObjectDisposedException) {
            }

            // We want to be sure that if not closing but disposing
            // should fire ObjectDisposedException instead of InvalidOperationException
            isf = IsolatedStorageFile.GetUserStoreForAssembly();
            isf.Dispose();

            try {
                isf.DirectoryExists("subdir");
                Assert.Fail("#Exc4");
            } catch (ObjectDisposedException) {
            }
        }
 public MainWindow()
 {
     InitializeComponent();
     //MyFunctions.DeleteDirectoryRecursively(isoStore, "PCGuardian");
     if (isoStore.DirectoryExists("PCGuardian"))
     {
         if (isoStore.FileExists("PCGuardian/temp/loggedin.txt"))
         {
             String user;
             using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("PCGuardian/temp/loggedin.txt", FileMode.Open, isoStore))
             {
                 using (StreamReader reader = new StreamReader(isoStream))
                 {
                     user = reader.ReadLine();
                     reader.Close();
                 }
                 isoStream.Close();
             }
             isoStore.Close();
             if (user == "admin")
             {
                 frame1.NavigationService.Navigate(new adminPortal());
             }
             else
             {
                 Application app = Application.Current;
                 app.Properties["loggeduser"] = user;
                 frame1.NavigationService.Navigate(new userPortal());
             }
         }
         else
         {
             isoStore.Close();
             frame1.NavigationService.Navigate(new startup());
         }
     }
     else
     {
         frame1.NavigationService.Navigate(new setup());
     }
 }
Esempio n. 17
0
        private void Konfiguracja_Usun()
        {
            if (BlokadaKonfiguracji == true)
            {
                return;
            }

            IsolatedStorageFile Magazyn = IsolatedStorageFile.GetMachineStoreForAssembly();

            Magazyn.Remove();
            Magazyn.Close();
        }
Esempio n. 18
0
    //<snippet4>
    private bool GetPrefsForUser()
    {
        try
        {
            //<Snippet15>

            // Retrieve an IsolatedStorageFile for the current Domain and Assembly.
            IsolatedStorageFile isoFile =
                IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
                                             IsolatedStorageScope.Assembly |
                                             IsolatedStorageScope.Domain,
                                             null,
                                             null);

            IsolatedStorageFileStream isoStream =
                new IsolatedStorageFileStream("substituteUsername",
                                              System.IO.FileMode.Open,
                                              System.IO.FileAccess.Read,
                                              System.IO.FileShare.Read);
            //</Snippet15>

            // The code executes to this point only if a file corresponding to the username exists.
            // Though you can perform operations on the stream, you cannot get a handle to the file.

            try
            {
                SafeFileHandle aFileHandle = isoStream.SafeFileHandle;
                Console.WriteLine("A pointer to a file handle has been obtained. "
                                  + aFileHandle.ToString() + " "
                                  + aFileHandle.GetHashCode());
            }

            catch (Exception e)
            {
                // Handle the exception.
                Console.WriteLine("Expected exception");
                Console.WriteLine(e);
            }

            StreamReader reader = new StreamReader(isoStream);
            // Read the data.
            this.NewsUrl   = reader.ReadLine();
            this.SportsUrl = reader.ReadLine();
            reader.Close();
            isoFile.Close();
            return(false);
        }
        catch (System.IO.FileNotFoundException)
        {
            // Expected exception if a file cannot be found. This indicates that we have a new user.
            return(true);
        }
    }
Esempio n. 19
0
 private static void ClearCache()
 {
     lock (sSemaphore)
     {
         sCachedDictionary.Clear();
         if (sIsolatedStorageFile != null)
         {
             sIsolatedStorageFile.Close();
             sIsolatedStorageFile = null;
         }
     }
 }
Esempio n. 20
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            // Создаем IsolatedStorageFile и определяем место для хранения настроек приложения.
            try
            {
                IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForDomain();
                isoStorage.DeleteFile("UserSettingsDS.xml");
                isoStorage.Close();

                MessageBox.Show("Настройки успешно удалены", "Пример");
            }
            catch (System.Exception ex) { MessageBox.Show(ex.Message); } // Обработка ошибок.
        }
Esempio n. 21
0
        public void LoadCardTextures()
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            LoadAllCards();
            XmlSerializer serializer = new XmlSerializer(typeof(Cards));

            if (!store.FileExists("Config_Cards"))
            {
                var        fs     = store.CreateFile("Config_Cards");
                TextWriter writer = new StreamWriter(fs);
                config             = new Cards();
                config.listOfCards = new List <CardConfig>();
                CardTypes.ForEach(p =>
                {
                    CardConfig c = new CardConfig();
                    c.Name       = p.Name;
                    c.SkinPath   = String.Empty;
                    config.listOfCards.Add(c);
                });
                XmlSerializer xml = new XmlSerializer(typeof(Cards));
                xml.Serialize(writer, config);
                writer.Close();
                fs.Close();
            }

            var file = store.OpenFile("Config_Cards", FileMode.Open);

            config = (Cards)serializer.Deserialize(file);
            file.Close();
            ShipsSkins.Clear();
            config.listOfCards.ForEach(p =>
            {
                CardTypes.Where(a => a.Name == p.Name).ToList().ForEach(z =>
                {
                    Texture2D skin = store.FileExists(p.SkinPath) ? loadTexture2D(p.SkinPath) : null;
                    ShipsSkins.Add(new ShipAndSkin()
                    {
                        ship = z.Name,
                        skin = skin
                    });
                    SkinsPaths.Add(new SkinAndPath()
                    {
                        skin = skin,
                        path = p.SkinPath
                    });
                });
            });
            file.Close();
            store.Close();
        }
Esempio n. 22
0
        /// <summary> Reads the user settings from a XML file in Isolated Storage </summary>
        /// <returns> TRUE if the XML file already existed, otherwise FALSE </returns>
        /// <remarks> If the XML file does not exist, an empty DataSet is created </remarks>
        protected static bool Read_XML_File( )
        {
            // Create the isolated storage file to load the information from the disk
            IsolatedStorageFile userSettingFile = IsolatedStorageFile.GetUserStoreForAssembly();

            // Look to see if the file exists
            string[] files = userSettingFile.GetFileNames(fileName + ".xml");
            if (files.Length > 0)
            {
                // Create a stream reader to get the data from the isolated storage for this user
                StreamReader stmReader = new StreamReader(new IsolatedStorageFileStream(fileName + ".xml", FileMode.Open, userSettingFile));

                // Read the xml file
                Setting_DataSet = new DataSet();
                Setting_DataSet.ReadXml(stmReader, XmlReadMode.ReadSchema);

                // Fetch the one line of data
                userSettings = Setting_DataSet.Tables[0].Rows[0];

                // Close the stream
                stmReader.Close();

                // Close the connection to the isolated storage
                userSettingFile.Close();

                // Return true since the file already existed
                return(true);
            }

            // The file did not exist yet, so create a data set locally
            Create_DataSet();

            // Close the connection to the isolated storage
            userSettingFile.Close();

            // Return false since the file did not already exist
            return(false);
        }
Esempio n. 23
0
 public virtual void AddPlugin(string name, IPlugin plugin)
 {
     using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         var serializer = new YamlSerializer();
         using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(name + ".yml", FileMode.OpenOrCreate, FileAccess.Write, store))
         {
             serializer.Serialize(stream, plugin);
             stream.Close();
         }
         store.Close();
     }
     plugins.Add(name, plugin);
 }
Esempio n. 24
0
        private static void Demo5CreateFolderIsolatedStorage()
        {
            IsolatedStorageFile usrStorage = IsolatedStorageFile.GetUserStoreForAssembly();

            usrStorage.CreateDirectory("MyDir");
            IsolatedStorageFileStream usrFile = new IsolatedStorageFileStream(@"MyDir\myFile.dat",
                                                                              FileMode.Create,
                                                                              usrStorage);

            //TODO: check this error
            //usrFile.Write(12);

            usrFile.Close();
            usrStorage.Close();
        }
Esempio n. 25
0
 public virtual void LoadRepositories()
 {
     repositories = new List <Repository>();
     using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         if (store.FileExists(filename))
         {
             using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.Read, store))
             {
                 repositories = Serializer.Deserialize <List <Repository> >(stream);
             }
         }
         store.Close();
     }
 }
Esempio n. 26
0
        public void FileExists()
        {
            IsolatedStorageFile       isf    = IsolatedStorageFile.GetUserStoreForAssembly();
            IsolatedStorageFileStream file_a = new IsolatedStorageFileStream("file-a", FileMode.Create, isf);
            IsolatedStorageFileStream file_b = new IsolatedStorageFileStream("file-b", FileMode.Create, isf);

            file_a.Close();
            file_b.Close();

            Assert.AreEqual(true, isf.FileExists("file-a"), "#A0");
            Assert.AreEqual(true, isf.FileExists("file-b"), "#A1");
            Assert.AreEqual(false, isf.FileExists(String.Empty), "#A2");
            Assert.AreEqual(false, isf.FileExists("file-"), "#A3");
            Assert.AreEqual(false, isf.FileExists("file-*"), "#A4");
            Assert.AreEqual(false, isf.FileExists("../../file-a"), "#A5");

            isf.CreateDirectory("subdir");
            Assert.AreEqual(false, isf.FileExists("subdir"), "#B0");

            try
            {
                isf.FileExists(null);
                Assert.Fail("#Exc1");
            }
            catch (ArgumentNullException)
            {
            }

            isf.Close();
            try
            {
                isf.FileExists("file-a");
                Assert.Fail("#Exc2");
            }
            catch (InvalidOperationException)
            {
            }

            isf.Dispose();
            try
            {
                isf.FileExists("file-a");
                Assert.Fail("#Exc3");
            }
            catch (ObjectDisposedException)
            {
            }
        }
Esempio n. 27
0
 private void SaveWindowPosition()
 {
     try
     {
         double x = this.Left, y = this.Top;
         IsolatedStorageFile       isFile = IsolatedStorageFile.GetUserStoreForDomain();
         IsolatedStorageFileStream isStream = new IsolatedStorageFileStream(APP_NAME, FileMode.Create, FileAccess.Write);
         using (StreamWriter writer = new StreamWriter(isStream))
         {
             writer.WriteLine(string.Format("{0},{1}", x, y));
         }
         isStream.Close();
         isFile.Close();
     }
     catch (Exception) { }
 }
Esempio n. 28
0
        public bool Export()
        {
            _mysqlDumpFacade = _tables != null
        ? new MySqlDumpFacade(ExportOptions, OutputFilePath, _fileName, _tables)
        : new MySqlDumpFacade(ExportOptions, OutputFilePath, _fileName);
            _mysqlDumpFacade.ProcessRequest(OutputFilePath);
            _isoStore.DeleteFile(Path.GetFileName(_fileName));
            _isoStore.Close();
            if (_mysqlDumpFacade.ErrorsOutput == null || string.IsNullOrEmpty(_mysqlDumpFacade.ErrorsOutput.ToString()))
            {
                return(true);
            }

            ErrorsOutput = _mysqlDumpFacade.ErrorsOutput;
            return(false);
        }
Esempio n. 29
0
        /// <summary>
        /// Save settings
        /// </summary>
        public virtual void Save()
        {
            IsolatedStorageFile       isoStore = null;
            IsolatedStorageFileStream stream   = null;
            XmlTextWriter             writer   = null;

            try
            {
                isoStore = IsolatedStorageFile.GetMachineStoreForDomain();

                if (isoStore.FileExists(SettingsFile))
                {
                    stream = new IsolatedStorageFileStream(SettingsFile,
                                                           FileMode.Create, isoStore);
                }
                else
                {
                    stream = new IsolatedStorageFileStream(SettingsFile,
                                                           FileMode.CreateNew, isoStore);
                }

                writer = new XmlTextWriter(stream, Encoding.UTF8);

                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();

                XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                serializer.Serialize(writer, Settings);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Flush();
                }

                if (stream != null)
                {
                    stream.Close();
                }

                if (isoStore != null)
                {
                    isoStore.Close();
                }
            }
        }
Esempio n. 30
0
        //----------------------------------------------
        //Private Methods
        //----------------------------------------------

        //
        // SaveSettings and LoadSettings use an XML file, saved in so called
        // Isolated Storage.
        //
        // I'm not convinced that this is really the best way or the best place
        // to store this information, but it's certainly a .NET way to do it.
        //
        private void LoadSettings()
        {
            // Set the defaults
            StartupMode     = enumStartupMode.ShowDialog;
            SelectedCulture = Thread.CurrentThread.CurrentUICulture;

            // Create an IsolatedStorageFile object and get the store
            // for this application.
            IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForDomain();

            // Check whether the file exists
            if (isoStorage.GetFileNames("CultureSettings.xml").Length > 0) //MLHIDE
            {
                // Create isoStorage StreamReader.
                StreamReader stmReader = new StreamReader
                                             (new IsolatedStorageFileStream
                                                 ("CultureSettings.xml",
                                                 FileMode.Open,
                                                 isoStorage));    //MLHIDE

                XmlTextReader xmlReader = new XmlTextReader(stmReader);

                // Loop through the XML file until all Nodes have been read and processed.
                while (xmlReader.Read())
                {
                    switch (xmlReader.Name)
                    {
                    case "StartupMode":                                             //MLHIDE
                        StartupMode = (enumStartupMode)int.Parse(xmlReader.ReadString());
                        break;

                    case "Culture":                                                 //MLHIDE
                        String      CultName = xmlReader.ReadString();
                        CultureInfo CultInfo = new CultureInfo(CultName);
                        SelectedCulture = CultInfo;
                        break;
                    }
                }

                // Close the reader
                xmlReader.Close();
                stmReader.Close();
            }

            isoStorage.Close();
        }