コード例 #1
0
        ///<summary>写入信息</summary>
        ///<param name="strategy">策略</param>
        ///<param name="appKey">AppKey</param>
        /// <param name="accountIdentity">帐号会话唯一标识</param>
        /// <param name="account">帐号信息</param>
        ///<returns>返回一个实例<see cref="AccountCacheInfo"/>的详细信息</returns>
        public void Write(IAccountStorageStrategy strategy, string appKey, string accountIdentity, IAccountInfo account)
        {
            // 过滤空值
            if (string.IsNullOrEmpty(accountIdentity))
            {
                return;
            }

            AccountCacheInfo param = strategy.Serialize(appKey, accountIdentity, account);

            param.Date = DateTime.Now;

            // 更新字典信息
            if (cacheStorage.ContainsKey(param.AccountIdentity))
            {
                cacheStorage[param.AccountIdentity] = param;
            }
            else
            {
                cacheStorage.Add(param.AccountIdentity, param);
            }

            // 更新数据库信息
            if (this.IsExist(param.AccountIdentity))
            {
                this.Update(param);
            }
            else
            {
                param.ValidFrom = DateTime.Now;
                param.ValidTo   = DateTime.Now.AddHours(SessionsConfigurationView.Instance.SessionTimeLimit);

                this.Insert(param);
            }
        }
コード例 #2
0
        /// <summary>查找数据</summary>
        /// <returns></returns>
        public string Find(XmlDocument doc)
        {
            StringBuilder outString = new StringBuilder();

            string accountIdentity = XmlHelper.Fetch("accountIdentity", doc);

            AccountCacheInfo param = this.service.FindByAccountIdentity(accountIdentity);

            outString.Append("{\"data\":");

            if (param != null)
            {
                outString.Append("{");
                outString.Append("\"accountIdentity\":\"" + param.AccountIdentity + "\",");
                outString.Append("\"accountCacheValue\":\"" + param.AccountCacheValue + "\",");
                outString.Append("\"accountObjectType\":\"" + param.AccountObjectType + "\",");
                outString.Append("\"accountObject\":\"" + param.AccountObject + "\",");
                outString.Append("\"date\":\"" + param.Date + "\" ");
                outString.Append("}");
            }

            outString.Append(",\"message\":{\"returnCode\":0,\"value\":\"操作成功。\"}}");

            return(outString.ToString());
        }
        /// <summary>将缓存信息反序列化为帐号信息</summary>
        /// <param name="accountCache"></param>
        /// <returns></returns>
        protected override IAccountInfo DeserializeObject(AccountCacheInfo accountCache)
        {
            AccountInfo account = new AccountInfo();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(accountCache.AccountObject);

            account.Id = doc.SelectSingleNode("accountObject/id").InnerText;

            if (doc.SelectSingleNode("accountObject/code") != null)
            {
                account.Code = doc.SelectSingleNode("accountObject/code").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/name") != null)
            {
                account.Name = doc.SelectSingleNode("accountObject/name").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/loginName") != null)
            {
                account.LoginName = doc.SelectSingleNode("accountObject/loginName").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/globalName") != null)
            {
                account.GlobalName = doc.SelectSingleNode("accountObject/globalName").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/displayName") != null)
            {
                account.DisplayName = doc.SelectSingleNode("accountObject/displayName").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/type") != null)
            {
                account.Type = Convert.ToInt32(doc.SelectSingleNode("accountObject/type").InnerText);
            }
            if (doc.SelectSingleNode("accountObject/certifiedAvatar") != null)
            {
                account.CertifiedAvatar = doc.SelectSingleNode("accountObject/certifiedAvatar").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/certifiedEmail") != null)
            {
                account.CertifiedEmail = doc.SelectSingleNode("accountObject/certifiedEmail").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/certifiedMobile") != null)
            {
                account.CertifiedMobile = doc.SelectSingleNode("accountObject/certifiedMobile").InnerText;
            }
            if (doc.SelectSingleNode("accountObject/ip") != null)
            {
                account.IP = doc.SelectSingleNode("accountObject/ip").InnerText;
            }

            return(account);
        }
コード例 #4
0
        /// <summary></summary>
        /// <param name="accountIdentity"></param>
        /// <returns></returns>
        public AccountCacheInfo Read(string accountIdentity)
        {
            // 过滤空值
            if (string.IsNullOrEmpty(accountIdentity))
            {
                return(null);
            }

            if (this.cacheStorage.ContainsKey(accountIdentity))
            {
                return(this.cacheStorage[accountIdentity]);
            }
            else
            {
                AccountCacheInfo accountCacheInfo = this.FindByAccountIdentity(accountIdentity);

                if (accountCacheInfo != null && !this.cacheStorage.ContainsKey(accountIdentity))
                {
                    this.cacheStorage.Add(accountIdentity, accountCacheInfo);
                }

                return(accountCacheInfo);
            }
        }
        public void TestInsert()
        {
            AccountCacheInfo param = new AccountCacheInfo();

            param.AccountIdentity = "test_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");

            param.AccountCacheValue = "test";

            param.AccountObject = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<accountObject><id>fbe67a6e-4c6c-439e-b54b-f62af23d30ba</id><loginName>jiqiliang</loginName><name>吉其亮</name><ip>127.0.0.1</ip></accountObject>";

            param.AccountObjectType = "X3Platform.Membership.Model.AccountInfo,X3Platform.Membership";

            param.IP = "255.255.255.255";

            param.ValidFrom = param.ValidTo = DateTime.Now;

            param.Date = DateTime.Now;

            SessionContext.Instance.AccountCacheService.Insert(param);

            AccountCacheInfo result = SessionContext.Instance.AccountCacheService.FindByAccountIdentity(param.AccountIdentity);

            Assert.IsTrue(param.AccountIdentity == result.AccountIdentity);
        }
コード例 #6
0
        /// <summary>修改记录</summary>
        /// <param name="param">实例<see cref="AccountCacheInfo"/>的详细信息</param>
        public void Update(AccountCacheInfo param)
        {
            IStorageNode storageNode = storageStrategy.GetStorageNode("Query");

            this.ibatisMappers[storageNode.Name].Update(StringHelper.ToProcedurePrefix(string.Format("{0}_Update", tableName)), param);
        }
コード例 #7
0
        /// <summary>获取当前帐号缓存信息</summary>
        /// <param name="strategy">帐号存储策略</param>
        public IAccountInfo GetAuthAccount(IAccountStorageStrategy strategy, string accountIdentity)
        {
            AccountCacheInfo param = this.Read(accountIdentity);

            return(strategy.Deserialize(param));
        }
コード例 #8
0
 ///<summary>修改记录</summary>
 ///<param name="param">实例<see cref="AccountCacheInfo"/>的详细信息</param>
 public void Update(AccountCacheInfo param)
 {
     this.provider.Update(param);
 }
コード例 #9
0
 ///<summary>添加记录</summary>
 ///<param name="param">实例<see cref="AccountCacheInfo"/>的详细信息</param>
 public void Insert(AccountCacheInfo param)
 {
     this.provider.Insert(param);
 }