Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.IO;
- using System.Xml.Serialization;
- using System.Xml;
- using WCell.Util;
- namespace miclipse.Irc
- {
- public class AccountsList : XmlFile<AccountsList>
- {
- public static string AccountsFileName = "Accounts.xml";
- [XmlElement("Account")]
- public Account[] Accounts { get; set; }
- public static string FilePath
- {
- get { return AccountsFileName; }
- }
- public static Dictionary<string, int> AccountsDict = new Dictionary<string, int>();
- public static Dictionary<string, int> LoadDictionary(string filename)
- {
- var dict = new Dictionary<string, int>();
- if (File.Exists(FilePath))
- {
- var cfg = Load(FilePath);
- if (cfg != null && cfg.Accounts != null)
- {
- foreach (var account in cfg.Accounts)
- dict[account.AccountName] = account.AccountLevel;
- }
- }
- AccountsDict = dict;
- return dict;
- }
- public static void SaveDictionary(string filename, Dictionary<string, int> accounts)
- {
- var array = accounts.TransformArray(pair => new Account(pair.Key, pair.Value));
- var cfg = new AccountsList { Accounts = array };
- cfg.SaveAs(FilePath);
- }
- }
- public class Account
- {
- public string AccountName;
- public int AccountLevel;
- public Account(string accountName, int accountLevel)
- {
- AccountName = accountName;
- AccountLevel = accountLevel;
- }
- public Account()
- { }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement