private void listViewDocuments_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            if (_downloadingHandler.DocumentsList.Count > 0)
            {
                DocDownloadTask task    = _downloadingHandler.DocumentsList[e.ItemIndex];
                int             nNumber = e.ItemIndex + 1;
                ListViewItem    lv      = new ListViewItem(nNumber.ToString());
                lv.SubItems.Add(task.DocId);
                lv.SubItems.Add(task.FundName);
                if (task.Status == DocDownloadStatus.Downloading)
                {
                    lv.SubItems.Add(task.Percentage);
                }
                else
                {
                    lv.SubItems.Add(task.Status.ToString());
                }
                lv.SubItems.Add(_documentTypeList[task.DocType]);
                lv.SubItems.Add(string.Format("{0}-{1}", task.CompanyId, _companyList[task.CompanyId]));
                //if (task.DownloadFailedTimes > 0)
                //    lv.SubItems.Add(task.DownloadFailedTimes.ToString());
                //else
                //    lv.SubItems.Add("");
                lv.SubItems.Add(task.DocUrl);

                e.Item = lv;
            }
        }
示例#2
0
 public void Clear()
 {
     while (!documentQueue.IsEmpty)
     {
         DocDownloadTask task = null;
         documentQueue.TryDequeue(out task);
     }
     aryDocuments.Clear();
 }
示例#3
0
        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);
        }
示例#4
0
        private void ThreadDownloadDocument()
        {
            try
            {
                DocDownloadTask task = null;

                while (documentQueue.TryDequeue(out task))
                {
                    Debug.WriteLine("Task {0} started...", task.DocId);


                    if (task.Status == DocDownloadStatus.New ||
                        task.Status == DocDownloadStatus.ServerBusy ||
                        task.Status == DocDownloadStatus.RefreshUrlFailed ||
                        task.Status == DocDownloadStatus.DownloadFailed)
                    {
                        if (task.RefreshUrl() != DocDownloadStatus.UrlReady)
                        {
                            documentQueue.Enqueue(task);
                            continue;
                        }
                        //_docCountUrlReady++;
                    }

                    if (task.Status == DocDownloadStatus.UrlReady)
                    {
                        if (task.Download() == DocDownloadStatus.Downloaded)
                        {
                            //ownerForm.Refresh();
                        }
                        else
                        {
                            documentQueue.Enqueue(task);
                        }
                    }

                    Debug.WriteLine("Task {0} ended.", task.DocId);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#5
0
 public CURLWrapper(DocDownloadTask task)
 {
     _task = task;
 }
示例#6
0
 public void AddDownloadTask(DocDownloadTask Task)
 {
     documentQueue.Enqueue(Task);
     aryDocuments.Add(Task);
     Debug.WriteLine(string.Format("Doc Enqueue({0}) : {1}", documentQueue.Count, Task.DocId));
 }