Ejemplo n.º 1
0
        /// <summary>
        /// Parses the Json string and returns a new User instance populated with all details. On failure, the method returns null.
        /// </summary>
        /// <param name="jsonString"></param>
        /// <returns></returns>
        public static User TryParseData(string jsonString)
        {
            try
            {
                User       user       = GetJsonStringOwner(jsonString);
                JsonObject rootObject = JsonObject.Parse(jsonString);

                ushort    totalCredits = 0;
                JsonArray coursesArray = rootObject.GetNamedArray("courses");
                foreach (JsonValue courseValue in coursesArray)
                {
                    JsonObject courseObj = courseValue.GetObject();
                    Course     course;
                    int        courseType = (int)courseObj.GetNamedNumber("course_type");
                    switch (courseType)
                    {
                    case 1:
                        course = new CBLCourse();
                        break;

                    case 2:
                        course = new LBCCourse();
                        break;

                    case 3:
                        course = new PBLCourse();
                        break;

                    case 4:
                        course = new RBLCourse();
                        break;

                    case 5:
                    case 6:
                        course = new PBCCourse();
                        break;

                    default:
                        continue;
                    }
                    AssignCourseDetails(course, courseObj);
                    user.AddCourse(course);
                    totalCredits += course.Credits;
                }
                user.CoursesMetadata = new CoursesMetadata(
                    rootObject.GetNamedString("semester"), GetRefreshUTC(rootObject.GetNamedString("refreshed")), totalCredits);
                return(user);
            }
            catch
            {
                return(null);
            }
        }
 private static void AssignSpecificDetails(RBLCourse course, JsonObject courseObject)
 {
 }
        /// <summary>
        /// Parses the Json string and returns a new User instance populated with all details. On failure, the method returns null.
        /// </summary>
        /// <param name="jsonString"></param>
        /// <returns></returns>
        public static User TryParseData(string jsonString)
        {
            try
            {
                User user = GetJsonStringOwner(jsonString);
                JsonObject rootObject = JsonObject.Parse(jsonString);

                ushort totalCredits = 0;
                JsonArray coursesArray = rootObject.GetNamedArray("courses");
                foreach (JsonValue courseValue in coursesArray)
                {
                    JsonObject courseObj = courseValue.GetObject();
                    Course course;
                    int courseType = (int)courseObj.GetNamedNumber("course_type");
                    switch (courseType)
                    {
                        case 1:
                            course = new CBLCourse();
                            break;
                        case 2:
                            course = new LBCCourse();
                            break;
                        case 3:
                            course = new PBLCourse();
                            break;
                        case 4:
                            course = new RBLCourse();
                            break;
                        case 5:
                        case 6:
                            course = new PBCCourse();
                            break;
                        default:
                            continue;
                    }
                    AssignCourseDetails(course, courseObj);
                    user.AddCourse(course);
                    totalCredits += course.Credits;
                }
                user.CoursesMetadata = new CoursesMetadata(
                            rootObject.GetNamedString("semester"), GetRefreshUTC(rootObject.GetNamedString("refreshed")), totalCredits);
                return user;
            }
            catch
            {
                return null;
            }
        }
Ejemplo n.º 4
0
 private static void AssignSpecificDetails(RBLCourse course, JsonObject courseObject)
 {
 }