public Course(bool createTimer) { this.years = new Year[3]; for (int i = 0; i < 3; i++) { this.years[i] = new Year(i + 1); this.years[i].Change += this.childChangedHandler; this.years[i]._WarningEmitted += this.warningEmittedHandler; this.years[i].TriggerCalculation(); } this.title = Properties.Resources.COURSE_DEFAULT_TITLE; this.Result = Course.Degree.Unknown; this.warnings = new CourseWarnings(); this.warnings.WarningsChanged += this.warningsChangedHandler; this._WarningEmitted += this.handleWarningChain; if (createTimer) { this.saveTimer = new Timer(Double.Parse(Properties.Resources.COURSE_SAVE_INTERVAL, CultureInfo.InvariantCulture)); this.saveTimer.AutoReset = true; this.saveTimer.Elapsed += (object sender, ElapsedEventArgs e) => { ConcurrentWorkQueue.Enqueue(() => { new CourseXMLBackend(this.DeepClone()).SetPath(Properties.Resources.SAVE_FILE_PATH).Save(); }); }; this.saveTimer.Start(); } }
public void populate() { this.view.Invoke((MethodInvoker) delegate { this.view.BeginLoading(); this.view.reset(); this.view.ModuleName = this.module.Title; this.view.ModuleCode = this.module.Code; this.view.ModuleCredits = this.module.Credits; this.view.ModuleResult = this.module.Result; }); ConcurrentWorkQueue.Enqueue(() => { foreach (var assessment in this.module.Assessments) { this.view.Invoke((MethodInvoker) delegate { Application.DoEvents(); this.view.createAssessment(this.openAssessmentHandler, this.removeAssessmentHandler, assessment); }); } this.view.Invoke((MethodInvoker) delegate { this.view.EndLoading(); }); }); }
public void LoadCourseHandler(object sender, EventArgs e) { OpenFileDialog file = new OpenFileDialog(); file.InitialDirectory = Environment.CurrentDirectory; file.CheckFileExists = true; file.CheckPathExists = true; file.Multiselect = false; file.ValidateNames = true; file.Filter = "Course files (*.course)|*.course"; file.FileOk += (s, ee) => { try { ConcurrentWorkQueue.Enqueue(() => { Course c = new CourseXMLBackend(null).SetPath(file.FileName).Load(); this.registerCourse(c); }); } catch (InvalidCourseXMLException) { MessageBox.Show("Error loading course, the file might be corrupted.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; file.ShowDialog(); }
protected virtual void childChangedHandler(CourseObjectBase sender, bool triggerRecalculation) { this.onChange(false); if (triggerRecalculation) { ConcurrentWorkQueue.Enqueue(() => this.recalculateResult()); } }
public void SaveCourseHandler(object sender, EventArgs e) { SaveFileDialog file = new SaveFileDialog(); file.InitialDirectory = Environment.CurrentDirectory; file.CheckPathExists = true; file.ValidateNames = true; file.Filter = "Course files (*.course)|*.course"; file.FileOk += (s, ee) => { ConcurrentWorkQueue.Enqueue(() => { new CourseXMLBackend(this.course.DeepClone()).SetPath(file.FileName).Save(); }); }; file.ShowDialog(); }
private void registerCourse(Course course) { if (course != null) { this.view.Invoke((MethodInvoker) delegate { this.view.reset(); this.view.startNew(); }); this.view.Invoke((MethodInvoker) delegate { this.warningsWindow.BeginLoading(); }); if (this.course != null) { this.course.Detach(); } this.course = course; this.course.Change += this.CourseChangedHandler; this.course.WarningEmitted += this.WarningsChangedHandler; this.course.TriggerCalculation(); ConcurrentWorkQueue.Enqueue(() => this.view.Invoke((MethodInvoker) delegate { this.warningsWindow.EndLoading(); })); this.view.Invoke((MethodInvoker) delegate { this.view.BeginLoading(); }); foreach (Year y in this.course.Years) { foreach (Module m in y.Modules) { this.view.Invoke((MethodInvoker) delegate { this.view.createModule(y.Number, this.OpenModuleHandler, this.RemoveModuleHandler, m); Application.DoEvents(); }); } } this.view.Invoke((MethodInvoker) delegate { this.view.SelectYearOne(); this.view.ResetModuleControlPositions(1); this.view.SelectYearTwo(); this.view.ResetModuleControlPositions(2); this.view.SelectYearThree(); this.view.ResetModuleControlPositions(3); this.view.SelectYearOne(); this.view.EndLoading(); }); } }
public void FileDroppedHandler(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); IEnumerable <string> selection = files.Where((string s) => s.Contains(".course")); string x; if (selection.Count() > 0) { x = selection.First(); ConcurrentWorkQueue.Enqueue(() => { try { Course c = new CourseXMLBackend(null).SetPath(x).Load(); this.registerCourse(c); } catch (InvalidCourseXMLException) { MessageBox.Show("Error loading course, the file might be corrupted.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); } }
public void StartLoadAutoHandler(object sender, EventArgs e) { // Load Course from autosave if (System.IO.File.Exists(Properties.Resources.SAVE_FILE_PATH)) { ConcurrentWorkQueue.Enqueue(() => { try { Course c = new CourseXMLBackend(null).SetPath(Properties.Resources.SAVE_FILE_PATH).Load(); this.registerCourse(c); return; } catch (InvalidCourseXMLException) { MessageBox.Show("Unable to load course, the file might be corrupted.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); } else { MessageBox.Show("No autosave file present.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public static void Enqueue(Action action) { _queue.Enqueue(action); }
public void StartNewHandler(object sender, EventArgs e) { // Reset Course instance // (re) Initialize main form ConcurrentWorkQueue.Enqueue(() => this.registerCourse(new Course())); }
public virtual void TriggerCalculation() { ConcurrentWorkQueue.Enqueue(() => this.recalculateResult()); }