public Scheduler(IExchangeApi exchangeApi, MessageDispatcher messageispatcher, Enumerations.SchedulerType schedulerType, int schedulerValueInSeconds, int candlePeriodInSeconds, Dictionary <Coin, Coin> coins, Logger logger) { _exchangeApi = exchangeApi; _messageispatcher = messageispatcher; _schedulerValueInSeconds = schedulerValueInSeconds; _coins = coins; _logger = logger; _schedulerType = schedulerType; _candlePeriodInSeconds = candlePeriodInSeconds; }
internal TimeSpan GetTimeSpanToSleepFor(Enumerations.SchedulerType schedulerType, int schedulerValueInSeconds) { switch (schedulerType) { case Enumerations.SchedulerType.ScheduledEventOccursEveryValueInSecondsPastTheHour: { var currentDateTimePlusOneHour = DateTime.UtcNow.AddHours(1); var theNextDateTimeToRunAt = new DateTime(currentDateTimePlusOneHour.Year, currentDateTimePlusOneHour.Month, currentDateTimePlusOneHour.Day, currentDateTimePlusOneHour.Hour, 0, 0).AddSeconds( schedulerValueInSeconds).ToUniversalTime(); return(theNextDateTimeToRunAt.Subtract(DateTime.UtcNow)); } case Enumerations.SchedulerType.ScheduledEventOccursOnceDailyValueInSecondsPastMidnight: { var currentDateTimePlusOneDay = DateTime.UtcNow.AddDays(1); var theNextDateTimeToRunAt = new DateTime(currentDateTimePlusOneDay.Year, currentDateTimePlusOneDay.Month, currentDateTimePlusOneDay.Day, 0, 0, 0).AddSeconds( schedulerValueInSeconds).ToUniversalTime(); return(theNextDateTimeToRunAt.Subtract(DateTime.UtcNow)); } case Enumerations.SchedulerType.ScheduledEventOccursEveryValueInSeconds: { var theNextDateTimeToRunAt = new DateTime(DateTime.UtcNow.AddMinutes(1).Year, DateTime.UtcNow.AddMinutes(1).Month, DateTime.UtcNow.AddMinutes(1).Day, DateTime.UtcNow.AddMinutes(1).Hour, 0, 0); return(theNextDateTimeToRunAt.Subtract(DateTime.UtcNow)); } default: { return(TimeSpan.FromSeconds(schedulerValueInSeconds)); } } }