Example #1
0
        // Reads class' data from config file, makes object and returns pointer
        // Returns NULL if method cannot parse configuration data
        private CourseClass ParseCourseClass(Dictionary <string, JsonElement> data)
        {
            int  pid = 0, cid = 0, dur = 1;
            bool lab = false;

            var groups = new List <StudentsGroup>();

            foreach (string key in data.Keys)
            {
                switch (key)
                {
                case "professor":
                    GetMember(data[key], ref pid);
                    break;

                case "course":
                    GetMember(data[key], ref cid);
                    break;

                case "lab":
                    GetMember(data[key], ref lab);
                    break;

                case "duration":
                    GetMember(data[key], ref dur);
                    break;

                case "group":
                case "groups":
                    if (JsonValueKind.Array.Equals(data[key].ValueKind))
                    {
                        var grpList = data[key].EnumerateArray();
                        foreach (var grp in grpList)
                        {
                            var g = GetStudentsGroupById(grp.GetInt32());
                            if (g != null)
                            {
                                groups.Add(g);
                            }
                        }
                    }
                    else
                    {
                        int group = -1;
                        GetMember(data[key], ref group);
                        var g = GetStudentsGroupById(group);
                        if (g != null)
                        {
                            groups.Add(g);
                        }
                    }
                    break;
                }
            }

            // get professor who teaches class and course to which this class belongs
            Professor p = GetProfessorById(pid);
            Course    c = GetCourseById(cid);

            // does professor and class exists
            if (c == null || p == null)
            {
                return(null);
            }

            // make object and return
            return(new CourseClass(p, c, lab, dur, groups.ToArray()));
        }
Example #2
0
 // Returns TRUE if another class has same professor.
 public bool ProfessorOverlaps(CourseClass c)
 {
     return(Professor.Equals(c.Professor));
 }