/// <summary> /// The get or create. /// </summary> /// <param name="dateInfo"> /// The date info. /// </param> /// <returns> /// The <see cref="DateVm"/>. /// </returns> public DateVm GetOrCreate(DateInfoModel dateInfo) { DateVm result = this.dateVmCollection.FirstOrDefault(dateVm => dateVm.IsDateEqual(dateInfo)); if (this.dateVmCollection.Count > CacheSize) { this.dateVmCollection.RemoveRange(0, this.dateVmCollection.Count - CacheSize); } if (result != null) { return(result); } switch (dateInfo.DateType) { case DateRepresentationType.Year: { result = new YearVm(dateInfo, this, this.taskMediator); break; } case DateRepresentationType.Month: { result = new MonthVm(dateInfo, this, this.taskMediator); break; } case DateRepresentationType.Week: { result = new WeekVm(dateInfo, this, this.taskMediator); break; } case DateRepresentationType.Day: { result = new DayVm(dateInfo, this, this.taskMediator); break; } case DateRepresentationType.Hour: { result = new HourVm(dateInfo, this, this.taskMediator); break; } default: { return(null); } } this.dateVmCollection.Add(result); return(result); }
/// <summary> /// The register child. /// </summary> /// <param name="childDate"> /// The child date. /// </param> protected virtual void RegisterChild(DateInfoModel childDate) { DateVm child = this.factory.Create(childDate, this.factory, this.taskMediator); child.NewVmNeeded += this.OnNewVmNeeded; child.TaskAdded += (sender, task) => { this.OnTaskAdded(this, task); this.OnTaskAdded(sender, task); }; child.TaskRemoved += (sender, task) => { this.OnTaskRemoved(this, task); this.OnTaskRemoved(sender, task); }; this.children.Add(child); this.OnPropertyChanged("Children"); }