Exemplo n.º 1
0
        /// <summary>
        /// Save the account database
        /// </summary>
        public static void Save()
        {
            string filePath = Persistance.GetSavePathname("accounts.xml");

            using (StreamWriter sw = new StreamWriter(filePath))
            {
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.Formatting  = Formatting.Indented;
                writer.IndentChar  = '\t';
                writer.Indentation = 1;

                writer.WriteStartDocument(true);

                writer.WriteStartElement("accounts");

                writer.WriteAttributeString("version", Account.AccountSaveVersion.ToString());
                writer.WriteAttributeString("count", m_byId.Count.ToString());

                foreach (Account a in m_byId.Values)
                {
                    a.Serialize(writer);
                }

                writer.WriteEndElement();

                writer.Close();
            }
        }
Exemplo n.º 2
0
        private static void Load()
        {
            string filePath = Persistance.GetSavePathname("accounts.xml");

            if (!File.Exists(filePath))
            {
                Loaded = true;
                Console.WriteLine("Accounts: No account file found.");
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(filePath);

            XmlElement root    = doc["accounts"];
            int        version = Persistance.Xml.GetXMLInt32(Persistance.Xml.GetAttribute(root, "version"), -1);
            int        size    = Persistance.Xml.GetXMLInt32(Persistance.Xml.GetAttribute(root, "count"), -1);

            foreach (XmlElement element in root.GetElementsByTagName("account"))
            {
                try
                {
                    Account account = new Account(element, version);
                    InternalAdd(account);
                }
                catch
                {
                    Console.WriteLine("Account load failed");
                }
            }
            Loaded = true;

            if (m_byId.Count != size)
            {
                Console.WriteLine("Accounts: Warning: Loaded {0} of {1} accounts.", m_byId.Count, size);
            }
            else
            {
                Console.WriteLine("Accounts: Loaded {0} accounts.", m_byId.Count);
            }
        }