Advertisement
miceiken

Untitled

Mar 25th, 2011
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Xml.Serialization;
  4. using System.Xml;
  5. using WCell.Util;
  6.  
  7. namespace miclipse.Irc
  8. {
  9.     public class AccountsList : XmlFile<AccountsList>
  10.     {
  11.         public static string AccountsFileName = "Accounts.xml";
  12.  
  13.         [XmlElement("Account")]
  14.         public Account[] Accounts { get; set; }
  15.  
  16.         public static string FilePath
  17.         {
  18.             get { return AccountsFileName; }
  19.         }
  20.  
  21.         public static Dictionary<string, int> AccountsDict = new Dictionary<string, int>();
  22.         public static Dictionary<string, int> LoadDictionary(string filename)
  23.         {
  24.             var dict = new Dictionary<string, int>();
  25.             if (File.Exists(FilePath))
  26.             {
  27.                 var cfg = Load(FilePath);
  28.                 if (cfg != null && cfg.Accounts != null)
  29.                 {
  30.                     foreach (var account in cfg.Accounts)
  31.                         dict[account.AccountName] = account.AccountLevel;
  32.                 }
  33.             }
  34.             AccountsDict = dict;
  35.             return dict;
  36.         }
  37.  
  38.         public static void SaveDictionary(string filename, Dictionary<string, int> accounts)
  39.         {
  40.             var array = accounts.TransformArray(pair => new Account(pair.Key, pair.Value));
  41.             var cfg = new AccountsList { Accounts = array };
  42.             cfg.SaveAs(FilePath);
  43.         }
  44.     }
  45.  
  46.     public class Account
  47.     {
  48.         public string AccountName;
  49.         public int AccountLevel;
  50.  
  51.         public Account(string accountName, int accountLevel)
  52.         {
  53.             AccountName = accountName;
  54.             AccountLevel = accountLevel;
  55.         }
  56.  
  57.         public Account()
  58.         { }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement