コード例 #1
0
        /// <summary>
        /// Add an existing schedule
        /// </summary>
        /// <param name="schedule"></param>
        public void Add(ContentSchedule schedule)
        {
            if (!_schedule.TryGetValue(schedule.Culture, out var changes))
            {
                changes = new SortedList <DateTime, ContentSchedule>();
                _schedule[schedule.Culture] = changes;
            }

            //TODO: Below will throw if there are duplicate dates added, validate/return bool?
            changes.Add(schedule.Date, schedule);

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, schedule));
        }
コード例 #2
0
 /// <summary>
 /// Remove a scheduled change
 /// </summary>
 /// <param name="change"></param>
 public void Remove(ContentSchedule change)
 {
     if (_schedule.TryGetValue(change.Culture, out var s))
     {
         var removed = s.Remove(change.Date);
         if (removed)
         {
             OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, change));
             if (s.Count == 0)
             {
                 _schedule.Remove(change.Culture);
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Adds a new schedule for a culture
        /// </summary>
        /// <param name="culture"></param>
        /// <param name="releaseDate"></param>
        /// <param name="expireDate"></param>
        /// <returns>true if successfully added, false if validation fails</returns>
        public bool Add(string culture, DateTime?releaseDate, DateTime?expireDate)
        {
            if (culture == null)
            {
                throw new ArgumentNullException(nameof(culture));
            }
            if (releaseDate.HasValue && expireDate.HasValue && releaseDate >= expireDate)
            {
                return(false);
            }

            if (!releaseDate.HasValue && !expireDate.HasValue)
            {
                return(false);
            }

            //TODO: Do we allow passing in a release or expiry date that is before now?

            if (!_schedule.TryGetValue(culture, out var changes))
            {
                changes            = new SortedList <DateTime, ContentSchedule>();
                _schedule[culture] = changes;
            }

            //TODO: Below will throw if there are duplicate dates added, should validate/return bool?
            // but the bool won't indicate which date was in error, maybe have 2 diff methods to schedule start/end?

            if (releaseDate.HasValue)
            {
                var entry = new ContentSchedule(culture, releaseDate.Value, ContentScheduleAction.Release);
                changes.Add(releaseDate.Value, entry);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, entry));
            }

            if (expireDate.HasValue)
            {
                var entry = new ContentSchedule(culture, expireDate.Value, ContentScheduleAction.Expire);
                changes.Add(expireDate.Value, entry);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, entry));
            }

            return(true);
        }
コード例 #4
0
 public bool Equals(ContentSchedule other)
 {
     // don't compare Ids, two ContentSchedule are equal if they are for the same change
     // for the same culture, on the same date - and the collection deals w/duplicates
     return(Culture.InvariantEquals(other.Culture) && Date == other.Date && Action == other.Action);
 }