Пример #1
0
        ///<summary>Refresh the cache(s) associated with the given cellType. If waitToReturn==true then block until finished.
        ///If waitToReturn==false then runs async and returns immediately. Optionally wait for the method to return or run async.
        ///onExit event will be fired after async version has completed. Will not fire when sync version is run as this is a blocking call so when it returns it is done.
        ///If invalidateFirst==true then cache will be invalidated and forcefully refreshed. Use this sparingly.</summary>
        public static void RefreshCellTypeIfInvalid(DashboardCellType cellType, DashboardFilter filter, bool waitToReturn, bool invalidateFirst, EventHandler onExit = null)
        {
            //Create a random group name so we can arbitrarily group and wait on the threads we are about to start.
            string groupName = cellType.ToString() + _rand.Next();

            try {
                switch (cellType)
                {
                case DashboardCellType.HQPhone:
                case DashboardCellType.HQConfirmation:
                case DashboardCellType.HQMtMessage:
                case DashboardCellType.HQBillingUsageAccess:
                case DashboardCellType.HQMoMessage:
                case DashboardCellType.HQBillingInboundOutbound:
                case DashboardCellType.HQSignups:
                    //Broadcast monitor does not use the ODGraph cache.
                    return;
                }
                //Always fill certain caches first. These will not be threaded as they need to be available to the threads which will run below.
                //It doesn't hurt to block momentarily here as the queries will run very quickly.
                Providers.Run(new DashboardFilter()
                {
                    UseDateFilter = false
                }, invalidateFirst);
                Clinics.Run(new DashboardFilter()
                {
                    UseDateFilter = false
                }, invalidateFirst);
                //Start certain cache threads depending on which cellType we are interested in. Each cache will have its own thread.
                switch (cellType)
                {
                case DashboardCellType.ProductionGraph:
                    FillCacheThreaded(CompletedProcs, filter, groupName, invalidateFirst);
                    FillCacheThreaded(Writeoffs, filter, groupName, invalidateFirst);
                    FillCacheThreaded(Adjustments, filter, groupName, invalidateFirst);
                    break;

                case DashboardCellType.IncomeGraph:
                    FillCacheThreaded(PaySplits, filter, groupName, invalidateFirst);
                    FillCacheThreaded(ClaimPayments, filter, groupName, invalidateFirst);
                    break;

                case DashboardCellType.AccountsReceivableGraph:
                    FillCacheThreaded(AR, filter, groupName, invalidateFirst);
                    break;

                case DashboardCellType.NewPatientsGraph:
                    FillCacheThreaded(Patients, filter, groupName, invalidateFirst);
                    break;

                case DashboardCellType.BrokenApptGraph:
                    FillCacheThreaded(BrokenAppts, filter, groupName, invalidateFirst);
                    FillCacheThreaded(BrokenProcs, filter, groupName, invalidateFirst);
                    FillCacheThreaded(BrokenAdjs, filter, groupName, invalidateFirst);
                    break;

                case DashboardCellType.NotDefined:
                default:
                    throw new Exception("Unsupported DashboardCellType: " + cellType.ToString());
                }
            }
            finally {
                if (waitToReturn)                  //Block until all threads have completed.
                {
                    ODThread.JoinThreadsByGroupName(System.Threading.Timeout.Infinite, groupName, true);
                }
                else if (onExit != null)                //Exit immediately but fire event later once all threads have completed.
                {
                    ODThread.AddGroupNameExitHandler(groupName, onExit);
                }
            }
        }