Example #1
0
        public void onLink(Object sender, EventArgs args)
        {
            Compass_Schedule testDialog = new Compass_Schedule();

            if (testDialog.ShowDialog(this) == DialogResult.OK)
            {
                link = testDialog.textBox1.Text;
            }

            if (Program.checkFile(link))
            {
                Properties.Settings.Default.CompassLink = link;
            }

            testDialog.Dispose();

            Program.getProgram().reload();
        }
        /* INIT */

        public Dictionary <DateTime, CalendarDay> LoadPeriods()
        {
            System.Diagnostics.Debug.Write("Update" + System.Environment.NewLine);

            if (Properties.Settings.Default.CompassLink == "Nil" || "C:\\Users\\DIE0003\\Documents\\Visual Studio 2010\\Projects\\SchoolCalenderTrayIcon\\SchoolCalenderTrayIcon\\bin\\Debug\\SchoolCalendarTrayIcon.exe" == System.Reflection.Assembly.GetExecutingAssembly().Location)
            {
                Compass_Schedule link = new Compass_Schedule();
                if (link.ShowDialog(this) == DialogResult.OK)
                {
                    Properties.Settings.Default.CompassLink = link.textBox1.Text;
                }
                else
                {
                    Properties.Settings.Default.CompassLink = "";
                }

                link.Dispose();
            }

            if (!checkFile(Properties.Settings.Default.CompassLink))
            {
                OnErrorExit();
            }

            Properties.Settings.Default.Save();

            string url = Properties.Settings.Default.CompassLink;

            string[] periodsText = splitCalender(readCalender(url));
            Dictionary <DateTime, CalendarDay> days = new Dictionary <DateTime, CalendarDay>();

            if (periodsText == null)
            {
                MessageBox.Show("Currently unable to load your calendar, School Calendar Tray Icon will continue to attempt loading your calendar.", "School Calendar Tray Icon Error");
            }

            PeriodStruct[] periods = CreatePeriods(periodsText).ToArray();
            string         nl      = System.Environment.NewLine;

            for (int i = 0; i < periods.Length; i++)
            {
                if (periods[i].name.Contains("."))
                {
                    periods[i].name = periods[i].name.Split(".".ToCharArray())[0];
                }
                try
                {
                    periods[i].name = System.Text.RegularExpressions.Regex.Replace(periods[i].name, "[0-9]", "");
                    periods[i].name = periods[i].name.Replace("/", "");
                    periods[i].name = periods[i].name.Replace("\\", "");

                    if (days.ContainsKey(periods[i].startTime.Date))
                    {
                        days[periods[i].startTime.Date].periods.Add(periods[i]);
                    }
                    else
                    {
                        days.Add(periods[i].startTime.Date, initializeCalendarDay(periods[i].startTime.Date));
                        days[periods[i].startTime.Date].periods.Add(periods[i]);
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.Write(e.Message);
                }
            }

            foreach (KeyValuePair <DateTime, CalendarDay> day in days)
            {
                day.Value.periods.Sort((x, y) => DateTime.Compare(x.startTime, y.startTime));

                for (int i = 0; i < day.Value.periods.Count; i++)
                {
                    day.Value.names.Add(day.Value.periods[i].name);
                    day.Value.rooms.Add(day.Value.periods[i].room);
                    day.Value.times.Add(day.Value.periods[i].startTime.ToString().Substring(10).Replace(":00 ", " "));
                    day.Value.ends.Add(day.Value.periods[i].endTime.ToString().Substring(10).Replace(":00 ", " "));
                }
            }

            System.Diagnostics.Debug.Write(days.Count.ToString() + System.Environment.NewLine);
            return(days);
        }