public void InitializeDomainFromDatabase( ITaskItemRepositoryFactory taskItemRepositoryFactory, INotificationManager notificationManager, ITaskManager taskManager, IClock clock) { /* * hook up to notfication added event now, so to retrieve new notifications generated by * the TaskItems being created below */ notificationManager.NotificationAdded += OnNotificationAdded; /* * read in task items from database. Create domain taskItems from * data and add items to taskManager */ ITaskItemRepository taskItemRepository = taskItemRepositoryFactory.New(); foreach (TaskItemDAL task in taskItemRepository.GetAll()) { INotificationFrequency notificationFrequency = null; if (task.customNotificationFrequency.HasValue) { CustomNotificationFrequencyDAL frequencyDAL = task.customNotificationFrequency.Value; notificationFrequency = NotificationFrequencyFactory.New( //TODO: do something safer than just a cast (NotificationFrequencyType)task.notificationFrequencyType, frequencyDAL.time ); } else { notificationFrequency = NotificationFrequencyFactory.New( //TODO: do something safer than just a cast (NotificationFrequencyType)task.notificationFrequencyType ); } taskManager.Add( new TaskItem( task.title, task.description, new Colour(task.r, task.g, task.b), task.startTime, notificationManager, notificationFrequency, clock, task.lastNotificationTime, task.id ) ); } }
/// <summary> /// Converts the fields of the CreateTaskUseCase's Input property to a TaskItem and returns /// it /// </summary> /// <returns> /// TaskItem created with the data contained in the CreateTaskUseCase's Input property /// </returns> private TaskItem InputToTaskItem(CreateTaskInput input) { INotificationFrequency frequency = NotificationFrequencyFactory.New(input.NotificationFrequencyType, input.CustomNotificationFrequency); return(new TaskItem( input.Title, input.Description, new task_scheduler_entities.Colour( input.R, input.G, input.B ), input.StartTime, notificationManager, frequency, clock )); }