private TimeSpan Fit(TimeTaskContext task, TimeSpan timeLeft, double sumPriority) { // Calculate how much overall time should it take based on priorities var timePart = GetRealPriority(task) / sumPriority; // Calculate and assign time to task return(TimeSpan.FromSeconds(Math.Ceiling(new TimeSpan((long)(timeLeft.Ticks * timePart)).TotalSeconds))); }
/// <summary> /// Removes single specified task from the database /// </summary> /// <param name="context">The task to delete</param> public void RemoveTask(TimeTaskContext context) { // Prepare an one element list with provided task's id var list = new List <int> { context.Id }; // Send it to the repository to delete this task mTimeTasksRepository.RemoveTasks(list); }
/// <summary> /// Saves new task to the database and adds it to the application's task list /// </summary> /// <param name="context">The context of a task to add</param> public void SaveTask(TimeTaskContext context) { // Initialize remaining data based on task's type InitializeTaskWithType(context); // Map it to the entity var entity = mTimeTasksMapper.ReverseMap(context); // Save it into database mTimeTasksRepository.SaveTask(entity); }
/// <summary> /// Starts new task in current session /// </summary> /// <param name="context">The task context to start</param> private void StartNextTask(TimeTaskContext context) { // Set provided time CurrentTimeLeft = context.SessionDynamicTime; // Save it for progress calculations mCurrentTask.SessionDynamicTime = CurrentTimeLeft; // Start the timer mSecondsTicker.Start(); // Inform subscribers TaskStarted.Invoke(); }
/// <summary> /// Send new tasks to session /// </summary> public void UpdateTasks(List <TimeTaskContext> tasks) { if (mSettingsProvider.HighestPrioritySetAsFirst) { // Sort descending priority if such setting is enabled tasks = tasks.OrderByDescending(x => x.Priority).ToList(); } mUserTasks = new HeadList <TimeTaskContext>(tasks); mCurrentTask = mUserTasks.Head; // Check if task list is properly set ValidateTasks(); }
/// <summary> /// Initializes provided task with type-specific data that should be configured here /// </summary> /// <param name="task">The context of task</param> private void InitializeTaskWithType(TimeTaskContext task) { // Based on task's type... switch (task.Type) { // Generic tasks case TimeTaskType.Generic: { // Max progress is 100% task.MaxProgress = 100; } break; // Reading tasks case TimeTaskType.Reading: { // Reading a book is always repeatable task.IsImmortal = true; } break; } }
/// <summary> /// Returns dynamic time according to task progress /// </summary> private TimeSpan ShrinkProgressedTask(TimeTaskContext constTask) => (constTask.AssignedTime * (1.0 - constTask.SessionProgress));
/// <summary> /// Returns priority taking progress into account /// </summary> private double GetRealPriority(TimeTaskContext context) => (int)context.Priority * (1.0 - context.SessionProgress);