コード例 #1
0
        public ElementWrapper[] SelectElements(ElementTypeDefs itemsTypes)
        {
            String cacheItemKey = String.Format("[SelectElements][{0}]", itemsTypes.ToString());

            selectElementsLock.AcquireReaderLock(dataProviderLockTimeout);

            ElementWrapper[] result = null;

            try
            {
                result = (ElementWrapper[])DataCache.Instance.Get(cacheItemKey);

                if (null == result)
                {
                    //////////////////////////////////////////////////////////////////
                    /// no data in cache - need to load it, but first check it again
                    ///

                    LockCookie lockCookie = selectElementsLock.UpgradeToWriterLock(dataProviderLockTimeout);

                    try
                    {
                        result = (ElementWrapper[])DataCache.Instance.Get(cacheItemKey);

                        if (null == result)
                        {
                            Element[] elements = (new ItemsDataProvider()).GetElementsByType(itemsTypes);

                            if (LoggerFactory.AppLogger.IsTraceEnabled)
                            {
                                LoggerFactory.AppLogger.Trace("[DataProviderProxy.SelectElements] Loaded elements " + elements.Length);
                            }

                            result = WrapperUtilities.Convert(elements);

                            DataCache.Instance.Add(cacheItemKey, result);
                        }
                    }
                    finally
                    {
                        selectElementsLock.DowngradeFromWriterLock(ref lockCookie);
                    }
                }
            }
            finally
            {
                selectElementsLock.ReleaseReaderLock();
            }

            return(result);
        }
コード例 #2
0
        public ElementDailyDataRange SelectDailyData(String ticker)
        {
            String cacheItemKey = String.Format("[SelectDailyData][{0}]", ticker);

            selectDailyDataLock.AcquireReaderLock(dataProviderLockTimeout);

            ElementDailyDataRange result = null;

            try
            {
                result = (ElementDailyDataRange)DataCache.Instance.Get(cacheItemKey);

                if (null == result)
                {
                    //////////////////////////////////////////////////////////////////
                    /// no data in cache - need to load it, but first check it again
                    ///

                    LockCookie lockCookie = selectDailyDataLock.UpgradeToWriterLock(dataProviderLockTimeout);

                    try
                    {
                        result = (ElementDailyDataRange)DataCache.Instance.Get(cacheItemKey);

                        if (null == result)
                        {
                            DailyData[] tempRes = (new ItemsDataProvider()).LoadItemDailyData(ticker);

                            if (tempRes.Length > 0)
                            {
                                result = new ElementDailyDataRange(ticker, WrapperUtilities.Convert(tempRes), tempRes[0].Day, tempRes[tempRes.Length - 1].Day);

                                if (LoggerFactory.AppLogger.IsTraceEnabled)
                                {
                                    LoggerFactory.AppLogger.Trace("[DataProviderProxy.SelectDailyData] Loaded records for " + ticker + " " + tempRes.Length + " " + result.DateFrom + " " + result.DateTo);
                                }

                                DataCache.Instance.Add(cacheItemKey, result);
                            }
                            else
                            {
                                LoggerFactory.AppLogger.Warn("[DataProviderProxy.SelectDailyData] No data for " + ticker);

                                result = new ElementDailyDataRange(ticker, EmptyArrayTemplate <DailyDataWrapper> .Instance, DateTime.MaxValue, DateTime.MaxValue);

                                //////////////////////////////////////////////////////
                                /// do not add empty item to cache
                                ///
                            }
                        }
                    }
                    finally
                    {
                        selectDailyDataLock.DowngradeFromWriterLock(ref lockCookie);
                    }
                }
            }
            finally
            {
                selectDailyDataLock.ReleaseReaderLock();
            }

            return(result);
        }