pszczyg

Untitled

Jun 30th, 2017
289
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public class DateTimeProviderDependentProductionCode
  2.     {
  3.         private readonly IAmActiveMetersLoader _meterLoader;
  4.         private readonly IAmDateTimeProvider _dateTimeProvider;
  5.  
  6.         public DateTimeProviderDependentProductionCode(IAmActiveMetersLoader meterLoader, IAmDateTimeProvider dateTimeProvider)
  7.         {
  8.             _meterLoader = meterLoader;
  9.             _dateTimeProvider = dateTimeProvider;
  10.             TimeForNextPeriodicCheck = _dateTimeProvider.Now.Date.AddHours(22);
  11.         }
  12.  
  13.         public void DoPeriodicCheckIfNeeded()
  14.         {
  15.             var isItTimeForPeriodicCheck = TimeForNextPeriodicCheck < _dateTimeProvider.Now;
  16.             if (!isItTimeForPeriodicCheck)
  17.                 return;
  18.  
  19.             _meterLoader.ReloadAllActiveMeters();
  20.  
  21.             TimeForNextPeriodicCheck = ComputeTimeForNextCheck();
  22.         }
  23.  
  24.         #region Irrelevant
  25.         private DateTime TimeForNextPeriodicCheck { get; set; }
  26.         private static DateTime ComputeTimeForNextCheck()
  27.         {
  28.             return DateTime.Now.AddMinutes(1);
  29.         }
  30.         #endregion Irrelevant
  31.     }
RAW Paste Data