Beispiel #1
0
        TraceImage _info = null;    // 事件之间传递信息
        void DownloadImages()
        {
            if (_trace_images.Count == 0)
            {
                return;
            }

            _info = _trace_images[0];
            _trace_images.RemoveAt(0);

            _info.FileName = GetTempFileName();

            string strError = "";

            if (_webClient == null)
            {
                _webClient = new WebClient();
            }

            _webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_downloadFileCompleted);
            try
            {
                _webClient.DownloadFileAsync(new Uri(_info.ImageUrl, UriKind.Absolute),
                                             _info.FileName, null);
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                _info.Row[COLUMN_IMAGE].Text = strError;
            }
        }
Beispiel #2
0
        void SetErrorText(TraceImage info, string strError)
        {
            if (this.dpTable_items.InvokeRequired)
            {
                this.dpTable_items.Invoke(new Action <TraceImage, string>(SetErrorText), info, strError);
                return;
            }

            info.Row[COLUMN_IMAGE].Text      = strError;
            info.Row[COLUMN_IMAGE].OwnerDraw = false;
        }
Beispiel #3
0
        void AddTraceItem(DpRow row)
        {
            AmazonBiblioInfo info = row.Tag as AmazonBiblioInfo;

            if (info != null && string.IsNullOrEmpty(info.ImageUrl) == false)
            {
                TraceImage trace = new TraceImage();
                trace.ImageUrl = info.ImageUrl;
                trace.Row      = row;
                lock (_trace_images)
                {
                    _trace_images.Add(trace);
                }
            }
        }
Beispiel #4
0
        TraceImage _info = null;    // 事件之间传递信息
        void DownloadImages()
        {
            if (_trace_images.Count == 0)
                return;

            _info = _trace_images[0];
            _trace_images.RemoveAt(0);

            _info.FileName = GetTempFileName();

            string strError = "";
            if (_webClient == null)
                _webClient = new WebClient();

            _webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_downloadFileCompleted);
            try
            {
                _webClient.DownloadFileAsync(new Uri(_info.ImageUrl, UriKind.Absolute),
                    _info.FileName, null);
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                _info.Row[COLUMN_IMAGE].Text = strError;
            }
        }
Beispiel #5
0
        void SetErrorText(TraceImage info, string strError)
        {
            if (this.dpTable_items.InvokeRequired)
            {
                this.dpTable_items.Invoke(new Action<TraceImage, string>(SetErrorText), info, strError);
                return;
            }

            info.Row[COLUMN_IMAGE].Text = strError;
            info.Row[COLUMN_IMAGE].OwnerDraw = false;
        }
Beispiel #6
0
 void AddTraceItem(DpRow row)
 {
     AmazonBiblioInfo info = row.Tag as AmazonBiblioInfo;
     if (info != null && string.IsNullOrEmpty(info.ImageUrl) == false)
     {
         TraceImage trace = new TraceImage();
         trace.ImageUrl = info.ImageUrl;
         trace.Row = row;
         lock (_trace_images)
         {
             _trace_images.Add(trace);
         }
     }
 }
Beispiel #7
0
        // 加入一个浏览行
        public void AddBiblioBrowseLine(
            string strBiblioRecPath,
            string strBrowseText,
            AmazonBiblioInfo info)
        {
            if (this.dpTable_items.InvokeRequired)
            {
                // 事件是在多线程上下文中触发的,需要 Invoke 显示信息
                this.BeginInvoke(new Action<string, string, AmazonBiblioInfo>(AddBiblioBrowseLine),
                    strBiblioRecPath,
                    strBrowseText,
                    info);
                return;
            }

            // 检查已经存在的最后一行是否为命令行
            if (this.dpTable_items.Rows.Count > 0)
            {
                DpRow tail = this.dpTable_items.Rows[this.dpTable_items.Rows.Count - 1];
                if (string.IsNullOrEmpty(tail[0].Text) == true)
                    this.dpTable_items.Rows.RemoveAt(this.dpTable_items.Rows.Count - 1);
            }

            List<string> columns = StringUtil.SplitList(strBrowseText, '\t');
            DpRow row = new DpRow();
            row.LineAlignment = StringAlignment.Center;

            DpCell cell = new DpCell();
            cell.Text = (this.dpTable_items.Rows.Count + 1).ToString();
            cell.Font = this._idFont;
            cell.ForeColor = SystemColors.GrayText;
            row.Add(cell);

#if NO
            cell = new DpCell();
            cell.Text = strBiblioRecPath;
            row.Add(cell);
#endif

            cell = new DpCell();
            // cell.Text = info.ImageUrl;
            // cell.Text = "正在加载图片 ...";
            row.Add(cell);

            int i = 0;
            foreach (string s in columns)
            {
                cell = new DpCell();
                cell.Text = s;
                if (i == 0)
                    cell.Font = this._titleFont;

                row.Add(cell);
                i++;
            }

            row.Tag = info;
            // row[COLUMN_IMAGE].OwnerDraw = true;

            this.dpTable_items.Rows.Add(row);

#if NO
            if (string.IsNullOrEmpty(info.ImageUrl) == false)
            {
                TraceImage trace = new TraceImage();
                trace.ImageUrl = info.ImageUrl;
                trace.Row = row;
                lock (_trace_images)
                {
                    _trace_images.Add(trace);
                }
            }
#endif
            AddTraceItem(row);
        }
Beispiel #8
0
        // 下载图像文件。因为在线程中使用,所以使用同步的版本就行
        void DownloadImages()
        {
            TraceImage info = null;

            lock (_trace_images)
            {
                if (_trace_images.Count == 0)
                {
                    return;
                }

                info = _trace_images[0];
                _trace_images.RemoveAt(0);
            }

            info.FileName = GetTempFileName();

            string strError = "";

            if (_webClient == null)
            {
                _webClient             = new MyWebClient();
                _webClient.Timeout     = 5000;
                _webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.CacheIfAvailable);
            }

            try
            {
                _webClient.DownloadFile(new Uri(info.ImageUrl, UriKind.Absolute), info.FileName);
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = ex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        if (response.StatusCode == HttpStatusCode.NotFound)
                        {
                            strError = ex.Message;
                            SetErrorText(info, strError);
                            goto END1;
                        }
                    }
                }

                strError = ex.Message;
                SetErrorText(info, strError);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                SetErrorText(info, strError);
#if NO
                info.Row[COLUMN_IMAGE].Text      = strError;
                info.Row[COLUMN_IMAGE].OwnerDraw = false;
#endif
            }

            if (this.IsDisposed == true || this.Visible == false ||
                info == null)
            {
                return;
            }

            // _info.Row[COLUMN_IMAGE].Image = Image.FromFile(_info.FileName);
            SetImage(info.Row[COLUMN_IMAGE], info.FileName);
END1:
            this.ActivateThread();
        }
Beispiel #9
0
        // 加入一个浏览行
        public void AddBiblioBrowseLine(
            string strBiblioRecPath,
            string strBrowseText,
            AmazonBiblioInfo info)
        {
            if (this.dpTable_items.InvokeRequired)
            {
                // 事件是在多线程上下文中触发的,需要 Invoke 显示信息
                this.BeginInvoke(new Action <string, string, AmazonBiblioInfo>(AddBiblioBrowseLine),
                                 strBiblioRecPath,
                                 strBrowseText,
                                 info);
                return;
            }

            // 检查已经存在的最后一行是否为命令行
            if (this.dpTable_items.Rows.Count > 0)
            {
                DpRow tail = this.dpTable_items.Rows[this.dpTable_items.Rows.Count - 1];
                if (string.IsNullOrEmpty(tail[0].Text) == true)
                {
                    this.dpTable_items.Rows.RemoveAt(this.dpTable_items.Rows.Count - 1);
                }
            }

            List <string> columns = StringUtil.SplitList(strBrowseText, '\t');
            DpRow         row     = new DpRow();

            row.LineAlignment = StringAlignment.Center;

            DpCell cell = new DpCell();

            cell.Text      = (this.dpTable_items.Rows.Count + 1).ToString();
            cell.Font      = this._idFont;
            cell.ForeColor = SystemColors.GrayText;
            row.Add(cell);

#if NO
            cell      = new DpCell();
            cell.Text = strBiblioRecPath;
            row.Add(cell);
#endif

            cell = new DpCell();
            // cell.Text = info.ImageUrl;
            // cell.Text = "正在加载图片 ...";
            row.Add(cell);

            int i = 0;
            foreach (string s in columns)
            {
                cell      = new DpCell();
                cell.Text = s;
                if (i == 0)
                {
                    cell.Font = this._titleFont;
                }

                row.Add(cell);
                i++;
            }

            row.Tag = info;
            // row[COLUMN_IMAGE].OwnerDraw = true;

            this.dpTable_items.Rows.Add(row);

#if NO
            if (string.IsNullOrEmpty(info.ImageUrl) == false)
            {
                TraceImage trace = new TraceImage();
                trace.ImageUrl = info.ImageUrl;
                trace.Row      = row;
                lock (_trace_images)
                {
                    _trace_images.Add(trace);
                }
            }
#endif
            AddTraceItem(row);
        }