예제 #1
0
        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);
        }
예제 #2
0
        public List <BasicDailyDataMission> getMissionList(bool readAll)
        {
            var resultList = new List <BasicDailyDataMission>();

            foreach (var currentStock in stockList)
            {
                int currentYear  = startYear;
                int currentMonth = startMonth;
                while (currentYear < DateTime.Now.Year ||
                       (currentYear == DateTime.Now.Year && currentMonth <= DateTime.Now.Month))
                {
                    var toAdd = new BasicDailyDataMission()
                    {
                        ID    = currentStock.ID,
                        type  = currentStock.type,
                        month = currentMonth,
                        year  = currentYear
                    };

                    if (!readAll)
                    {
                        var fileStatus = Core.basicDailyDataManager.getFileStatus(currentStock.ID);
                        int index      = fileStatus.BinarySearch(new BasicDailyDataFileStatusInformation()
                        {
                            year = currentYear.ToString(), month = currentMonth.ToString()
                        });
                        if (index < 0
                            ||
                            index >= 0 &&
                            (
                                (
                                    fileStatus[index].fileStatus == FileStatus.Temp
                                    ||
                                    (
                                        fileStatus[index].fileStatus == FileStatus.Null
                                        &&
                                        index >= fileStatus.Count() - 1
                                    )
                                ) &&
                                fileStatus[index].modifiedTime.getDateTimeFromString()
                                .ToString("yyyyMMdd") !=
                                DateTime.Now.ToString("yyyyMMdd")
                                ||
                                (
                                    fileStatus[index].modifiedTime.getDateTimeFromString()
                                    .ToString("yyyyMMdd") ==
                                    DateTime.Now.ToString("yyyyMMdd")
                                    &&
                                    fileStatus[index].modifiedTime.getDateTimeFromString().Hour < 16
                                    &&
                                    DateTime.Now.Hour >= 16
                                )
                            )
                            )
                        {
                            resultList.Add(toAdd);
                        }
                    }
                    else
                    {
                        resultList.Add(toAdd);
                    }

                    currentMonth++;
                    if (currentMonth > 12)
                    {
                        currentMonth = 1;
                        currentYear++;
                    }
                }
            }
            return(resultList);
        }
예제 #3
0
        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();
        }