Example #1
0
        ///<summary>Process all Signals and Acks Since a given DateTime.  Only to be used by OpenDentalWebService.
        ///Returns latest valid signal Date/Time and the list of InvalidTypes that were refreshed.
        ///Can throw exception.</summary>
        public static List <InvalidType> RefreshForWeb()
        {
            InvalidTypeHistory.InitIfNecessary();
            int defaultProcessSigsIntervalInSecs = 7;

            ODException.SwallowAnyException(() => defaultProcessSigsIntervalInSecs = PrefC.GetInt(PrefName.ProcessSigsIntervalInSecs));
            if (DateTime.Now.Subtract(SignalLastRefreshedWeb) <= TimeSpan.FromSeconds(defaultProcessSigsIntervalInSecs))
            {
                return(new List <InvalidType>());
            }
            InvalidType[] arrayInvalidTypes = new InvalidType[0];
            //No need to check RemotingRole; no call to db.
            List <Signalod> listSignals = new List <Signalod>();

            try {
                if (SignalLastRefreshedWeb.Year < 1880)                //First signals for this session so go back in time a bit.
                {
                    SignalLastRefreshedWeb = MiscData.GetNowDateTime().AddSeconds(-1);
                }
                listSignals = Signalods.RefreshTimed(SignalLastRefreshedWeb);
                if (listSignals.Count > 0)                  //Next lower bound is current upper bound.
                {
                    SignalLastRefreshedWeb = listSignals.Max(x => x.SigDateTime);
                }
                arrayInvalidTypes = Signalods.GetInvalidTypesForWeb(listSignals);
                //Get all invalid types since given time and refresh the cache for those given invalid types.
                Cache.Refresh(arrayInvalidTypes);
            }
            catch (Exception e) {
                //Most likely cause for an exception here would be a thread collision between 2 consumers trying to refresh the cache at the exact same instant.
                //There is a chance that performing as subsequent refresh here would cause yet another collision but it's the best we can do without redesigning the entire cache pattern.
                Cache.Refresh(InvalidType.AllLocal);
                //Reset the last signal process time.
                DateTime dateTimeNow = DateTime.Now;
                ODException.SwallowAnyException(() => dateTimeNow = OpenDentBusiness.MiscData.GetNowDateTime());
                SignalLastRefreshedWeb = dateTimeNow;
                throw new Exception("Server cache may be invalid. Please try again. Error: " + e.Message);
            }
            InvalidTypeHistory.UpdateStatus(SignalLastRefreshedWeb, listSignals, arrayInvalidTypes);
            return(arrayInvalidTypes.ToList());
        }
Example #2
0
        ///<summary>Process all Signals and Acks Since a given DateTime.  Only to be used by OpenDentalWebService.
        ///Returns latest valid signal Date/Time and the list of InvalidTypes that were refreshed.
        ///Can throw exception.</summary>
        public static List <InvalidType> RefreshForWeb()
        {
            int defaultProcessSigsIntervalInSecs = 7;

            ODException.SwallowAnyException(() => defaultProcessSigsIntervalInSecs = PrefC.GetInt(PrefName.ProcessSigsIntervalInSecs));
            if (DateTime.Now.Subtract(_signalLastRefreshedWeb) <= TimeSpan.FromSeconds(defaultProcessSigsIntervalInSecs))
            {
                return(new List <InvalidType>());
            }
            InvalidType[] arrayInvalidTypes = new InvalidType[0];
            //No need to check RemotingRole; no call to db.
            try {
                if (_signalLastRefreshedWeb.Year < 1880)
                {
                    _signalLastRefreshedWeb = MiscData.GetNowDateTime();
                }
                arrayInvalidTypes = Signalods.GetInvalidTypesForWeb(Signalods.RefreshTimed(_signalLastRefreshedWeb));
                //Get all invalid types since given time and refresh the cache for those given invalid types.
                Cache.Refresh(arrayInvalidTypes);
            }
            catch (Exception e) {
                //Most likely cause for an exception here would be a thread collision between 2 consumers trying to refresh the cache at the exact same instant.
                //There is a chance that performing as subsequent refresh here would cause yet another collision but it's the best we can do without redesigning the entire cache pattern.
                Cache.Refresh(InvalidType.AllLocal);
                throw new Exception("Server cache may be invalid. Please try again. Error: " + e.Message);
            }
            finally {
                DateTime dateTimeNow = DateTime.Now;
                try {
                    dateTimeNow = OpenDentBusiness.MiscData.GetNowDateTime();
                }
                catch (Exception) { }
                _signalLastRefreshedWeb = dateTimeNow;
            }
            return(arrayInvalidTypes.ToList());
        }