private string recordDataInWebBrowser(HtmlDocument doc, string checkingYM, string checkingID) { string resultYM = ""; viewModel.acquiredData = BasicDailyDataInformation.ToTitle() + "\r\n"; var basicDailyDataList = Core.basicDailyDataManager.getBasicDailyData(currentMission.ID); var fileStatusList = Core.basicDailyDataManager.getFileStatus(currentMission.ID); HtmlElement IDHeader = doc.GetElementById("stk_no"); HtmlElement resultTable = getResultTable(doc); if (resultTable == null) { return(""); } List <BasicDailyDataInformation> analyzedDataList = analysisDataTable(resultTable.InnerHtml); FileStatus currentFileStatus = getCurrentFileStatus(analyzedDataList); if ((currentFileStatus != FileStatus.Null && checkingYM == analyzedDataList.First().date.ToString("yyyyMM") && IDHeader.InnerHtml.Contains(checkingID)) || currentFileStatus == FileStatus.Null && ++nullcount >= 4) { nullcount = 0; renewFileStatus(fileStatusList, currentFileStatus, analyzedDataList.Count); renewBasicDailyDataList(basicDailyDataList, analyzedDataList); Core.basicDailyDataManager.saveBasicDailyData(currentMission.ID, basicDailyDataList); Core.basicDailyDataManager.saveFileStatus(currentMission.ID, fileStatusList); missionList.Remove(currentMission); missionListB.RemoveAt(0); missionList.Remove(currentMission); currentMission = null; } return(resultYM); }
public void startMainMissionLoop() { missionStartTime = DateTime.Now; viewModel.acquiredData = BasicDailyDataInformation.ToTitle(); missionListA = missionList.Where(x => x.type == "A").ToList(); missionListB = missionList.Where(x => x.type == "B").ToList(); Thread.Sleep(100); currentWebSiteStockType = "A"; currentMission = null; DateTime missionAssignedTime = DateTime.Now; int nullcount = 0; while (missionListA.Count > 0) { currentMission = missionListA.First(); printMissionList(); Application.DoEvents(); var basicDailyDataList = Core.basicDailyDataManager.getBasicDailyData(currentMission.ID); var fileStatusList = Core.basicDailyDataManager.getFileStatus(currentMission.ID); printMissionList(); var s = GetCSV( $"http://www.tse.com.tw/exchangeReport/STOCK_DAY?response=csv&date={currentMission.year}{currentMission.month.ToString("D2")}01&stockNo={currentMission.ID}"); List <BasicDailyDataInformation> analyzedDataList = analysisDataCSV(s); FileStatus currentFileStatus = getCurrentFileStatus(analyzedDataList); if ((currentFileStatus != FileStatus.Null) || nullcount > 3) { renewFileStatus(fileStatusList, currentFileStatus, analyzedDataList.Count); renewBasicDailyDataList(basicDailyDataList, analyzedDataList); Core.basicDailyDataManager.saveBasicDailyData(currentMission.ID, basicDailyDataList); Core.basicDailyDataManager.saveFileStatus(currentMission.ID, fileStatusList); missionList.Remove(currentMission); missionListA.RemoveAt(0); currentMission = null; nullcount = 0; } else { nullcount++; } printMissionList(); } webBrowser.Navigate(@"http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php?l=zh-tw"); while (missionListB.Count > 0) { Application.DoEvents(); if (currentMission == null) { currentMission = missionListB.First(); printMissionList(); } bool isRetry = DateTime.Now.Subtract(missionAssignedTime).TotalSeconds > 4; if (isRetry) { webBrowser.Navigate(@"http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php?l=zh-tw"); missionAssignedTime = DateTime.Now; querySend = false; } if (!querySend && webBrowser.ReadyState == WebBrowserReadyState.Complete) { missionAssignedTime = DateTime.Now; querySend = true; selectIDandDateThenDoQueryB(); } } printMissionList(); }