Пример #1
0
        /// <summary>
        /// Gets the current data of the specified channels.
        /// </summary>
        public Dto <CurData> GetCurDataStep1(IdList cnlNums, bool useCache)
        {
            try
            {
                // request data
                CheckAccessRights(cnlNums);
                CurData curData = RequestCurData(cnlNums, 0, useCache);

                // write channel list to the cache
                if (useCache && curData.CnlListID != "0")
                {
                    memoryCache.Set(
                        PluginUtils.GetCacheKey("CnlList", curData.CnlListID),
                        cnlNums,
                        new MemoryCacheEntryOptions {
                        SlidingExpiration = WebUtils.CacheExpiration
                    });
                }

                return(Dto <CurData> .Success(curData));
            }
            catch (AccessDeniedException ex)
            {
                return(Dto <CurData> .Fail(ex.Message));
            }
            catch (Exception ex)
            {
                webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(GetCurDataStep1)));
                return(Dto <CurData> .Fail(ex.Message));
            }
        }
Пример #2
0
 /// <summary>
 /// Gets the current data by the channel list ID returned in step 1.
 /// </summary>
 public Dto <CurData> GetCurDataStep2(long cnlListID)
 {
     try
     {
         IdList  cnlNums = memoryCache.Get <IdList>(PluginUtils.GetCacheKey("CnlList", cnlListID));
         CurData curData = RequestCurData(cnlNums, cnlListID, true);
         return(Dto <CurData> .Success(curData));
     }
     catch (Exception ex)
     {
         webContext.Log.WriteError(ex.BuildErrorMessage(WebPhrases.ErrorInWebApi, nameof(GetCurDataStep2)));
         return(Dto <CurData> .Fail(ex.Message));
     }
 }
Пример #3
0
        /// <summary>
        /// Gets the current data by view.
        /// </summary>
        /// <remarks>Loads the specified view if it is not in the cache.</remarks>
        public Dto <CurData> GetCurDataByView(int viewID, long cnlListID)
        {
            try
            {
                if (viewLoader.GetView(viewID, out ViewBase view, out string errMsg))
                {
                    CurData curData = memoryCache.GetOrCreate(PluginUtils.GetCacheKey("CurData", viewID), entry =>
                    {
                        entry.SetAbsoluteExpiration(DataCacheExpiration);
                        return(RequestCurData(view.CnlNumList, cnlListID, true));
                    });

                    return(Dto <CurData> .Success(curData));
                }
                else
                {
                    return(Dto <CurData> .Fail(errMsg));
                }
            }