Exemple #1
0
        /// <summary>
        /// 登录FS系统
        /// </summary>
        public FstiToken FSLogin(string username, string password)
        {
            username = username?.Trim();
            password = password?.Trim();
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException("username");
            }
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            string    cackeKey       = FstiToken.GetCacheItemKey(username, password);
            FstiToken tokenCacheItem = _fstiTokenCache.GetOrDefault(cackeKey);    //从缓存获取token

            using (FSTI_GUID fstiService = this.CreateFSTIService())
            {
                if (tokenCacheItem != null)
                {
                    //验证Token是否有效
                    string validateResult = fstiService.logonPool(tokenCacheItem.Token.ToString());
                    if (FstiResultParser.IsLoginTokenValidate(validateResult))
                    {
                        return(tokenCacheItem);
                    }
                    else
                    {
                        _fstiTokenCache.Remove(tokenCacheItem.CacheItemKey);   //移除失效token的缓存
                    }
                }
                return(this.LoginCore(fstiService, username, password));
            }
        }
Exemple #2
0
        /// <summary>
        /// 创建FSTI WebService实例
        /// </summary>
        /// <returns></returns>
        public virtual FSTI_GUID CreateFSTIService()
        {
            FSTI_GUID fsti = new FSTI_GUID();

            fsti.Credentials = new NetworkCredential(this.FSTI_NetUserName, this.FSTI_NetPassword, this.FSTI_NetDomain);
            return(fsti);
        }
Exemple #3
0
 /// <summary>
 /// 注销FS系统
 /// </summary>
 public void FSLogout(Guid fstiToken)
 {
     if (fstiToken != Guid.Empty)
     {
         using (FSTI_GUID fstiService = this.CreateFSTIService())
         {
             //注销ERP登录
             fstiService.logout(fstiToken.ToString());
         }
     }
 }
Exemple #4
0
        protected virtual FstiToken LoginCore(FSTI_GUID fstiService, string username, string password)
        {
            if (fstiService == null)
            {
                throw new ArgumentNullException("fstiService");
            }

            //登录ERP并获得登录GUID
            string loginResult = fstiService.logon(username, password);
            Guid   token       = new Guid(loginResult);

            //更新缓存
            FstiToken cacheItem = new FstiToken(username, password, token);

            _fstiTokenCache.Set(cacheItem.CacheItemKey, cacheItem);
            return(cacheItem);
        }