public AccountManager(string datafilePath) { if (!File.Exists(datafilePath)) { // create an empty data file CSVUtil.WriteToFile(datafilePath, null); } accountsDataFilePath = datafilePath; }
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); } } }