Exemple #1
0
        public async Task dashBoardCache()
        {
            try
            {
                var dashboarList = await RequestAPI.getAsyncAllDashboards(dashBoards);

                foreach (var dashboardLazy in dashboarList)
                {
                    if (dashboardLazy.disableShow != null)
                    {
                        dashboardLazy.disableShow = dashboardLazy.disableShow.ToLower();
                    }
                    if (dashboardLazy.disableShow == "false" || dashboardLazy.disableShow == null)
                    {
                        var Dashboard = await RequestAPI.getAsyncDashboard(dashBoards + "/" + dashboardLazy.dashboardConfigId);

                        lock (MemoryCaches.memDash)
                        {
                            if (MemoryCaches.memDash.Where(x => x.dashboardId == Dashboard.dashboardConfigId.ToString()).Count() == 0)
                            {
                                MemoryCaches.memDash.Add(new dashMemory
                                {
                                    active      = true,
                                    dashboardId = Dashboard.dashboardConfigId.ToString(),
                                    dashboard   = Dashboard
                                });
                            }
                            else
                            {
                                var cacheItem = MemoryCaches.memDash.Where(x => x.dashboardId == Dashboard.dashboardConfigId.ToString()).FirstOrDefault();
                                var index     = MemoryCaches.memDash.IndexOf(cacheItem);
                                MemoryCaches.memDash[index] = new dashMemory
                                {
                                    active      = cacheItem.active,
                                    dashboardId = Dashboard.dashboardConfigId.ToString(),
                                    dashboard   = Dashboard
                                };
                            }
                        }
                    }
                    else
                    {
                        RequestAPI.DelAsyncCache(cacheURlMain + "/" + dashboardLazy.dashboardConfigId);
                    }
                }
                Logger.Info("------------------Dashboard Cache Updated------------------");
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }
Exemple #2
0
        public async Task DisableUnusedDash()
        {
            List <Task>       tasks = new List <Task>();
            List <dashMemory> localDict;

            lock (MemoryCaches.memDash)
                localDict = new List <dashMemory>(MemoryCaches.memDash);
            foreach (var item in localDict)
            {
                var DashboardId = item.dashboardId;
                var lastRequest = await RequestAPI.getAsyncLastAccessCache(LastAccessURL + "/" + DashboardId);

                TimeSpan dif;
                if (lastRequest != null)
                {
                    dif = DateTime.Now - (DateTime)lastRequest;
                    Logger.Info("->" + item.dashboardId + " : " + item.dashboard.name);
                    Logger.Info("->Tempo desde Ultimo Acesso:" + dif);

                    if (dif.TotalMinutes > MaxTimeCache)
                    {
                        if (item.active == true)
                        {
                            lock (MemoryCaches.memDash)
                            {
                                MemoryCaches.memDash.Where(x => x.dashboardId == item.dashboardId).FirstOrDefault().active = false;
                            }

                            RequestAPI.DelAsyncCache(cacheURlMain + "/" + item.dashboardId);
                        }
                    }
                    else
                    {
                        if (item.active == false)
                        {
                            lock (MemoryCaches.memDash)
                            {
                                MemoryCaches.memDash.Where(x => x.dashboardId == item.dashboardId).FirstOrDefault().active = true;
                            }
                        }
                    }
                }
            }
        }