示例#1
0
 private void CallOneResourceDownloadedEvent(TumblrEventArgs e)
 {
     if (OnOneResourceDownloaded != null)
     {
         OnOneResourceDownloaded.Invoke(this, e);
     }
 }
示例#2
0
        private void UpdatePostListMethod(EventArgs e)
        {
            TumblrEventArgs ex = (TumblrEventArgs)e;
            //  MessageBox.Show(ex.TumblrPostURL);
            ListViewItem lvi = new ListViewItem(listView1.Items.Count.ToString());

            //  MessageBox.Show(listView1.Items.Count.ToString());
            listView1.Columns[0].Name = "tumPostIndex";
            listView1.Columns[1].Name = "tumPostID";
            listView1.Columns[2].Name = "tumPostURL";
            listView1.Columns[3].Name = "tumResCnt";
            listView1.Columns[4].Name = "parseErrors";
            //  lvi.SubItems.Add(listView1.Items.Count.ToString());
            lvi.SubItems.Add("未完成");
            lvi.SubItems.Add(ex.TumblrPostURL);
            lvi.SubItems.Add("未完成");
            lvi.SubItems.Add("未完成");

            listView1.Columns["tumPostIndex"].Text = "序号";
            listView1.Columns["tumPostID"].Text    = "PostID";
            listView1.Columns["tumPostURL"].Text   = "PostURL";
            listView1.Columns["tumResCnt"].Text    = "资源数量";
            listView1.Columns["parseErrors"].Text  = "错误";

            listView1.Items.Add(lvi);
            // label5.Text = ex.TumblrPostURL;
            // label5.Update();
            listView1.Update();
        }
示例#3
0
        private void UpdateDGVMethod(EventArgs e)
        {
            //查找传入的资源编号,更新显示
            TumblrEventArgs ex = (TumblrEventArgs)e;

            toolStripStatusLabel1.Text = ex.TumblrResourceIndex + "下载完成!";
            statusStrip1.Update();
            // MessageBox.Show(ex.TumblrResourceIndex + " / " + ex.TumblrResourceTime);
        }
示例#4
0
        public void StartDownLoad()
        {
            Console.WriteLine(System.Threading.Thread.CurrentThread.Name + "线程待下载资源数量是:" + ToDownRes.Count);
            if (ToDownRes.Count <TumblrResource>() > 0)
            {
                foreach (TumblrResource tr in ToDownRes)
                {
                    String   tumResFilePath   = Program.TumblrResourcesFolder + tr.ResourceName;
                    FileInfo tumResFileInfo   = new FileInfo(tumResFilePath);
                    long     tumContentLength = 0;
                    if (!tumResFileInfo.Exists)
                    {
                        if (true)
                        {
                            try
                            {
                                TumDownReq = tumDownProxy.GetHttpWebRequest(tr.ResourceURL);
                                TumDownRes = (HttpWebResponse)TumDownReq.GetResponse();
                                byte[] imageBuffer = new byte[Program.TumblrResourceBufferSize];
                                if (TumDownRes.StatusCode == HttpStatusCode.OK)
                                {
                                    tumStream        = TumDownRes.GetResponseStream();
                                    tumContentLength = TumDownRes.ContentLength;
                                    int    tumResSize_KB = (int)Math.Round((double)tumContentLength / 1024, 0);
                                    double tumResSize_MB = Math.Round((double)tumContentLength / 1024 / 1024, 2);
                                    if (tumResSize_KB < 10240)
                                    {
                                        TumblrResourceSize = tumResSize_KB + " KB";
                                    }
                                    else
                                    {
                                        TumblrResourceSize = tumResSize_MB + " MB";
                                    }

                                    Console.WriteLine("编号为" + tr.ResourceIndex + "资源长度: " + TumblrResourceSize);
                                    int        readSize  = tumStream.Read(imageBuffer, 0, imageBuffer.Length);
                                    int        filelenth = 0;
                                    FileStream tumFS     = new FileStream(tumResFilePath, FileMode.Create);
                                    while (readSize > 0)
                                    {
                                        tumFS.Write(imageBuffer, 0, readSize);
                                        filelenth = filelenth + readSize;
                                        readSize  = tumStream.Read(imageBuffer, 0, imageBuffer.Length);
                                        Console.WriteLine(System.Threading.Thread.CurrentThread.Name + "已写入长度: " + tumFS.Length);
                                    }


                                    tumFS.Close();
                                    tumStream.Close();
                                    TumblrEventArgs tea = new TumblrEventArgs();


                                    dbo.UpdateTumblrResourceItem(tr.ResourceIndex, tumContentLength.ToString(), DateTime.Now.ToString());
                                    tea.TumblrResourceDownloadStatus = "DN";
                                    tea.TumblrResourceIndex          = tr.ResourceIndex;
                                    tea.TumblrResourceSize           = this.TumblrResourceSize;
                                    tea.TumblrResourceTime           = DateTime.Now.ToString();
                                    CallOneResourceDownloadedEvent(tea);
                                }
                            }
                            catch (IOException e)
                            {
                                Console.WriteLine(System.Threading.Thread.CurrentThread.Name + "下载:" + tr.ResourceIndex + ",发生IO异常:" + e.Message);
                            }
                            catch (WebException e)
                            {
                                Console.WriteLine(System.Threading.Thread.CurrentThread.Name + "下载:" + tr.ResourceIndex + ",发生NET异常:" + e.Message);
                            }
                            finally
                            {
                                if (TumDownRes != null)
                                {
                                    TumDownRes.Close();
                                }
                                if (TumDownReq != null)
                                {
                                    TumDownReq.Abort();
                                }
                            }
                        }

                        /*
                         * else if (tr.ResourceType == "video")
                         * {
                         *
                         * }
                         */
                    }
                    else
                    {
                        //文件已存在
                    }
                }
            }
        }