private void Select(int select)
        {
            if (pastSelect != 0)
            {
                IEnumerator <DayViewModel> iteratorPast = DaysOfMonth.GetEnumerator();
                while (iteratorPast.MoveNext())
                {
                    if (iteratorPast.Current.NumberDayOfWeek == pastSelect)
                    {
                        iteratorPast.Current.ColorBack = (Brush) new BrushConverter().ConvertFromString("LightGoldenrodYellow");
                        break;
                    }
                }
            }
            IEnumerator <DayViewModel> iterator = DaysOfMonth.GetEnumerator();

            while (iterator.MoveNext())
            {
                if (iterator.Current.NumberDayOfWeek == select)
                {
                    iterator.Current.ColorBack = (Brush) new BrushConverter().ConvertFromString("PaleTurquoise");
                    pastSelect = select;
                    break;
                }
            }
        }
Beispiel #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var mask = (DaysOfMonth)parameter;

            _target = (DaysOfMonth)value;
            return((mask & _target) != 0);
        }
Beispiel #3
0
 public CronTemplate(IList <int> seconds, IList <int> minutes, IList <int> hours, IList <int> daysOfMonth, IList <int> months, IList <int> dayOfWeek)
 {
     Seconds.AddRange(seconds);
     Minutes.AddRange(minutes);
     Hours.AddRange(hours);
     DaysOfMonth.AddRange(daysOfMonth);
     Months.AddRange(months);
     DaysOfWeek.AddRange(dayOfWeek);
 }
Beispiel #4
0
        public bool CheckDateTime(DateTime?dateTime = null)
        {
            var time = dateTime ?? DateTime.Now;

            return(Minutes.Contains(time.Minute) &&
                   Hours.Contains(time.Hour) &&
                   Months.Contains(time.Month - 1) &&
                   (DaysOfMonth.Contains(time.Day - 1) || DaysOfWeek.Contains((int)time.DayOfWeek - 1)));
        }
Beispiel #5
0
            public IEnumerable <DateTime> GetScheduledTimes(DateTime start, TimeSpan howFarAhead)
            {
                IEnumerable <DateTime> monthDates;
                var endDate = start + howFarAhead;

                bool IsValid(DateTime dt) => dt >= start && dt <= endDate;

                if (MonthsOfYear.Any())
                {
                    var months = new List <DateTime>();
                    for (var monthDate = start; monthDate < endDate;)
                    {
                        months.Add(monthDate);
                        monthDate = monthDate.AddMonths(1);
                        monthDate = new DateTime(monthDate.Year, monthDate.Month, 1);
                    }
                    monthDates = months.ToArray();
                }
                else
                {
                    monthDates = new[] { start };
                }
                IEnumerable <DateTime> dayDates;

                if (!DaysOfMonth.Any() && !WeekDays.Any())
                {
                    dayDates = new[] { start };
                }
                else
                {
                    dayDates = monthDates.SelectMany(m => DaysOfMonth.Select(d => new DateTime(m.Year, m.Month, d, 0, 0, 0))).Where(IsValid);
                    var dayDates2 = monthDates.SelectMany(m => WeekDays.SelectMany(wd => DayOfWeekDatesForMonth(wd, m.Year, m.Month))).Where(IsValid);
                    if (dayDates.Any() && dayDates2.Any())
                    {
                        dayDates = dayDates.Intersect(dayDates2);
                    }
                    else
                    {
                        dayDates = dayDates.Concat(dayDates2);
                    }
                }

                if (Times.Any())
                {
                    dayDates = dayDates.SelectMany(d => Times.Select(t => new DateTime(d.Year, d.Month, d.Day, t.Hour, t.Minute ?? 0, 0))).Where(IsValid);
                }

                if (Every.HasValue)
                {
                    dayDates = dayDates.SelectMany(d => PartsInValidTime(d, Every.Value)).Where(IsValid);
                }

                return(dayDates);
            }
Beispiel #6
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Seconds != null ? Seconds.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Minutes != null ? Minutes.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Hours != null ? Hours.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DaysOfMonth != null ? DaysOfMonth.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Months != null ? Months.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DaysOfWeek != null ? DaysOfWeek.GetHashCode() : 0);
         return(hashCode);
     }
 }
Beispiel #7
0
        public override async Task <CollectResult> Collect()
        {
            // Determine if this report should run as per this day of the month
            string day        = DateTime.UtcNow.Day.ToString();
            bool   should_run = false;

            if (String.IsNullOrEmpty(DaysOfMonth))
            {
                should_run = true;
            }
            else
            {
                List <string> days = DaysOfMonth.Split(',').ToList();
                should_run = days.Contains(day);
            }

            // Skip out if theres no work to do
            if (!should_run)
            {
                return(new CollectResult(0));
            }

            // Connect to the database and retrieve this value
            DataTable dt = null;

            using (SqlConnection conn = new SqlConnection(this.Device.ConnectionString)) {
                await conn.OpenAsync();

                using (SqlCommand cmd = new SqlCommand(Sql, conn)) {
                    cmd.CommandTimeout = TimeoutSeconds;
                    var dr = await cmd.ExecuteReaderAsync();

                    dt = new DataTable();
                    dt.Load(dr);
                    dr.Close();
                }
                conn.Close();
            }

            // Here's our report
            return(new CollectResult(dt.Rows.Count, dt));
        }
Beispiel #8
0
        public override int GetHashCode()
        {
            unchecked {
                int hash = 17;
                if (Weekdays != default(Weekdays[]))
                {
                    hash = hash * 23 + Weekdays.GetHashCode();
                }
                if (DaysOfMonth != default(int[]))
                {
                    hash = hash * 23 + DaysOfMonth.GetHashCode();
                }
                if (WeekdayOfMonth != default(String))
                {
                    hash = hash * 23 + WeekdayOfMonth.GetHashCode();
                }

                return(hash);
            }
        }
Beispiel #9
0
            public bool IsTime(DateTime currentTime)
            {
                if (MonthsOfYear.Any() && !MonthsOfYear.Any(x => (int)x == currentTime.Month))
                {
                    return(false);
                }
                if (DaysOfMonth.Any() && !DaysOfMonth.Any(x => x == currentTime.Day))
                {
                    return(false);
                }
                if (WeekDays.Any() && !WeekDays.Any(x => x == currentTime.DayOfWeek))
                {
                    return(false);
                }
                if (Times.Any() && !Times.Any(x => x.IsTime(currentTime)))
                {
                    return(false);
                }

                return(true);
            }
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     _target ^= (DaysOfMonth)parameter;
     return _target;
 }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var mask = (DaysOfMonth)parameter;
     _target = (DaysOfMonth)value;
     return ((mask & _target) != 0);
 }
Beispiel #12
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     _target ^= (DaysOfMonth)parameter;
     return(_target);
 }