コード例 #1
0
ファイル: AVRFacade.cs プロジェクト: EIDSS/EIDSS6.1.0.45
 public bool DoesCachedQueryExists(long queryId, string lang, bool isArchive)
 {
     try
     {
         TraceMethodCall(queryId, AvrDbHelper.GetQueryNameForLog(queryId), lang);
         var  cacheKey = new QueryCacheKey(queryId, lang, isArchive);
         long?id       = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);
         return(id.HasValue);
     }
     catch (Exception ex)
     {
         m_Trace.TraceMethodException(ex, Utils.GetCurrentMethodName(), m_TraceTitle);
         string format = EidssMessages.Get("msgCouldNotGetQueryCacheExistance",
                                           "Could not define does query cache exists for Query ID={0}.");
         throw new AvrDataException(String.Format(format, queryId), ex);
     }
 }
コード例 #2
0
ファイル: AVRFacade.cs プロジェクト: EIDSS/EIDSS6.1.0.45
        private QueryTableHeaderDTO GetInternalCachedQueryTableHeader(long queryId, bool isSchedulerCall, string lang, bool isArchive)
        {
            try
            {
                string    queryName = AvrDbHelper.GetQueryNameForLog(queryId);
                Stopwatch watch     = TraceMethodCall(queryId, queryName, lang, isArchive);

                EidssAvrServiceInitializer.CheckAndInitEidssCore();

                var cacheKey = new QueryCacheKey(queryId, lang, isArchive);

                long?id = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);

                if (!id.HasValue)
                {
                    bool needExecute;
                    lock (m_CacheSyncLock)
                    {
                        needExecute = !m_QueryCacheList.Contains(cacheKey);
                        if (needExecute)
                        {
                            m_QueryCacheList.Add(cacheKey);
                            if (!m_QueryCacheSyncLock.ContainsKey(cacheKey))
                            {
                                m_QueryCacheSyncLock.Add(cacheKey, new object());
                            }
                            if (!m_QueryCacheErrors.ContainsKey(cacheKey))
                            {
                                m_QueryCacheErrors.Add(cacheKey, false);
                            }
                        }
                    }
                    lock (m_QueryCacheSyncLock[cacheKey])
                    {
                        try
                        {
                            if (needExecute)
                            {
                                try
                                {
                                    id = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);
                                    if (!id.HasValue)
                                    {
                                        QueryTableModel tableModel = AvrDbHelper.GetQueryResult(queryId, lang, isArchive);
                                        id = AvrDbHelper.SaveQueryCache(tableModel);
                                    }
                                }
                                finally
                                {
                                    lock (m_CacheSyncLock)
                                    {
                                        m_QueryCacheErrors[cacheKey] = !id.HasValue;
                                        m_QueryCacheList.Remove(cacheKey);
                                    }
                                }
                            }
                            else
                            {
                                while (true)
                                {
                                    lock (m_CacheSyncLock)
                                    {
                                        if (!m_QueryCacheList.Contains(cacheKey))
                                        {
                                            break;
                                        }
                                    }

                                    Monitor.Wait(m_QueryCacheSyncLock[cacheKey]);
                                }
                                lock (m_CacheSyncLock)
                                {
                                    if (m_QueryCacheErrors[cacheKey])
                                    {
                                        string message = EidssMessages.Get("msgCouldNotGetQueryCacheHeaderGeneral",
                                                                           "Could not get header of query cashe table. For detail see previous exception logged");
                                        throw new AvrDataException(message);
                                    }
                                }
                                id = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays, true);
                            }
                        }
                        finally
                        {
                            Monitor.PulseAll(m_QueryCacheSyncLock[cacheKey]);
                        }
                    }
                }
                if (!id.HasValue)
                {
                    string msg = EidssMessages.Get("msgCouldNotGetQueryCacheId", "Could not get query cashe ID. See log for more details.");
                    throw new AvrDataException(msg);
                }

                QueryTableHeaderDTO header = AvrDbHelper.GetQueryCacheHeader(id.Value, isSchedulerCall, isArchive);
                TraceMethodCallFinished(watch, queryId, queryName, lang, isArchive);
                return(header);
            }
            catch (Exception ex)
            {
                m_Trace.TraceMethodException(ex, Utils.GetCurrentMethodName(), m_TraceTitle, queryId, lang);
                string format = EidssMessages.Get("msgCouldNotGetQueryCacheHeader",
                                                  "Could not get header of query cashe table. Query ID={0}, Language={1}");
                throw new AvrDataException(String.Format(format, queryId, lang), ex);
            }
        }
コード例 #3
0
ファイル: AVRFacade.cs プロジェクト: EIDSS/EIDSS6.1.0.45
        public ViewDTO GetCachedView(string sessionId, long layoutId, string lang)
        {
            try
            {
                m_ViewSemaphore.Wait();

                var       layout = AvrDbHelper.GetLayoutDTO(layoutId);
                Stopwatch watch  = TraceMethodCall(sessionId, layoutId, layout.DefaultLayoutName, lang);
                EidssAvrServiceInitializer.CheckAndInitEidssCore();

                ViewDTO view         = null;
                var     cacheKey     = new QueryCacheKey(layout.QueryId, lang, layout.UseArchivedData);
                long?   queryCacheId = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);
                if (queryCacheId.HasValue)
                {
                    var viewCacheId = AvrDbHelper.GetViewCacheId(queryCacheId.Value, layoutId, RefreshedCacheOnUserCallAfterDays);
                    if (viewCacheId.HasValue)
                    {
                        view = AvrDbHelper.GetViewCache(viewCacheId.Value, false);
                    }
                }

                if (view == null)
                {
                    AvrPivotViewModel model = VirtualPivot.CreateAvrPivotViewModel(layoutId, lang, m_Container);

                    string xmlViewHeader    = AvrViewSerializer.Serialize(model.ViewHeader);
                    byte[] zippedViewHeader = BinaryCompressor.ZipString(xmlViewHeader);

                    BaseTableDTO serializedDTO = BinarySerializer.SerializeFromTable(model.ViewData);
                    BaseTableDTO zippedDTO     = BinaryCompressor.Zip(serializedDTO);

                    view = new ViewDTO(zippedDTO, zippedViewHeader);

                    queryCacheId = AvrDbHelper.GetQueryCacheId(cacheKey, RefreshedCacheOnUserCallAfterDays);
                    if (queryCacheId.HasValue)
                    {
                        AvrDbHelper.SaveViewCache(queryCacheId.Value, layoutId, view);
                    }
                }
                TraceMethodCallFinished(watch, sessionId, layoutId, layout.DefaultLayoutName, lang);
                return(view);
            }
            catch (OutOfMemoryException ex)
            {
                m_Trace.TraceMethodException(ex, Utils.GetCurrentMethodName(), m_TraceTitle, sessionId, layoutId, lang);
                throw new AvrDataException(EidssMessages.Get("ErrAVROutOfMemory"), ex);
            }
            catch (Exception ex)
            {
                m_Trace.TraceMethodException(ex, Utils.GetCurrentMethodName(), m_TraceTitle, sessionId, layoutId, lang);
                string format = EidssMessages.Get("msgCouldNotGetViewData",
                                                  "Could not get View Data from Layout. LayoutID={0}, Lang={1}, SessionId={2}");
                string msg = String.Format(format, layoutId, lang, sessionId);
                throw new AvrDataException(msg, ex);
            }
            finally
            {
                m_ViewSemaphore.Release();
            }
        }