public UserTask CreateUserTask() { UserTask userTask = new UserTask { TaskColor = (string)TaskColor, Id = Id }; if (TaskName == null || TaskName == "") { ValidationMessage = TaskNameValdationMessage; return(null); } userTask.TaskName = TaskName; if (IsHasGoal) { var isPomodoroCountValid = IntergerBoundValidationController.Check(1, 1000, this.PomodoroCount, "Pomodoro Count"); if (!isPomodoroCountValid.result) { ValidationMessage = isPomodoroCountValid.message; return(null); } var taskGoal = new TaskGoal() { GoalInterval = (GoalFrequency)System.Enum.Parse(typeof(GoalFrequency), GoalFrequency), PomodoroCount = PomodoroCount, }; userTask.TaskGoal = taskGoal; } if (IsHaveSettings) { PomodoroSettings pomodoroSettings = new PomodoroSettings(); var isSmallBreakValid = IntergerBoundValidationController.Check(1, 150, this.SmallBreakDuration, "Small Break Duration"); var isLargeBreakDurationValid = IntergerBoundValidationController.Check(1, 150, this.LargeBreakDuration, "Large Break Duration"); var isPomodoroDurationValid = IntergerBoundValidationController.Check(1, 150, this.PomodoroDuration, "Pomodoro Duration"); var isSessionPomodoroCountValid = IntergerBoundValidationController.Check(1, 150, this.SessionPomodoroCount, "Session Pomodoro Count"); if (!isPomodoroDurationValid.result) { ValidationMessage = isPomodoroDurationValid.message; return(null); } if (!isSmallBreakValid.result) { ValidationMessage = isSmallBreakValid.message; return(null); } if (!isLargeBreakDurationValid.result) { ValidationMessage = isLargeBreakDurationValid.message; return(null); } if (!isSessionPomodoroCountValid.result) { ValidationMessage = isSessionPomodoroCountValid.message; return(null); } pomodoroSettings.AutoContinue = false; pomodoroSettings.SessionPomodoroCount = SessionPomodoroCount; pomodoroSettings.PomodoroBreakDuration = TimeSpan.FromMinutes(SmallBreakDuration); pomodoroSettings.SessionBreakDuration = TimeSpan.FromMinutes(LargeBreakDuration); pomodoroSettings.PomodoroDuration = TimeSpan.FromMinutes(PomodoroDuration); userTask.PomodoroSettings = pomodoroSettings; } return(userTask); }
/// <summary> /// Reads a line from the streamreader and converts it to a goal(its type dependant on line read) /// </summary> /// <param name="reader">Stream Reader</param> /// <returns>Goal of type</returns> public static Goal ReadGoalType(this StreamReader reader) { Goal result; string readGoalType = reader.ReadLine(); if (readGoalType == "LongTerm") { result = new LongTermGoal("", "", GoalCategory.Career, new List<ShortTermGoal>() ); } else if (readGoalType == "ShortTerm") { result = new ShortTermGoal("", "", GoalCategory.Career, new List<TaskGoal>()); } else if (readGoalType == "Task") { result = new TaskGoal("", "", GoalCategory.Career); } else { result = new TaskGoal("", "", GoalCategory.Career); } return result; }
/// <summary> /// Loads a goal from a stream reacer and attaches it to the profile /// </summary> /// <param name="sr">StreamReader</param> /// <param name="user">Profile</param> private void LoadGoal(StreamReader sr, ref Profile user) { Goal resultGoal = sr.ReadGoalType(); string goalName = sr.ReadLine(); string goalDesc = sr.ReadLine(); GoalCategory goalCate = sr.ReadCategory(); if (resultGoal is LongTermGoal) { LongTermGoal resultLong = new LongTermGoal(goalName, goalDesc, goalCate, new List<ShortTermGoal>()); resultLong.Completed = sr.ReadBool(); resultLong.ExpVal = sr.ReadInteger(); resultLong.EstHours = sr.ReadInteger(); int reqShort = sr.ReadInteger(); for (int i = 0; i < reqShort; i++) { string reqShortName = sr.ReadLine(); foreach (ShortTermGoal sg in user.ShortGoals) { if (sg.Name == reqShortName) { if (!resultLong.ReqShort.Contains(sg)) { resultLong.ReqShort.Add(sg); break; } } } } resultGoal = resultLong; } else if (resultGoal is ShortTermGoal) { ShortTermGoal resultShort = new ShortTermGoal(goalName, goalDesc, goalCate, new List<TaskGoal>()); resultShort.Completed = sr.ReadBool(); resultShort.ExpVal = sr.ReadInteger(); resultShort.EstHours = sr.ReadInteger(); int reqTasks = sr.ReadInteger(); for (int i = 0; i < reqTasks; i++) { string reqTaskName = sr.ReadLine(); foreach (TaskGoal tg in user.Tasks) { if (tg.Name == reqTaskName) { if (!resultShort.ReqTasks.Contains(tg)) { resultShort.ReqTasks.Add(tg); break; } } } } resultGoal = resultShort; } else { resultGoal = new TaskGoal(goalName, goalDesc, goalCate); resultGoal.Completed = sr.ReadBool(); resultGoal.ExpVal = sr.ReadInteger(); resultGoal.EstHours = sr.ReadInteger(); } user.AddGoal(resultGoal); }