You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.8 KiB
127 lines
3.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using ProtoCSStruct;
|
|
|
|
namespace HttpProxy
|
|
{
|
|
public static class FacebookTokenCacheSvc
|
|
{
|
|
private static string GetKey(int accountType, string accountId)
|
|
{
|
|
return accountType.ToString() + "_" + accountId;
|
|
}
|
|
|
|
public static void UpdateAccountTokenToCache(int accountType, string accountId, string token, string nick, string icon, int gender, string email)
|
|
{
|
|
string key = GetKey(accountType, accountId);
|
|
|
|
FacebookTokenCache cache = HttpProxyServerUtils.GetHttpProxyServerData().m_facebookTokenCache;
|
|
|
|
lock(cache.Locker)
|
|
{
|
|
FacebookAccountInfo accountInfo;
|
|
if (cache.CacheDict.ContainsKey(key))
|
|
{
|
|
accountInfo = cache.CacheDict[key];
|
|
}
|
|
else
|
|
{
|
|
accountInfo = new FacebookAccountInfo();
|
|
accountInfo.AccountID = accountId;
|
|
accountInfo.AccountType = accountType;
|
|
|
|
cache.CacheDict.Add(key, accountInfo);
|
|
}
|
|
|
|
accountInfo.Token = token;
|
|
accountInfo.Nick = nick;
|
|
accountInfo.Icon = icon;
|
|
accountInfo.Gender = gender;
|
|
|
|
if (string.IsNullOrEmpty(email) == false)
|
|
{
|
|
accountInfo.Email = email;
|
|
}
|
|
else
|
|
{
|
|
accountInfo.Email = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void UpdateFriendToCache(int accountType, string accountId, List<SnsFriendInfoAccount> friendlist)
|
|
{
|
|
string key = GetKey(accountType, accountId);
|
|
|
|
FacebookTokenCache cache = HttpProxyServerUtils.GetHttpProxyServerData().m_facebookTokenCache;
|
|
|
|
lock (cache.Locker)
|
|
{
|
|
FacebookAccountInfo accountInfo;
|
|
if (cache.CacheDict.ContainsKey(key))
|
|
{
|
|
accountInfo = cache.CacheDict[key];
|
|
|
|
if(accountInfo.Friendlist == null)
|
|
{
|
|
accountInfo.Friendlist = new List<SnsFriendInfoAccount>();
|
|
}
|
|
accountInfo.Friendlist.Clear();
|
|
accountInfo.Friendlist.AddRange(friendlist);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static FacebookAccountInfo GetAccountInfo(int accountType, string accountId)
|
|
{
|
|
string key = GetKey(accountType, accountId);
|
|
|
|
FacebookTokenCache cache = HttpProxyServerUtils.GetHttpProxyServerData().m_facebookTokenCache;
|
|
|
|
lock (cache.Locker)
|
|
{
|
|
if (cache.CacheDict.ContainsKey(key))
|
|
{
|
|
return cache.CacheDict[key];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void ClearAccountInfo(int accountType, string accountId)
|
|
{
|
|
string key = GetKey(accountType, accountId);
|
|
|
|
FacebookTokenCache cache = HttpProxyServerUtils.GetHttpProxyServerData().m_facebookTokenCache;
|
|
|
|
lock (cache.Locker)
|
|
{
|
|
if (cache.CacheDict.ContainsKey(key))
|
|
{
|
|
cache.CacheDict.Remove(key);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
internal static void GmClearAllCache()
|
|
{
|
|
FacebookTokenCache cache = HttpProxyServerUtils.GetHttpProxyServerData().m_facebookTokenCache;
|
|
|
|
lock (cache.Locker)
|
|
{
|
|
cache.CacheDict.Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|