示例#1
0
        /// <summary>
        /// NOTE: Cached.
        /// </summary>
        public EntityResponse <List <SecurityInformation> > GetSecuritiesInformation(StockBoard stockBoard = null, string securityCode = null)
        {
            //lock (MemoryCache.SecurityInformationCache)
            //{

            if (!MemoryCache.IsSecurityInformationCacheExpired(securityCode))
            {
                // memory cache working.
                return(MemoryCache.SecurityInformationCache[securityCode].SecurityInformations);
            }

            DBCacheStatus status;
            IQueryable <SecurityInformationCache> databaseCache = _databaseCacheService.Get <SecurityInformationCache>(out status);

            if (status != DBCacheStatus.Ok)
            {
                EntityResponse <List <SecurityInformation> > info = GetAllSecuritiesInformationFromLibrary();
                if (info.IsSuccess)
                {
                    List <SecurityInformationCache> mapped = Mapper.Map <List <SecurityInformation>, List <SecurityInformationCache> >(info);
                    _databaseCacheService.UpdateCache(mapped);
                    List <SecurityInformation> result = info.Entity.Where(si => (stockBoard == null || si.TradeSector == stockBoard) &&
                                                                          (securityCode == null || si.SecurityCode == securityCode)).ToList();
                    MemoryCache.AddOrUpdateSecurityInformationCache(securityCode, result);
                    return(result);
                }
                return(info);
            }


            if (stockBoard != null)
            {
                string tradeSectorCode = stockBoard.ToString();
                databaseCache = databaseCache.Where(si => si.TradeSector == tradeSectorCode);
            }
            if (securityCode != null)
            {
                databaseCache = databaseCache.Where(si => si.SecurityCode == securityCode);
            }
            List <SecurityInformation> mappedResult = Mapper.Map <List <SecurityInformationCache>, List <SecurityInformation> >(databaseCache.ToList());

            MemoryCache.AddOrUpdateSecurityInformationCache(securityCode, mappedResult);
            return(mappedResult);
            //}
        }