Beispiel #1
0
        /// <summary>
        /// Sets the main instance to a given instance, if no instance exsists yet.
        /// Used to initiate the config instance when loading the config data from file.
        /// </summary>
        /// <param name="c">Instance of <c>UEKVConfig</c> to set the main instance to.</param>
        /// <returns>Main instance of <c>UEKVConfig</c>.</returns>
        public static UEKVConfig InitiateInstance(UEKVConfig c)
        {
            if (UEKVConfig.instance == null)
            {
                UEKVConfig.instance = c;
            }

            return(UEKVConfig.GetInstance());
        }
        //TODO Remove legacy references & comments

        /*
         * private void LoadConfigCourseSelection()
         * {
         *  foreach (string s in UEKVConfig.GetInstance().Subjects)
         *  {
         *      string subjectText = $"{s} ({Library.COURSE_MAIN_ABBRV[Library.COURSE_MAIN_SUBJ[s]]})";
         *      int loc = this.checkedListBox_Profile.Items.IndexOf(subjectText);
         *      this.checkedListBox_Profile.SetItemChecked(loc, true);
         *  }
         * }
         */

        #region Config

        //TODO Move method to UEKConfig.cs
        private void LoadConfigJSON()
        {
            if (!File.Exists(Library.CONFIG_PATH))
            {
                this.SaveConfigJSON();
            }
            string     confRaw = File.ReadAllText(Library.CONFIG_PATH, Encoding.UTF8);
            UEKVConfig c       = JsonConvert.DeserializeObject <UEKVConfig>(confRaw);

            UEKVConfig.InitiateInstance(c);
        }
Beispiel #3
0
 /// <summary>
 /// Gets the main instance of <c>UEKVConfig</c>.
 /// Creates one, if none exsists yet.
 /// </summary>
 /// <returns>Main instance of <c>UEKVConfig</c>.</returns>
 public static UEKVConfig GetInstance()
 {
     if (UEKVConfig.instance == null)
     {
         UEKVConfig c = new UEKVConfig();
         c.lastUpdated       = new DateTime(0);
         c.subjects          = new List <string>();
         UEKVConfig.instance = c;
     }
     return(UEKVConfig.instance);
 }
        //TODO Check if method should be moved
        private void RefreshAbbreviationInfo()
        {
            Library.ABBRV_INFORMATION = "Abbreviations:";
            List <string> _tmp = UEKVConfig.GetInstance().Subjects;

            _tmp.Sort();

            foreach (string s in _tmp)
            {
                Library.ABBRV_INFORMATION += $"\n{s} = {Library.COURSE_MAIN_ABBRV[Library.COURSE_MAIN_SUBJ[s]]}";
            }
        }
        private void checkedListBox_Profile_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            string subj = (((string)this.checkedListBox_Profile.Items[e.Index]).Split(new char[] { '(' }))[0].Trim();

            if (e.NewValue == CheckState.Checked)
            {
                if (!UEKVConfig.GetInstance().Subjects.Contains(subj))
                {
                    UEKVConfig.GetInstance().Subjects.Add(subj);
                }
            }
            else
            {
                if (UEKVConfig.GetInstance().Subjects.Contains(subj))
                {
                    UEKVConfig.GetInstance().Subjects.Remove(subj);
                }
            }
        }
        //TODO Check if method should be moved
        private List <CourseEvent> GetCoursesForDay(DateTime dt)
        {
            List <CourseEvent> ret             = new List <CourseEvent>();
            DateTime           comp            = new DateTime(dt.Year, dt.Month, dt.Day);
            List <CourseMain>  relevantCourses = new List <CourseMain>();

            foreach (string s in UEKVConfig.GetInstance().Subjects)
            {
                relevantCourses.Add(Library.COURSE_MAIN_SUBJ[s]);
            }

            foreach (CourseEvent ce in Library.ALL_COURSE_EVENT)
            {
                if (ce.Date == comp && relevantCourses.Contains(ce.Course))
                {
                    ret.Add(ce);
                }
            }
            return(ret);
        }
 //TODO Move method to UEKConfig.cs
 private UEKVConfig GetConfigJSON()
 {
     return(UEKVConfig.GetInstance());
 }