Esempio n. 1
0
        private static ApplicationDateModel GetApplicationDates()
        {
            int officeId = CurrentSession.GetOfficeId();
            Collection <ApplicationDateModel> applicationDates = ApplicationStateHelper.GetApplicationDates();
            bool persist = false;

            if (applicationDates == null || applicationDates.Count.Equals(0))
            {
                applicationDates = Data.Frequency.GetApplicationDates();
                persist          = true;
            }
            else
            {
                for (int i = 0; i < applicationDates.Count; i++)
                {
                    if (applicationDates[i].NewDayStarted)
                    {
                        int modelOfficeId = applicationDates[i].OfficeId;

                        applicationDates.Remove(applicationDates[i]);
                        applicationDates.Add(Data.Frequency.GetApplicationDates(modelOfficeId));
                        persist = true;
                    }
                }
            }

            if (persist)
            {
                ApplicationStateHelper.SetApplicationDates(applicationDates);
            }

            return(applicationDates.FirstOrDefault(c => c.OfficeId.Equals(officeId)));
        }
        public static void Update <T>(PerformanceMode performanceMode, string performanceKey, T value, Delegate func, params object[] args)
        {
            switch (performanceMode)
            {
            case PerformanceMode.ApplicationState:
                ApplicationStateHelper.SetOrUpdate <T>(performanceKey, value);
                break;

            case PerformanceMode.Cache:
                CacheHelper.SetOrUpdate <T>(performanceKey, value);
                break;

            //case PerformanceMode.MemoryCache:
            //    MemoryCacheHelper.SetOrUpdate<T>(performanceKey, value);
            //    break;
            case PerformanceMode.Session:
                SessionHelper.SetOrUpdate <T>(performanceKey, value);
                break;

            //  case PerformanceMode.Redis:
            //  return RedisCacheHelper.Change<T>(performanceKey, value);
            //  break;
            case PerformanceMode.None:
                func.DynamicInvoke(args);
                break;
            }
        }
        private void SuggestDateReload()
        {
            int officeId = CurrentSession.GetOfficeId();
            Collection <ApplicationDateModel> applicationDates = ApplicationStateHelper.GetApplicationDates();

            if (applicationDates != null)
            {
                ApplicationDateModel model = applicationDates.FirstOrDefault(c => c.OfficeId.Equals(officeId));
                if (model != null)
                {
                    applicationDates.Add(new ApplicationDateModel(model.OfficeId, model.Today, model.MonthStartDate, model.MonthEndDate, model.QuarterStartDate, model.QuarterEndDate, model.FiscalHalfStartDate, model.FiscalHalfEndDate, model.FiscalYearStartDate, model.FiscalYearEndDate, true));
                    applicationDates.Remove(model);

                    ApplicationStateHelper.SetApplicationDates(applicationDates);
                }
            }
        }
        private void ForceLogOff(int officeId)
        {
            Collection <ApplicationDateModel> applicationDates = ApplicationStateHelper.GetApplicationDates();
            DateTime forcedLogOffOn = DateTime.Now.AddMinutes(2);

            if (applicationDates != null)
            {
                ApplicationDateModel model = applicationDates.FirstOrDefault(c => c.OfficeId.Equals(officeId));

                if (model != null)
                {
                    applicationDates.Add(new ApplicationDateModel(model.OfficeId, model.Today, model.MonthStartDate, model.MonthEndDate, model.QuarterStartDate, model.QuarterEndDate, model.FiscalHalfStartDate, model.FiscalHalfEndDate, model.FiscalYearStartDate, model.FiscalYearEndDate, false, forcedLogOffOn));
                    applicationDates.Remove(model);

                    ApplicationStateHelper.SetApplicationDates(applicationDates);
                }
            }
        }
        public static void ClearPerformance(string performanceKey, PerformanceMode performanceMode)
        {
            switch (performanceMode)
            {
            case PerformanceMode.ApplicationState:
                if (ApplicationStateHelper.Exists(performanceKey))
                {
                    ApplicationStateHelper.Clear(performanceKey);
                }
                break;

            case PerformanceMode.Cache:
                if (CacheHelper.Exists(performanceKey))
                {
                    CacheHelper.Clear(performanceKey);
                }
                break;

            //case PerformanceMode.MemoryCache:
            //    if (MemoryCacheHelper.Exists(performanceKey))
            //    {
            //        MemoryCacheHelper.Clear(performanceKey);
            //    }
            //    break;

            case PerformanceMode.Session:
                if (SessionHelper.Exists(performanceKey))
                {
                    SessionHelper.Clear(performanceKey);
                }
                break;

            case PerformanceMode.Redis:
            //if (RedisCacheHelper.Exists(performanceKey))
            //{
            //    RedisCacheHelper.Clear(performanceKey);
            //}
            //break;

            case PerformanceMode.None:
                break;
            }
        }
Esempio n. 6
0
        private void ForceLogOff()
        {
            int officeId = SessionHelper.GetOfficeId();
            Collection <ApplicationDateModel> applicationDates = ApplicationStateHelper.GetApplicationDates();

            if (applicationDates != null)
            {
                ApplicationDateModel model = applicationDates.FirstOrDefault(c => c.OfficeId.Equals(officeId));
                if (model != null)
                {
                    if (model.ForcedLogOffTimestamp != null)
                    {
                        if (model.ForcedLogOffTimestamp <= DateTime.Now && model.ForcedLogOffTimestamp >= SessionHelper.GetSignInTimestamp())
                        {
                            RequestLogOnPage();
                        }
                    }
                }
            }
        }
        public static T SetOrGet <T>(string performanceKey, T value)
        {
            switch (AppConfig.PerformanceMode)
            {
            case PerformanceMode.ApplicationState:
                return(ApplicationStateHelper.SetOrGet <T>(performanceKey, value));

            case PerformanceMode.Cache:
                return(CacheHelper.SetOrGet <T>(performanceKey, value));

            //case PerformanceMode.MemoryCache:
            //    return MemoryCacheHelper.SetOrGet<T>(performanceKey, value);

            case PerformanceMode.Session:
                return(SessionHelper.SetOrGet <T>(performanceKey, value));

                //  case PerformanceMode.Redis:
                //  return RedisCacheHelper.SetOrGet<T>(performanceKey, value);
            }

            return(value);
        }
        public static void GetPerformance <T>(PerformanceMode performanceMode, string performanceKey, out T keyValue, Delegate func, params object[] args)
        {
            keyValue = default(T);

            switch (performanceMode)
            {
            case PerformanceMode.ApplicationState:
                if (ApplicationStateHelper.Exists(performanceKey))
                {
                    ApplicationStateHelper.Get <T>(performanceKey, out keyValue);
                }
                else
                {
                    keyValue = (T)func.DynamicInvoke(args);
                    ApplicationStateHelper.Add <T>(performanceKey, keyValue);
                }
                break;

            case PerformanceMode.Cache:
                if (CacheHelper.Exists(performanceKey))
                {
                    CacheHelper.Get <T>(performanceKey, out keyValue);
                }
                else
                {
                    keyValue = (T)func.DynamicInvoke(args);
                    CacheHelper.Add <T>(performanceKey, keyValue);
                }
                break;

            //case PerformanceMode.MemoryCache:
            //    if (MemoryCacheHelper.Exists(performanceKey))
            //    {
            //        MemoryCacheHelper.Get<T>(performanceKey, out keyValue);
            //    }
            //    else
            //    {
            //        keyValue = (T)func.DynamicInvoke(args);
            //        MemoryCacheHelper.Add<T>(performanceKey, keyValue);
            //    }
            //    break;

            case PerformanceMode.Session:
                if (SessionHelper.Exists(performanceKey))
                {
                    SessionHelper.Get <T>(performanceKey, out keyValue);
                }
                else
                {
                    keyValue = (T)func.DynamicInvoke(args);
                    SessionHelper.Add <T>(performanceKey, keyValue);
                }
                break;

            case PerformanceMode.Redis:
                //if (RedisCacheHelper.Exists(performanceKey))
                //{
                // //   RedisCacheHelper.Get<T>(performanceKey, out keyValue);
                //}
                //else
                //{
                //   // keyValue = (T)func.DynamicInvoke(args);
                //  //  RedisCacheHelper.Add<T>(performanceKey, keyValue);
                //}
                break;

            case PerformanceMode.None:
                keyValue = (T)func.DynamicInvoke(args);
                break;
            }
        }