123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections.Generic;
- using System.Collections.Concurrent;
- namespace ZcPeng.weixin.PublicAccount
- {
-
-
-
- public static class AccountInfoCollection
- {
-
-
-
- private static ConcurrentDictionary<string, AccountInfo> accountInfos = new ConcurrentDictionary<string, AccountInfo>();
-
-
-
-
-
- public static AccountInfo GetAccountInfo(string userName)
- {
- return accountInfos.ContainsKey(userName) ? accountInfos[userName] : null;
- }
-
-
-
-
- public static void SetAccountInfo(AccountInfo account)
- {
- if (account == null)
- throw new ArgumentNullException("account", "公众号信息不能为空。");
- accountInfos[account.UserName] = account;
- }
-
-
-
- public static ICollection<string> UserNames
- {
- get
- {
- return accountInfos.Keys;
- }
- }
-
-
-
- public static ICollection<AccountInfo> AccountInfos
- {
- get
- {
- return accountInfos.Values;
- }
- }
-
-
-
- public static AccountInfo First
- {
- get
- {
- AccountInfo account = null;
- if (accountInfos.Count > 0)
- {
- foreach (KeyValuePair<string, AccountInfo> pair in accountInfos)
- {
- account = pair.Value;
- break;
- }
- }
- return account;
- }
- }
- }
- }
|