Exemple #1
0
        private void SaveUserConfig()
        {
            RoboSepUserConfig config = new RoboSepUserConfig();

            config.CurrentUser = myCurrentActionContext;

            using (FileStream fs = new FileStream(myUserConfigPath, FileMode.Create))
            {
                XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
                writer.Formatting = Formatting.Indented;
                myXmlSerializer.Serialize(writer, config);
            }
        }
Exemple #2
0
        private void LoadCurrentUser()
        {
            RoboSepUserConfig config = null;

            if (File.Exists(myUserConfigPath))
            {
                // Initialise a file stream for reading
                FileStream fs = new FileStream(myUserConfigPath, FileMode.Open);

                try
                {
                    // Deserialize a RoboSepProtocol XML description into a RoboSepProtocol
                    // object that matches the contents of the specified protocol file.
                    XmlReader reader = new XmlTextReader(fs);

                    // Create a validating reader to process the file.  Report any errors to the
                    // validation page.
                    XmlValidatingReader validatingReader = new XmlValidatingReader(reader);
                    validatingReader.ValidationType = ValidationType.Schema;

                    // Get the RoboSep protocol schema and add it to the collection for the
                    // validator
                    XmlSchemaCollection xsc = new XmlSchemaCollection();
                    xsc.Add("STI", myXSDPath);
                    validatingReader.Schemas.Add(xsc);

                    // 'Rehydrate' the object (that is, deserialise data into the object)
                    config = (RoboSepUserConfig)myXmlSerializer.Deserialize(validatingReader);
                    myCurrentActionContext = config.CurrentUser;
                }
                catch (Exception /*ex*/)
                {
                    MessageBox.Show("User Config File Invalid");
                    myCurrentActionContext = "User1.udb";
                }
                finally
                {
                    // Close the file stream
                    fs.Close();
                }
            }
            else
            {
                myCurrentActionContext = "User1.udb";
            }
        }