virtual protected string DownloadPage(string projectName, string scriptName, string paraStr) { DownloadPageAPI downloadPageAPI = new DownloadPageAPI(); string htmlString = downloadPageAPI.GetTextByCasperjs(projectName, scriptName, paraStr); return(htmlString); }
public DocDownloadStatus RefreshUrl() { if (IsDownoaded()) { _status = DocDownloadStatus.Downloaded; return(_status); } DownloadPageAPI downloadAPI = new DownloadPageAPI(); string reslink = downloadAPI.GetTextByCasperjs("doc.twse", "doc.t57sb01.js", _casperPara + " " + _docId); if (!reslink.StartsWith("<res>")) { //Todo: why return ""? Debug.WriteLine(reslink); } try { //Debug.WriteLine(reslink); XmlDocument resXml = new XmlDocument(); resXml.LoadXml(reslink); if (resXml != null) { string xpath = string.Format("/res/doc[@id='{0}']", _docId); XmlNode node = resXml.SelectSingleNode(xpath); if (node != null) { string url = node.InnerText; if (string.IsNullOrEmpty(url)) { _status = DocDownloadStatus.ServerBusy; Debug.WriteLine("ServerBusy : " + _docId); } else { _docUrl = url; _status = DocDownloadStatus.UrlReady; //_downloadingHandler.AddDownloadTask(this); Debug.WriteLine("Document URL: " + url); } } } else { _status = DocDownloadStatus.RefreshUrlFailed; } } catch (Exception e) { _status = DocDownloadStatus.RefreshUrlFailed; _lastError = e.Message; Debug.WriteLine(_lastError + reslink); } return(_status); }
public int ScanDocument() { if (_docCountNeedDownload == -1) { DownloadPageAPI downloadAPI = new DownloadPageAPI(); string paraStr = string.Format("{0} {1} {2} ", DocType, CompanyId, Year); string res = downloadAPI.GetTextByCasperjs("doc.twse", "doc.t57sb01.js", paraStr + "nofilter"); Debug.WriteLine(res); _docCountOnPage = 0; _docCountNeedDownload = 0; _docCountUrlReady = 0; _docCountDownloaded = 0; string[] pdfs = res.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); _docCountOnPage = pdfs.Length; foreach (string documentPdf in pdfs) { bool needDownload = false; string[] idname = documentPdf.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (idname.Length == 2) { if (FilterMonth.Count > 0) { foreach (string month in FilterMonth) { string docYearMonth = (Year + 1911).ToString() + month; if (idname[0].StartsWith(docYearMonth)) { needDownload = true; break; } } } else { needDownload = true; } if (needDownload) { DocDownloadTask task = new DocDownloadTask(idname[0], idname[1], _docType, _companyId, _downloadFolder, paraStr, _downloadingHandler); _docDownloadTasks.Add(task.DocId, task); _docCountNeedDownload++; _downloadingHandler.AddDownloadTask(task); } } } } return(_docCountNeedDownload); }