/// <summary> /// Produces an IDescriptiveNotificationFrequency corresponding to the value of the 'type' /// parameter /// </summary> /// <param name="type"> /// String identifying which implementation of /// IDescriptiveNotificationFrequency to produce and return. /// </param> /// <param name="customPeriod"> /// A custom time interval to initialize a CustomNotificationFrequency with, if the /// 'type' requested is "Custom" /// </param> /// <returns> /// An implementation of IDescriptiveNotificationFrequency corresponding to the 'type' /// parameter, and initialize with the 'customPeriod' parameter if the value of 'type' is /// "Custom". null is returned if the 'type' parameter value does not describe a pre-defined /// type /// </returns> public static INotificationFrequency New(NotificationFrequencyType type, TimeSpan customPeriod = new TimeSpan()) { //TODO: protect against invalid customPeriod switch (type) { case NotificationFrequencyType.Daily: return(new DailyNotificationFrequency()); case NotificationFrequencyType.AlternateDay: return(new AlternateDayNotificationFrequency()); case NotificationFrequencyType.Review: return(new ReviewNotificationFrequency()); case NotificationFrequencyType.Custom: return(new CustomNotificationFrequency(customPeriod)); default: return(null); } }
/// <summary> /// Extracts TaskItem input data from a IAddTaskView and creates a new TaskItem for the /// application. /// </summary> /// <param name="view"> /// Where new TaskItem info was inputted /// </param> public void CreateTask(IAddTaskView view) { //map the view's notification frequency type string to an enum value NotificationFrequencyType notificationFrequencyType = frequenctTypeStrMap.Where(x => x.Value == view.FrequencyType).First().Key; //create input for use-case from data of the view CreateTaskInput input = new CreateTaskInput { Title = view.Title, Description = view.Description, StartTime = view.StartTime, R = view.Color.R, G = view.Color.G, B = view.Color.B, NotificationFrequencyType = notificationFrequencyType, CustomNotificationFrequency = view.CustomFrequency }; //create UseCase instance and assign input structure to its input port var uc = taskSchedulerApplication.NewCreateTaskUseCase(); //run the use case CreateTaskOutput output = uc.Execute(input); if (output.Success) { //get the taskItemDTO returned creatd by the executed usecase TaskItemDTO taskDTO = output.TaskItemDTO; //get a string representation of the taskDTO's notification frequency type string frequencyTypeStr = frequenctTypeStrMap[taskDTO.NotificationFrequencyType]; //convert the taskDTO's rgb color to a Windows brush SolidColorBrush colorBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(255, taskDTO.R, taskDTO.G, taskDTO.B)); //create task item model from taskDTO TaskItemModel newTaskItemModel = new TaskItemModel() { Id = taskDTO.Id, Title = taskDTO.Title, Description = taskDTO.Description, StartTime = taskDTO.StartTime, FrequencyType = frequencyTypeStr, NotificationFrequency = taskDTO.CustomNotificationFrequency, Color = colorBrush }; //fire the TaskCreated event OnTaskCreated(newTaskItemModel); //clear the views input fields and close it view.ClearFields(); view.CloseSelf(); } else { //transfer the use-cases error to the view view.ApplicationErrorMessage = output.Error; view.ApplicationError = true; } }