예제 #1
0
파일: ImageManager.cs 프로젝트: zszqwe/dp2
        // 加入一个获取对象文件的请求
        // parameters:
        //      strFileName 临时文件名。可为空,功能中会自动给出一个临时文件名
        public void AsyncGetObjectFile(string strServerUrl,
                                       string strUserName,
                                       string strObjectPath,
                                       string strFileName,
                                       object tag)
        {
            TraceObject trace = new TraceObject();

            trace.ServerUrl  = strServerUrl;
            trace.UserName   = strUserName;
            trace.ObjectPath = strObjectPath;
            trace.FileName   = strFileName;
            trace.Tag        = tag;
            lock (_trace_images)
            {
                _trace_images.Add(trace);
            }
        }
예제 #2
0
파일: ImageManager.cs 프로젝트: zszqwe/dp2
        // 下载图像文件
        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);
            }
        }
예제 #3
0
 // 加入一个获取对象文件的请求
 // parameters:
 //      strFileName 临时文件名。可为空,功能中会自动给出一个临时文件名
 public void AsyncGetObjectFile(string strServerUrl,
     string strUserName,
     string strObjectPath,
     string strFileName,
     object tag)
 {
     TraceObject trace = new TraceObject();
     trace.ServerUrl = strServerUrl;
     trace.UserName = strUserName;
     trace.ObjectPath = strObjectPath;
     trace.FileName = strFileName;
     trace.Tag = tag;
     lock (_trace_images)
     {
         _trace_images.Add(trace);
     }
 }