// 下载图像文件 void DownloadImages() { string strError = ""; TraceObject info = null; lock (_trace_images) { if (_trace_images.Count == 0) { return; } info = _trace_images[0]; _trace_images.RemoveAt(0); } if (string.IsNullOrEmpty(info.FileName) == true) { info.FileName = GetTempFileName(); } // http 协议的图像文件 if (StringUtil.IsHttpUrl(info.ObjectPath) == true) { // 先从 cache 中找 if (_localFileCache != null) { string strLocalFile = (string)_localFileCache[info.ObjectPath]; if (string.IsNullOrEmpty(strLocalFile) == false) { if (string.IsNullOrEmpty(info.FileName) == false) { DeleteTempFile(info.FileName); info.FileName = ""; } info.FileName = strLocalFile; goto END1; } } 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.ObjectPath, 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; goto ERROR1; } } } strError = ex.Message; goto ERROR1; } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); goto ERROR1; } _localFileCache[info.ObjectPath] = info.FileName; } else { // dp2library 协议的对象资源 LibraryChannel channel = this.ChannelPool.GetChannel(info.ServerUrl, info.UserName); try { byte[] baOutputTimeStamp = null; string strMetaData = ""; string strTempOutputPath = ""; long lRet = channel.GetRes( null, info.ObjectPath, info.FileName, "content,data,metadata,timestamp,outputpath,gzip", // 2017/10/7 增加 gzip out strMetaData, out baOutputTimeStamp, out strTempOutputPath, out strError); if (lRet == -1) { strError = "下载资源文件失败,原因: " + strError; goto ERROR1; } _localFileCache[info.ObjectPath] = info.FileName; } finally { this.ChannelPool.ReturnChannel(channel); // 2016/6/6 } } END1: // 通知 if (this.GetObjectComplete != null) { GetObjectCompleteEventArgs e = new GetObjectCompleteEventArgs(); e.TraceObject = info; this.GetObjectComplete(this, e); } this.Activate(); return; ERROR1: // 通知 if (this.GetObjectComplete != null) { GetObjectCompleteEventArgs e = new GetObjectCompleteEventArgs(); e.TraceObject = info; e.ErrorInfo = strError; this.GetObjectComplete(this, e); } }
// 下载图像文件 void DownloadImages() { string strError = ""; TraceObject info = null; lock (_trace_images) { if (_trace_images.Count == 0) return; info = _trace_images[0]; _trace_images.RemoveAt(0); } if (string.IsNullOrEmpty(info.FileName) == true) info.FileName = GetTempFileName(); // http 协议的图像文件 if (StringUtil.HasHead(info.ObjectPath, "http:") == true) { // 先从 cache 中找 if (_localFileCache != null) { string strLocalFile = (string)_localFileCache[info.ObjectPath]; if (string.IsNullOrEmpty(strLocalFile) == false) { if (string.IsNullOrEmpty(info.FileName) == false) { DeleteTempFile(info.FileName); info.FileName = ""; } info.FileName = strLocalFile; goto END1; } } 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.ObjectPath, 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; goto ERROR1; } } } strError = ex.Message; goto ERROR1; } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); goto ERROR1; } _localFileCache[info.ObjectPath] = info.FileName; } else { // dp2library 协议的对象资源 LibraryChannel channel = this.ChannelPool.GetChannel(info.ServerUrl, info.UserName); try { byte[] baOutputTimeStamp = null; string strMetaData = ""; string strTempOutputPath = ""; long lRet = channel.GetRes( null, info.ObjectPath, info.FileName, out strMetaData, out baOutputTimeStamp, out strTempOutputPath, out strError); if (lRet == -1) { strError = "下载资源文件失败,原因: " + strError; goto ERROR1; } _localFileCache[info.ObjectPath] = info.FileName; } finally { this.ChannelPool.ReturnChannel(channel); // 2016/6/6 } } END1: // 通知 if (this.GetObjectComplete != null) { GetObjectCompleteEventArgs e = new GetObjectCompleteEventArgs(); e.TraceObject = info; this.GetObjectComplete(this, e); } this.Activate(); return; ERROR1: // 通知 if (this.GetObjectComplete != null) { GetObjectCompleteEventArgs e = new GetObjectCompleteEventArgs(); e.TraceObject = info; e.ErrorInfo = strError; this.GetObjectComplete(this, e); } }