Example #1
0
 /// <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;
 }
Example #2
0
        /// <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);
        }