Пример #1
0
 public CountdownEventViewModel(Event e, TimeZoneOptions timezoneOptions)
 {
     Subject = e.Subject;
     Start   = (e.IsAllDay ?? false)
         ? DateTime.Parse(e.Start.DateTime)
         : DateTime.Parse(e.Start.DateTime).FromUtcTo(timezoneOptions);
 }
Пример #2
0
        public void Start()
        {
            if (!_options.Running)
            {
                return;
            }

            var timeZone = new TimeZoneOptions(_options.TimeZone).ToTimeZoneInfo();

            foreach (var job in _options.Jobs)
            {
                if (!job.Running)
                {
                    continue;
                }

                var cron = new CronExpression(job.Cron);

                if (!cron.IsValid)
                {
                    _loggerFactory.CreateLogger(GetType().FullName)
                    .LogWarning($"Invalid cron expression for '{job.Name}'.");

                    continue;
                }

                var timer = new JobInterval(cron, timeZone, async() => await RunAsync(job.Name));

                _timers.Add(timer);

                timer.Run();
            }
        }
Пример #3
0
        public void ShouldConvertToLocalTime(string timeZone, string expected)
        {
            var timeZoneOptions = new TimeZoneOptions(timeZone);
            var timeZoneInfo    = timeZoneOptions.ToTimeZoneInfo();
            var localDateTime   = TimeZoneInfo.ConvertTime(_mockUtcTime, timeZoneInfo);
            var iso8601Format   = localDateTime.ToString("yyyy-MM-ddTHH:mm:ss");

            Assert.Equal(expected, iso8601Format);
        }
Пример #4
0
 public CountdownViewModel(
     IOptions <CountdownOptions> options,
     IOptions <TimeZoneOptions> timezoneOptions,
     ICalendarManager calendarManager)
 {
     _options         = options.Value;
     _timezoneOptions = timezoneOptions.Value;
     _calendarManager = calendarManager;
 }
Пример #5
0
 public EventViewModel(Event e, string backgroundColor, string textColor, TimeZoneOptions timezoneOptions)
 {
     // All day events dont need the timezone adjustment
     Subject = e.Subject;
     Start   = (e.IsAllDay ?? false)
         ? DateTime.Parse(e.Start.DateTime)
         : DateTime.Parse(e.Start.DateTime).FromUtcTo(timezoneOptions);
     End = (e.IsAllDay ?? false)
         ? DateTime.Parse(e.End.DateTime)
         : DateTime.Parse(e.End.DateTime).FromUtcTo(timezoneOptions);
     AllDay          = e.IsAllDay ?? false;
     Recurring       = e.Recurrence is not null ? true : false;
     BackgroundColor = backgroundColor;
     TextColor       = textColor;
 }
Пример #6
0
 public static TimeZoneInfo FromTimeZoneOptions(this TimeZoneOptions options)
 {
     // Windows
     if (TryFindSystemTimeZoneById(options.WindowsTimeZoneId, out TimeZoneInfo winTimeZoneInfo))
     {
         return(winTimeZoneInfo);
     }
     // Linux
     else if (TryFindSystemTimeZoneById(options.UnixTimeZoneId, out TimeZoneInfo unixTimeZoneInfo))
     {
         return(unixTimeZoneInfo);
     }
     else
     {
         throw new TimeZoneNotFoundException();
     }
 }
Пример #7
0
 public static DateTime FromUtcTo(this DateTime dateTime, TimeZoneOptions options)
 {
     // Windows
     if (TryFindSystemTimeZoneById(options.WindowsTimeZoneId, out TimeZoneInfo winTimeZoneInfo))
     {
         Debug.WriteLine($"Found time zone '{options.WindowsTimeZoneId}'");
         return(TimeZoneInfo.ConvertTimeFromUtc(dateTime, winTimeZoneInfo));
     }
     // Linux
     else if (TryFindSystemTimeZoneById(options.UnixTimeZoneId, out TimeZoneInfo unixTimeZoneInfo))
     {
         Debug.WriteLine($"Found time zone '{options.UnixTimeZoneId}'");
         return(TimeZoneInfo.ConvertTimeFromUtc(dateTime, unixTimeZoneInfo));
     }
     else
     {
         throw new TimeZoneNotFoundException();
     }
 }
Пример #8
0
        public void Start()
        {
            if (!_options.Running)
            {
                return;
            }

            var timeZone = new TimeZoneOptions(_options.TimeZone).ToTimeZoneInfo();

            foreach (var job in Jobs)
            {
                var config = _options.Jobs.SingleOrDefault(entry => entry.Name == job.Name);

                if (config == null)
                {
                    var logger = _loggerFactory.CreateLogger(job.FullName);
                    logger.LogWarning($"No job configuration matches '{job.Name}'.");

                    continue;
                }

                if (!config.Running)
                {
                    continue;
                }

                var cron = new CronExpression(config.Cron);

                if (!cron.IsValid)
                {
                    var logger = _loggerFactory.CreateLogger(job.FullName);
                    logger.LogWarning($"Invalid cron expression for '{job.Name}'.");

                    continue;
                }

                var timer = new JobInterval(cron, timeZone, async() => await RunAsync(job));

                _timers.Add(timer);

                timer.Run();
            }
        }