private void times_DownloadStringCompleted(string res) { if (res == "") { return; } string comp = res.Replace(" ", string.Empty); List <Data> resultCollection = new List <Data> (); //TO-DO: Parse VPlan //lastD = false; if (!_silent) { OnRaiseReadyToClearViewEvent(); } int needleCount = GetNewsBoxesLength(comp); int daysAndNewsBoxes = VConfig.ExpectedDayNum + needleCount; string[] raw = GetDayArray(comp, daysAndNewsBoxes); InterstitialFetching preliminaryResult = new InterstitialFetching(); foreach (var item in raw) { preliminaryResult = InterstitialFetching.ProcessRow(item, preliminaryResult.OuterLoopCursor, daysAndNewsBoxes, _mode, _silent, preliminaryResult.HasToGetSecondSchedule); if (preliminaryResult.HasToGetSecondSchedule) { GetTimes(_group, Activity.ParseSecondSchedule); } resultCollection.AddRange(preliminaryResult.ParsedRows); } _globData = resultCollection; if (!preliminaryResult.HasToGetSecondSchedule) { if (_rootToTemporary) { _temporaryRefresh(resultCollection); } else { OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(resultCollection)); } } }
private void news_DownloadStringCompleted(string res) { if (res == "") { return; } string comp = res.Replace(" ", string.Empty); //TO-DO: Parse VPlan //lastD = false; int needleCount = GetNewsBoxesLength(comp); int daysAndNewsBoxes = VConfig.ExpectedDayNum + needleCount; string[] raw = GetDayArray(comp, daysAndNewsBoxes); InterstitialFetching preliminaryResult = new InterstitialFetching(); foreach (var item in raw) { preliminaryResult = InterstitialFetching.ProcessRow(item, preliminaryResult.OuterLoopCursor, daysAndNewsBoxes, _mode, _silent, preliminaryResult.HasToGetSecondSchedule, Activity.GetNews); if (preliminaryResult.ParsedNews != null && (preliminaryResult.ParsedNews.Content != null || preliminaryResult.ParsedNews.Summary != null)) { OnRaiseRetreivedNewsItemEvent(new NewsEventArgs(preliminaryResult.ParsedNews)); } } }
/// <summary> /// Given a string representing a table of a day in WebUntis' HTML, <see cref="ProcessRow"/> will return an object including the <see cref="Data"/> representations of each schedule value /// </summary> /// <returns>Object containing the current progress of parsing and the last <see cref="Data"/>-objects that were parsed</returns> /// <param name="item">The HTML string representing the table of a day</param> /// <param name="iOuter">The progress through the day tables</param> /// <param name="mode">The background operations mode. See also <seealso cref="UntisExp.Fetcher"/></param> /// <param name="silent">Whether the task will add headings</param> /// <param name="daysAndNewsBoxes">The number of news tables in the week</param> /// <param name="passDontImmediatelyRefresh">If appropriate, this value will be passed to <see cref="HasToGetSecondSchedule"/>.</param> /// <param name="activity">The action which should be performed.</param> public static InterstitialFetching ProcessRow(string item, int iOuter, int daysAndNewsBoxes, int mode, bool silent, bool passDontImmediatelyRefresh, Activity activity = Activity.ParseFirstSchedule) { List <Data> v1 = new List <Data>(); InterstitialFetching result = new InterstitialFetching { HasToGetSecondSchedule = passDontImmediatelyRefresh }; int daysRec = 0; if (item.IndexOf(VConfig.SearchNoAccess, StringComparison.Ordinal) == -1) { string it = item.Replace(" ", String.Empty); string searchInFront; News news = null; if (activity == Activity.GetNews) { searchInFront = "<tr>"; news = new News { Image = "http://centrallink.de/sr/Blackboard.png", Source = new Uri(VConfig.Url) }; } else { searchInFront = "<trclass='list"; } if ((item.IndexOf(VConfig.NoEventsText.Replace(" ", string.Empty), StringComparison.Ordinal) == -1) || activity == Activity.GetNews) { int iterations = 0; it = it.Substring(it.IndexOf("</tr>", StringComparison.Ordinal) + 5, it.Length - it.IndexOf("</tr>", StringComparison.Ordinal) - 5); while (it.IndexOf(searchInFront, StringComparison.Ordinal) != -1) { if (iterations == 0) { // news box should not be a day so we count days here daysRec++; } if (activity == Activity.GetNews) { if (news != null && news.Summary != null) { news.Summary += "\n\n"; } DateTime date = GetDateFromDay(iOuter, Activity.ParseFirstSchedule); string dateName = new CultureInfo("de-DE").DateTimeFormat.GetDayName(date.DayOfWeek); if (news != null) { news.Summary += dateName + ", " + date.Day + "." + date.Month + ":\n"; } } Data data = new Data(); string w = it.Substring(it.IndexOf(searchInFront, StringComparison.Ordinal)); w = w.Substring(0, w.IndexOf("</tr>", StringComparison.Ordinal)); it = it.Substring(it.IndexOf("</tr>", StringComparison.Ordinal) + 5, it.Length - it.IndexOf("</tr>", StringComparison.Ordinal) - 5); var mc = VConfig.CellSearch.Matches(w); int webColumn = 0; foreach (var thing in mc) { string compute = PrepareScheduleItem(thing); if (activity != Activity.GetNews) { data = ProceedScheduleItem(compute, data, webColumn, iterations, silent, v1); webColumn++; } else { news = ProcessNewsItem(compute, news); result.ParsedNews = news; } } if (activity != Activity.GetNews) { data.Refresh(); if ((mode == 1 && daysRec == 2) || (mode != 1 && mode != 0) || (mode == 0 && daysRec == 1)) { v1.Add(data); } } iterations++; } if ((iterations == 0 && activity != Activity.GetNews) || (iterations > 0 && activity == Activity.GetNews)) { iOuter--; } } else { daysRec++; if (!silent) { //Adds Date v1.Add(new Data(GetDateFromDay(iOuter, activity))); //Adds no events message v1.Add(new Data()); } } } iOuter++; if (iOuter == daysAndNewsBoxes && (daysRec == 1) && mode != 0 && activity == Activity.ParseFirstSchedule) { result.HasToGetSecondSchedule = true; } result.OuterLoopCursor = iOuter; result.ParsedRows = v1; return(result); }
private void timesNext_DownloadStringCompleted(string res) { try { if (res == "") { if (_rootToTemporary) { _temporaryRefresh(_globData); } else { OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); } return; } string comp = res.Replace(" ", string.Empty); if (comp.IndexOf("NotFound", StringComparison.Ordinal) != -1 || comp.Length == 0) { if (_rootToTemporary) { _temporaryRefresh(_globData); } else { OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); } return; } List <Data> resultCollection = new List <Data> (); int needleCount = GetNewsBoxesLength(comp); int daysAndNewsBoxes = VConfig.ExpectedDayNum + needleCount; string[] raw = GetDayArray(comp, daysAndNewsBoxes); InterstitialFetching preliminaryResult = new InterstitialFetching(); foreach (var item in raw) { preliminaryResult = InterstitialFetching.ProcessRow(item, preliminaryResult.OuterLoopCursor, daysAndNewsBoxes, _mode, _silent, preliminaryResult.HasToGetSecondSchedule, Activity.ParseSecondSchedule); resultCollection.AddRange(preliminaryResult.ParsedRows); } _globData.AddRange(resultCollection); if (_rootToTemporary) { _temporaryRefresh(_globData); } else { OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); } } catch { if (_rootToTemporary) { _temporaryRefresh(_globData); } else { OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); } } }
/// <summary> /// Given a string representing a table of a day in WebUntis' HTML, <see cref="ProcessRow"/> will return an object including the <see cref="Data"/> representations of each schedule value /// </summary> /// <returns>Object containing the current progress of parsing and the last <see cref="Data"/>-objects that were parsed</returns> /// <param name="item">The HTML string representing the table of a day</param> /// <param name="iOuter">The progress through the day tables</param> /// <param name="mode">The background operations mode. See also <seealso cref="UntisExp.Fetcher"/></param> /// <param name="silent">Whether the task will add headings</param> /// <param name="daysAndNewsBoxes">The number of news tables in the week</param> /// <param name="passDontImmediatelyRefresh">If appropriate, this value will be passed to <see cref="HasToGetSecondSchedule"/>.</param> /// <param name="activity">The action which should be performed.</param> public static InterstitialFetching ProcessRow(string item, int iOuter, int daysAndNewsBoxes, int mode, bool silent, bool passDontImmediatelyRefresh,int daysRec, Activity activity = Activity.ParseFirstSchedule,News news = null) { List<Data> v1 = new List<Data>(); InterstitialFetching result = new InterstitialFetching { HasToGetSecondSchedule = passDontImmediatelyRefresh }; if (item.IndexOf(VConfig.SearchNoAccess, StringComparison.Ordinal) == -1) { string it = item.Replace(" ", String.Empty); string searchInFront; if (activity == Activity.GetNews) { searchInFront = "<tr>"; if(news==null) news = new News { Image = "http://centrallink.de/sr/Blackboard.png", Source = new Uri(VConfig.Url) }; } else { searchInFront = "<trclass='list"; } if ((item.IndexOf(VConfig.NoEventsText.Replace(" ", string.Empty), StringComparison.Ordinal) == -1) || activity == Activity.GetNews) { int iterations = 0; it = it.Substring(it.IndexOf("</tr>", StringComparison.Ordinal) + 5, it.Length - it.IndexOf("</tr>", StringComparison.Ordinal) - 5); while (it.IndexOf(searchInFront, StringComparison.Ordinal) != -1) { if (iterations == 0) { // news box should not be a day so we count days here daysRec++; } if (activity == Activity.GetNews) { if (news != null && news.Summary != null) { news.Summary += "\n\n"; } DateTime date = GetDateFromDay(iOuter, Activity.ParseFirstSchedule); string dateName = new CultureInfo("de-DE").DateTimeFormat.GetDayName(date.DayOfWeek); if (news != null) news.Summary += dateName + ", " + date.Day + "." + date.Month + ":\n"; } Data data = new Data(); string w = it.Substring(it.IndexOf(searchInFront, StringComparison.Ordinal)); w = w.Substring(0, w.IndexOf("</tr>", StringComparison.Ordinal)); it = it.Substring(it.IndexOf("</tr>", StringComparison.Ordinal) + 5, it.Length - it.IndexOf("</tr>", StringComparison.Ordinal) - 5); var mc = VConfig.CellSearch.Matches(w); int webColumn = 0; foreach (var thing in mc) { string compute = PrepareScheduleItem(thing); if (activity != Activity.GetNews) { data = ProceedScheduleItem(compute, data, webColumn, iterations, silent, v1); webColumn++; } else { news = ProcessNewsItem(compute, news); } } if (activity != Activity.GetNews) { data.Refresh(); if ((mode == 1 && daysRec == 2) || (mode != 1 && mode != 0) || (mode == 0 && daysRec == 1)) v1.Add(data); } iterations++; } //skips News-Boxes in iOuter-count to have the right current-day in iOuter if ((iterations == 0 && activity != Activity.GetNews) || (iterations > 0 && activity == Activity.GetNews)) { iOuter--; } } else { daysRec++; if (!silent) { //Adds Date v1.Add(new Data(GetDateFromDay(iOuter, activity))); //Adds no events message v1.Add(new Data()); } } } iOuter++; if (iOuter == VConfig.ExpectedDayNum && (daysRec == 1) && mode != 0 && activity == Activity.ParseFirstSchedule) { result.HasToGetSecondSchedule = true; } result.OuterLoopCursor = iOuter; result.ParsedRows = v1; result.ParsedNews = news; result.RecordedDays = daysRec; return result; }
private void times_DownloadStringCompleted(string res) { #if DEBUG if (VConfig.testhtml != null) { res = VConfig.testhtml; } #endif if (res == "") { return; } string comp = res.Replace(" ", string.Empty); List<Data> resultCollection = new List<Data> (); //TO-DO: Parse VPlan //lastD = false; if (!_silent) OnRaiseReadyToClearViewEvent(); int needleCount = GetNewsBoxesLength(comp); int daysAndNewsBoxes = VConfig.ExpectedDayNum + needleCount; string[] raw = GetDayArray (comp, daysAndNewsBoxes); InterstitialFetching preliminaryResult = new InterstitialFetching(); foreach (var item in raw) { preliminaryResult = InterstitialFetching.ProcessRow (item, preliminaryResult.OuterLoopCursor, daysAndNewsBoxes, _mode, _silent, preliminaryResult.HasToGetSecondSchedule,preliminaryResult.RecordedDays); if (preliminaryResult.HasToGetSecondSchedule) { GetTimes(_group, Activity.ParseSecondSchedule); } resultCollection.AddRange (preliminaryResult.ParsedRows); } _globData = resultCollection; if (!preliminaryResult.HasToGetSecondSchedule) { if (_rootToTemporary) _temporaryRefresh (resultCollection); else OnRaiseRetreivedScheduleItemsEvent (new ScheduleEventArgs (resultCollection)); } }
private void timesNext_DownloadStringCompleted(string res) { try { if (res == "") { if (_rootToTemporary) _temporaryRefresh(_globData); else OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); return; } string comp = res.Replace(" ", string.Empty); if (comp.IndexOf("NotFound", StringComparison.Ordinal) != -1 || comp.Length == 0) { if (_rootToTemporary) _temporaryRefresh(_globData); else OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); return; } List<Data> resultCollection = new List<Data> (); int needleCount = GetNewsBoxesLength(comp); int daysAndNewsBoxes = VConfig.ExpectedDayNum + needleCount; string[] raw = GetDayArray (comp, daysAndNewsBoxes); InterstitialFetching preliminaryResult = new InterstitialFetching(); foreach (var item in raw) { preliminaryResult = InterstitialFetching.ProcessRow(item, preliminaryResult.OuterLoopCursor, daysAndNewsBoxes, _mode, _silent, preliminaryResult.HasToGetSecondSchedule,preliminaryResult.RecordedDays, Activity.ParseSecondSchedule); resultCollection.AddRange (preliminaryResult.ParsedRows); } _globData.AddRange(resultCollection); if (_rootToTemporary) _temporaryRefresh(_globData); else OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); } catch { if (_rootToTemporary) _temporaryRefresh(_globData); else OnRaiseRetreivedScheduleItemsEvent(new ScheduleEventArgs(_globData)); } }
private void news_DownloadStringCompleted(string res) { #if DEBUG if (VConfig.testhtml != null) { res = VConfig.testhtml; } #endif if (res == "") { return; } string comp = res.Replace (" ", string.Empty); //TO-DO: Parse VPlan //lastD = false; int needleCount = GetNewsBoxesLength(comp); int daysAndNewsBoxes = VConfig.ExpectedDayNum + needleCount; string[] raw = GetDayArray (comp, daysAndNewsBoxes); InterstitialFetching preliminaryResult = new InterstitialFetching(); foreach (var item in raw) { preliminaryResult = InterstitialFetching.ProcessRow (item, preliminaryResult.OuterLoopCursor, daysAndNewsBoxes, _mode, _silent, preliminaryResult.HasToGetSecondSchedule,preliminaryResult.RecordedDays, Activity.GetNews,preliminaryResult.ParsedNews); } if (preliminaryResult.ParsedNews != null && (preliminaryResult.ParsedNews.Content != null || preliminaryResult.ParsedNews.Summary != null)) OnRaiseRetreivedNewsItemEvent(new NewsEventArgs(preliminaryResult.ParsedNews)); }