using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace ZcPeng.weixin.PublicAccount
{
///
/// 公众号集合
///
public static class AccountInfoCollection
{
///
/// 已知的公众号信息
///
private static ConcurrentDictionary accountInfos = new ConcurrentDictionary();
///
/// 获取公众号信息
///
/// 公众号
/// 返回公众号信息;如果公众号不存在,返回null。
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 UserNames
{
get
{
return accountInfos.Keys;
}
}
///
/// 获取已知的公众号信息
///
public static ICollection AccountInfos
{
get
{
return accountInfos.Values;
}
}
///
/// 获取第一个已知的公众号信息
///
public static AccountInfo First
{
get
{
AccountInfo account = null;
if (accountInfos.Count > 0)
{
foreach (KeyValuePair pair in accountInfos)
{
account = pair.Value;
break;
}
}
return account;
}
}
}
}