예제 #1
0
 public IntervalList(IGui gui)
 {
     this.gui = gui;
     ctc      = new CoTaughtCourses(gui);
 }
예제 #2
0
        public string Print(Semester semester, bool printAllSections, bool printAllDates)
        {
            if (semester == null)
            {
                MessageBox.Show("No semester loaded.");
            }
            else
            {
                // open file for each room in roomList array defined above
                //open file
                try
                {
                    string lastCatalogNbr = "";
                    string lastSection    = "";

                    foreach (var room in roomList)
                    {
                        string filename = Configuration.ICSDIRECTORY + semester.Name + " - " + room + ".ics";
                        using (System.IO.StreamWriter printer = new System.IO.StreamWriter(filename, false))
                        {
                            // print header
                            printer.WriteLine("BEGIN:VCALENDAR");
                            printer.WriteLine("PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN");
                            printer.WriteLine("VERSION:2.0");
                            printer.WriteLine("METHOD:PUBLISH");
                            printer.WriteLine("X-MS-OLK-FORCEINSPECTOROPEN:TRUE");
                            printer.WriteLine("BEGIN:VTIMEZONE");
                            printer.WriteLine("TZID:Central Standard Time");
                            printer.WriteLine("BEGIN:STANDARD");
                            printer.WriteLine("DTSTART:16011104T020000"); //
                            printer.WriteLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11");
                            printer.WriteLine("TZOFFSETFROM:-0500");
                            printer.WriteLine("TZOFFSETTO:-0600");
                            printer.WriteLine("END:STANDARD");
                            printer.WriteLine("BEGIN:DAYLIGHT");
                            printer.WriteLine("DTSTART:16010311T020000");
                            printer.WriteLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3");
                            printer.WriteLine("TZOFFSETFROM:-0600");
                            printer.WriteLine("TZOFFSETTO:-0500");
                            printer.WriteLine("END:DAYLIGHT");
                            printer.WriteLine("END:VTIMEZONE");

                            // start processing courses as calendar events
                            for (int x = 0; x < semester.Size(); x++)
                            {
                                Section sec       = semester.ElementAt(x);
                                string  catNumber = sec.CatalogNbr;

                                // don't add event for second/third instructors of same section
                                if (catNumber.Equals(lastCatalogNbr) && sec.SectionName.Equals(lastSection))
                                {
                                    continue;
                                }
                                else
                                {
                                    lastCatalogNbr = catNumber;
                                    lastSection    = sec.SectionName;
                                }

                                // combine courses with co-taught numbers into a single event, but only create event for lowest catalog number
                                CoTaughtCourses cotaught = new CoTaughtCourses(gui);
                                string          ctc      = cotaught.CoTaughtCourseOf(catNumber);
                                if (ctc.Any())
                                {
                                    int cNum   = int.Parse(catNumber);
                                    int ctcNum = int.Parse(ctc);
                                    if ((!room.Equals("graduate") && !room.Equals("undergraduate")) ||
                                        (room.Equals("graduate") && IsGraduateCourse(cNum) && IsGraduateCourse(ctcNum)) ||
                                        (room.Equals("undergraduate") && IsUnderGraduateCourse(cNum) && IsUnderGraduateCourse(ctcNum)))
                                    {
                                        if (cNum > ctcNum)
                                        {
                                            continue; // skip courses whose number is greater than their cotaught course
                                        }
                                        else
                                        {
                                            catNumber += "/" + ctc;
                                        }
                                    }
                                }

                                // skip sections we are not interested in scheduling
                                if (NonPrintedSection(sec, room))
                                {
                                    continue; // do not print these sections
                                }
                                else
                                {
                                    // format values for event

                                    string today = ICSToday();

                                    string startDate = ICSDate(sec.MeetingStartDt);
                                    string endDate   = ICSDate(AddDaysToDate(sec.MeetingEndDt, 1)); // add 1 day to last class date
                                    string startTime = ICSTime(sec.MeetingTimeStart);
                                    string endTime   = ICSTime(sec.MeetingTimeEnd);

                                    string daysOfWeek = ICSDaysOfWeek(sec);

                                    startDate = ICSDate(CalculateActualStartDate(sec.MeetingStartDt, daysOfWeek));

                                    // print out lines for sections of interest
                                    printer.WriteLine("BEGIN:VEVENT");
                                    printer.WriteLine("CATEGORIES:Student/Teaching");
                                    printer.WriteLine("CLASS:PUBLIC");
                                    printer.WriteLine("CREATED:" + today);
                                    printer.WriteLine("DESCRIPTION:" + sec.Subject + " " + catNumber + "  " + sec.ClassDescr
                                                      + (!sec.TopicDescr.Equals(" ") ? " - " + sec.TopicDescr : ""));
                                    printer.WriteLine("DTEND;TZID=\"Central Standard Time\":" + startDate + endTime + "00");
                                    printer.WriteLine("DTSTAMP:" + today);
                                    printer.WriteLine("DTSTART;TZID=\"Central Standard Time\":" + startDate + startTime + "00");
                                    printer.WriteLine("LAST-MODIFIED:" + today);
                                    printer.WriteLine("LOCATION:" + sec.FacilityId);
                                    printer.WriteLine("PRIORITY:5");
                                    printer.WriteLine("RRULE:FREQ=WEEKLY;UNTIL=" + endDate + "000000" + ";" + daysOfWeek);
                                    printer.WriteLine("SEQUENCE:0");
                                    printer.WriteLine("SUMMARY;LANGUAGE=en-us:" + sec.Subject + " " + catNumber + " - "
                                                      + sec.SectionName + " (" + sec.Instructor + ")");
                                    printer.WriteLine("TRANSP:OPAQUE");
                                    printer.WriteLine("UID:" + Guid.NewGuid());
                                    printer.WriteLine("X-ALT-DESC;");
                                    printer.WriteLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
                                    printer.WriteLine("X-MICROSOFT-CDO-IMPORTANCE:1");
                                    printer.WriteLine("X-MICROSOFT-DISALLOW-COUNTER:FALSE");
                                    printer.WriteLine("X-MS-OLK-AUTOFILLLOCATION:FALSE");
                                    printer.WriteLine("X-MS-OLK-AUTOSTARTCHECK:FALSE");
                                    printer.WriteLine("X-MS-OLK-CONFTYPE:0");
                                    printer.WriteLine("END:VEVENT");
                                }
                            }
                            printer.WriteLine("END:VCALENDAR");
                        }
                    }
                }
                catch (Exception e)
                {
                    gui.WriteLine(e.Message);
                }

                gui.WriteLine("Calendar events generated.");
            }
            return("");
        }