Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // START BUTTON Event
- private void StartBtn_OnClick(object sender, EventArgs e)
- {
- string dllName = cboxDlls.Text;
- try
- {
- InputModel input = new InputModel (_coursesSource, dllName);
- // Starting Background Crawler
- _bgCrawler = new AbortableBackgroundWorker(); // Crawler in Background
- // Invokes BGWorker using invoke. Dunno why, but it worked
- CoursesGrid.Invoke((Action) delegate {_bgCrawler.RunWorkerAsync(input);});
- // Starting Background Grid Refresher
- RefreshGridWorker.RunWorkerAsync ();
- }
- catch (Exception ex)
- {
- // TODO: Log and Add Exceptions Logs @ UI
- }
- }
- // BG Worker 2 : Gridview refresher
- private void RefreshGridWorker_DoWork(object sender, DoWorkEventArgs e)
- {
- while (1 == 1)
- {
- CoursesGrid.BeginInvoke // Inline method declaration
- (
- (Action)delegate
- {
- if (_coursesSource.Count > 0)
- {
- _coursesSourceClone = new BindingSource();
- // Not good but everysecond i copy the whole source list to a temp one
- foreach (OutputModel m in _coursesSource)
- {
- _coursesSourceClone.Add(m);
- }
- CoursesGrid.DataSource = _coursesSourceClone;
- CoursesGrid.EndEdit();
- }
- }
- ); // end of inline method declaration
- Thread.Sleep(1000); // Checks every second for a new source
- }
- }
- }
- // Method of interest in the .dll - This is the method that parses each course
- public static void ParseCourse(ref Course parsedCourse, ref BindingSource coursesSource)
- {
- List<Discipline> courseDisciplines;
- // Auxiliar Methods Calling
- string name = ParseCourseName();
- int segments = CountCourseSegments();
- courseDisciplines = ParseCourseDisciplines();
- // Adding parsed course to list
- Course tmpCourse = new Course (name, segments, courseDisciplines);
- // Updating source of courses
- coursesSource.Add(new OutputModel(tmpCourse.Name,tmpCourse.DisciplinesCount,tmpCourse.Segments)); // Here is where i populate the source
- coursesSource.EndEdit();
- parsedCourse = tmpCourse;
- m_parsedCourses.Add(tmpCourse);
- // Adding Unique Disciplines to List of Disciplines of the university
- foreach (Discipline disc in courseDisciplines)
- {
- if (!m_parsedDisciplines.ContainsKey(disc.Code))
- {
- m_parsedDisciplines.Add(disc.Code, disc);
- }
- }
- // Logging Step and Writing course to file
- Logs.LogWriter.LogInfo("Finished Parsing : " + tmpCourse.Name + " Total Disciplines : " + tmpCourse.DisciplinesCount);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement