コード例 #1
0
 public AccountManager(string datafilePath)
 {
     if (!File.Exists(datafilePath))
     {
         // create an empty data file
         CSVUtil.WriteToFile(datafilePath, null);
     }
     accountsDataFilePath = datafilePath;
 }
コード例 #2
0
        private Dictionary <string, EmailAccountInfo> LoadAccounts()
        {
            Dictionary <string, EmailAccountInfo> accounts = new Dictionary <string, EmailAccountInfo>();

            if (accountsDataFilePath != null)
            {
                List <String[]> ls = CSVUtil.ReadFromFile(this.accountsDataFilePath);

                //i start from 1, skip title
                for (int i = 1; i < ls.Count; i++)
                {
                    if (ls[i].Length != CSVUtil.ColumnCount)
                    {
                        LogManager.SingleInstance.Log("Invalid account record found: {0}, it will be removed", ls[i]);
                        continue;
                    }
                    String[] strArr = ls[i];
                    Dictionary <string, string> extendedProperties = null;

                    extendedProperties = new Dictionary <string, string>();
                    extendedProperties[Constants.ExtendedParam_DGs] = strArr[(int)CSVUtil.AccountPropertyIndex.DistributionLists];
                    extendedProperties[Constants.KeyForwardEmail]   = strArr[(int)CSVUtil.AccountPropertyIndex.KeyForwardEmail];
                    extendedProperties[Constants.KeyActiveSync]     = strArr[(int)CSVUtil.AccountPropertyIndex.KeyActiveSync];

                    EmailAccountInfo info = new EmailAccountInfo(extendedProperties);
                    if (strArr.Length > (int)CSVUtil.AccountPropertyIndex.AdditionalEmailAddresses)
                    {
                        char[] splitters = { '|' };
                        if (!string.IsNullOrEmpty(strArr[(int)CSVUtil.AccountPropertyIndex.AdditionalEmailAddresses]))
                        {
                            string[] emailAddresses = strArr[(int)CSVUtil.AccountPropertyIndex.AdditionalEmailAddresses].Split(splitters);
                            foreach (string emailAddress in emailAddresses)
                            {
                                info.AdditionalEmailAddresses.Add(emailAddress);
                            }
                        }
                    }

                    info.AccountId           = strArr[(int)CSVUtil.AccountPropertyIndex.AccountId];
                    info.DisplayName         = strArr[(int)CSVUtil.AccountPropertyIndex.DisplayName];
                    info.PrimaryEmailAddress = strArr[(int)CSVUtil.AccountPropertyIndex.PrimaryEmailAddress];

                    bool parseResult = true;
                    if (Boolean.TryParse(strArr[(int)CSVUtil.AccountPropertyIndex.Enabled], out parseResult))
                    {
                        info.Enabled = parseResult;
                    }

                    info.FirstName = strArr[(int)CSVUtil.AccountPropertyIndex.FirstName];
                    info.LastName  = strArr[(int)CSVUtil.AccountPropertyIndex.LastName];
                    LogManager.SingleInstance.Log("Account loaded: {0}", info.ToString());
                    accounts.Add(info.AccountId, info);
                }
            }
            return(accounts);
        }
コード例 #3
0
        private void SaveAccounts(Dictionary <string, EmailAccountInfo> accounts)
        {
            if (accounts == null)
            {
                throw new ArgumentNullException("accounts");
            }
            lock (this)
            {
                if (this.accountsDataFilePath != null)
                {
                    List <String[]> ls = new List <String[]>();
                    foreach (EmailAccountInfo account in accounts.Values)
                    {
                        String[] rowStringArray = new String[CSVUtil.ColumnCount];
                        rowStringArray[(int)CSVUtil.AccountPropertyIndex.AccountId]           = account.AccountId;
                        rowStringArray[(int)CSVUtil.AccountPropertyIndex.DisplayName]         = account.DisplayName;
                        rowStringArray[(int)CSVUtil.AccountPropertyIndex.PrimaryEmailAddress] = account.PrimaryEmailAddress;
                        rowStringArray[(int)CSVUtil.AccountPropertyIndex.Enabled]             = account.Enabled.ToString();
                        rowStringArray[(int)CSVUtil.AccountPropertyIndex.FirstName]           = account.FirstName;
                        rowStringArray[(int)CSVUtil.AccountPropertyIndex.LastName]            = account.LastName;
                        if (account.ExtendedProperties != null && account.ExtendedProperties.ContainsKey(Constants.ExtendedParam_DGs))
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.DistributionLists] = account.ExtendedProperties[Constants.ExtendedParam_DGs];
                        }
                        else
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.DistributionLists] = string.Empty;
                        }

                        if (account.ExtendedProperties != null && account.ExtendedProperties.ContainsKey(Constants.KeyActiveSync))
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.KeyActiveSync] = account.ExtendedProperties[Constants.KeyActiveSync];
                        }
                        else
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.KeyActiveSync] = false.ToString();
                        }

                        if (account.ExtendedProperties != null && account.ExtendedProperties.ContainsKey(Constants.KeyForwardEmail))
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.KeyForwardEmail] = account.ExtendedProperties[Constants.KeyForwardEmail];
                        }
                        else
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.KeyForwardEmail] = string.Empty;
                        }

                        if (account.AdditionalEmailAddresses != null)
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.AdditionalEmailAddresses] = string.Join("|", account.AdditionalEmailAddresses);
                        }
                        else
                        {
                            rowStringArray[(int)CSVUtil.AccountPropertyIndex.AdditionalEmailAddresses] = string.Empty;
                        }

                        ls.Add(rowStringArray);
                    }
                    CSVUtil.WriteToFile(this.accountsDataFilePath, ls);
                }
            }
        }