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 DocDownloadTask(string docId, string name, string docType, string companyId, string downloadFolder, string para, DownloadTaskHandler handler) { _docId = docId; _name = name; _casperPara = para; _downloadingHandler = handler; _docType = docType; _companyId = companyId; _downloadFolder = downloadFolder; _status = DocDownloadStatus.New; _downloadFailedTimes = 0; _percentage = ""; }
public DocDownloadStatus Download() { Debug.WriteLine(string.Format("Downloaded: {0}", _docId)); if (IsDownoaded()) { _status = DocDownloadStatus.Downloaded; return(_status); } if (!string.IsNullOrEmpty(DocUrl)) { try { _status = DocDownloadStatus.Downloading; string path = _downloadFolder + "\\" + _docId; //WebClient myWebClient = new WebClient(); //myWebClient.DownloadFile(DocUrl, path); CURLWrapper curl = new CURLWrapper(this); if (curl.DownloadStaticURL(DocUrl, path)) { _status = DocDownloadStatus.Downloaded; } else { _status = DocDownloadStatus.DownloadFailed; } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); _downloadFailedTimes++; _status = DocDownloadStatus.DownloadFailed; } } return(_status); }