protected Token GetApiToken()
        {
            var token = (from t in dbContext.Set <Token>()
                         where t.OpenId == aLCTConfiguration.EnterpriseCode && t.ExpiryDate < DateTime.Now
                         orderby t.Id descending
                         select t).FirstOrDefault();

            if (token == null)
            {
                var response = authenticationAgent.DoApiLogin(new ALCTApiLoginRequest()
                {
                    EnterpriseCode     = aLCTConfiguration.EnterpriseCode,
                    EnterpriseIdentity = aLCTConfiguration.AppIdentity,
                    EnterpriseKey      = aLCTConfiguration.AppKey
                });

                if (response != null)
                {
                    token = response.ToToken(aLCTConfiguration.EnterpriseCode);
                    using (var transaction = dbContext.Database.BeginTransaction())
                    {
                        var expiredTokens = (from t in dbContext.Set <Token>() where t.OpenId == aLCTConfiguration.EnterpriseCode select t).ToList();
                        dbContext.RemoveRange(expiredTokens);
                        dbContext.Add(token);
                        transaction.Commit();
                    }
                }
            }
            return(token);
        }
Example #2
0
        public ALCTConfiguration GetALCTConfiguration()
        {
            if (aLCTConfiguration != null)
            {
                return(aLCTConfiguration);
            }

            var config = dbContext.Set <SystemConfig>().Where(x => x.Key == "ALCTConfiguration").FirstOrDefault();

            if (config != null)
            {
                aLCTConfiguration = JsonConvert.DeserializeObject <ALCTConfiguration>(config.Value);
            }
            else
            {
                logger.LogError("ALCT configuration is not configed in database");
                aLCTConfiguration = new ALCTConfiguration();
            }

            return(aLCTConfiguration);
        }