Exemple #1
0
        /// <summary>
        /// NOTE: Cached.
        /// </summary>
        public IQueryable <OptionBasicInformationCache> GetAllOptionBasicInformation()
        {
            //lock (MemoryCache.OptionBasicInformationCache)
            //{
            if (!MemoryCache.IsOptionBasicInfomationCacheExpired(null))
            {
                // memory cache working
                List <OptionBasicInformation> OptionBasicInformationFromMemoryCache = MemoryCache.OptionBasicInformationCache[MemoryCache.ALL_OPTIONS].OptionBasicInformations;
                return(Mapper.Map <List <OptionBasicInformation>, List <OptionBasicInformationCache> >(OptionBasicInformationFromMemoryCache).AsQueryable());
            }
            else
            {
                DBCacheStatus status;
                IQueryable <OptionBasicInformationCache> result = _databaseCacheService.Get <OptionBasicInformationCache>(out status);
                if (status == DBCacheStatus.Ok)
                {
                    List <OptionBasicInformation> mappedResult = Mapper.Map <List <OptionBasicInformationCache>, List <OptionBasicInformation> >(result.ToList());
                    mappedResult = mappedResult.Select(x => ConvertExpirationDate(x)).ToList();
                    MemoryCache.AddOrUpdateOptionBasicInformationCache(null, mappedResult);
                    return(result);
                }

                // If Cannot get information from DB.
                List <OptionBasicInformation>      info   = GetAllOptionBasicInformationFromLibrary();
                List <OptionBasicInformation>      list   = info.Select(x => ConvertExpirationDate(x)).ToList();
                List <OptionBasicInformationCache> mapped = Mapper.Map <List <OptionBasicInformation>, List <OptionBasicInformationCache> >(list);
                _databaseCacheService.UpdateCache(mapped);
                MemoryCache.AddOrUpdateOptionBasicInformationCache(null, list);
                return(mapped.AsQueryable());
            }
            //}
        }
Exemple #2
0
        /// <summary>
        /// NOTE: Cached.
        /// </summary>
        public EntityResponse <List <OptionBasicInformation> > GetOptionBasicInformation(string underlyingCode = null, string optionNumber = null)
        {
            //lock (MemoryCache.OptionBasicInformationCache)
            //{

            if (!MemoryCache.IsOptionBasicInfomationCacheExpired(underlyingCode))
            {
                // memory cache working.
                var index = underlyingCode == null ? MemoryCache.ALL_OPTIONS : underlyingCode;
                var infos = MemoryCache.OptionBasicInformationCache[index].OptionBasicInformations;
                return(optionNumber == null ? infos : infos.Where(x => x.OptionNumber == optionNumber).ToList());
            }


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

            if (status != DBCacheStatus.Ok)
            {
                EntityResponse <List <OptionBasicInformation> > info = GetAllOptionBasicInformationFromLibrary();
                if (info.IsSuccess)
                {
                    var list = info.Entity.Select(x => ConvertExpirationDate(x)).ToList();
                    List <OptionBasicInformationCache> mapped = Mapper.Map <List <OptionBasicInformation>, List <OptionBasicInformationCache> >(list);
                    _databaseCacheService.UpdateCache(mapped);
                    // Add condition to filter non-affective options.
                    List <OptionBasicInformation> result = list
                                                           .Where(obi => (underlyingCode == null || obi.OptionUnderlyingCode == underlyingCode) &&
                                                                  (optionNumber == null || obi.OptionNumber == optionNumber) &&
                                                                  obi.OptionStatus != " ")
                                                           .ToList();

                    if (optionNumber == null)
                    {
                        MemoryCache.AddOrUpdateOptionBasicInformationCache(underlyingCode, result);
                    }
                    return(result);
                }
                return(info);
            }


            if (underlyingCode != null)
            {
                databaseCache = databaseCache.Where(obi => (obi.OptionUnderlyingCode == underlyingCode && obi.OptionStatus != " "));
            }
            if (optionNumber != null)
            {
                databaseCache = databaseCache.Where(obi => obi.OptionNumber == optionNumber);
            }

            List <OptionBasicInformation> mappedResult = Mapper.Map <List <OptionBasicInformationCache>, List <OptionBasicInformation> >(databaseCache.ToList());

            mappedResult = mappedResult.Select(x => ConvertExpirationDate(x)).ToList();

            if (optionNumber == null)
            {
                MemoryCache.AddOrUpdateOptionBasicInformationCache(underlyingCode, mappedResult);
            }
            return(mappedResult);
            //}
        }