internal void AsyncGetImageFile(object sender, AsyncGetImageEventArgs e) { string strError = ""; if (String.IsNullOrEmpty(e.RecPath) == true) { strError = "e.RecPath 为空,无法获得图像文件"; goto ERROR1; } if (StringUtil.HasHead(e.ObjectPath, "http:") == true) { EventFilter filter = new EventFilter(); // filter.BiblioRegister = biblioRegister; filter.Row = e.Row; filter.BiblioRecPath = e.RecPath; this._imageManager.AsyncGetObjectFile( "", "", e.ObjectPath, e.FileName, filter); } else { string strPath = ""; string strServerName = ""; StringUtil.ParseTwoPart(e.RecPath, "@", out strPath, out strServerName); AccountInfo account = _base.GetAccountInfo(strServerName, false); if (account == null) { strError = "e.RecPath 中 '" + e.RecPath + "' 服务器名 '" + strServerName + "' 没有配置"; goto ERROR1; } string strServerUrl = account.ServerUrl; string strUserName = account.UserName; if (EntityRegisterBase.IsDot(strServerUrl) == true) strServerUrl = this.MainForm.LibraryServerUrl; if (EntityRegisterBase.IsDot(strUserName) == true) strUserName = this.MainForm.DefaultUserName; EventFilter filter = new EventFilter(); // filter.BiblioRegister = biblioRegister; filter.Row = e.Row; filter.BiblioRecPath = e.RecPath; // string strObjectPath = strPath + "/object/" + e.ObjectPath; string strObjectPath = ScriptUtil.MakeObjectUrl(strPath, e.ObjectPath); this._imageManager.AsyncGetObjectFile(strServerUrl, strUserName, strObjectPath, e.FileName, filter); } return; ERROR1: this.AsyncGetImageComplete(e.Row, "", null, strError); }
// public event AsyncGetImageEventHandler AsyncGetImage = null; // bool CoverImageRequested = false; // 如果为 true ,表示已经请求了异步获取图像,不要重复请求 // 准备特定浏览行的封面图像 // parameters: // bRetry 是否为重试?如果为 true,表示即便 info.CoverImageRquested == true 也要重做 void PrepareCoverImage(DpRow row, bool bRetry = false) { Debug.Assert(row != null, ""); RegisterBiblioInfo info = row.Tag as RegisterBiblioInfo; if (info == null) return; if (string.IsNullOrEmpty(info.CoverImageFileName) == false) return; if (string.IsNullOrEmpty(info.OldXml) == true) return; string strUrl = ""; { string strError = ""; string strMARC = ""; string strMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 int nRet = MarcUtil.Xml2Marc(info.OldXml, true, null, out strMarcSyntax, out strMARC, out strError); if (nRet == -1) { Debug.Assert(false, ""); return; } if (string.IsNullOrEmpty(strMARC) == true) return; strUrl = ScriptUtil.GetCoverImageUrl(strMARC); if (string.IsNullOrEmpty(strUrl) == true) return; } #if NO if (StringUtil.HasHead(strUrl, "http:") == true) return; #endif if (info != null && bRetry == false && info.CoverImageRquested == true) return; // 通过 dp2library 协议获得图像文件 // if (this.AsyncGetImage != null) { AsyncGetImageEventArgs e = new AsyncGetImageEventArgs(); e.RecPath = row[1].Text; e.ObjectPath = strUrl; e.FileName = ""; e.Row = row; this.AsyncGetImageFile(this, e); // 修改状态,表示已经发出请求 if (row != null && info != null) { info.CoverImageRquested = true; } } }
void _biblioRegister_AsyncGetImage(object sender, AsyncGetImageEventArgs e) { EntityRegisterControl container = this.Container as EntityRegisterControl; BiblioRegisterControl biblioRegister = sender as BiblioRegisterControl; container.AsyncGetImageFile(biblioRegister, e); }
// 设置特定浏览行的封面图像 void SetCoverImage(DpRow row) { RegisterBiblioInfo info = row.Tag as RegisterBiblioInfo; if (info == null) goto CLEAR; string strMARC = info.OldXml; if (string.IsNullOrEmpty(strMARC) == true) goto CLEAR; string strUrl = ScriptUtil.GetCoverImageUrl(strMARC); if (string.IsNullOrEmpty(strUrl) == true) goto CLEAR; #if NO if (StringUtil.HasHead(strUrl, "http:") == true) this.pictureBox1.LoadAsync(strUrl); else { if (string.IsNullOrEmpty(info.CoverImageFileName) == false) this.pictureBox1.LoadAsync(info.CoverImageFileName); else { // 通过 dp2library 协议获得图像文件 if (this.AsyncGetImage != null) { string strBiblioRecPath = row[1].Text; AsyncGetImageEventArgs e = new AsyncGetImageEventArgs(); e.RecPath = strBiblioRecPath; e.ObjectPath = strUrl; e.FileName = ""; e.Row = row; this.AsyncGetImage(this, e); } } } #endif // 设置封面图像 // 按照这样的次序:1) 如果是 http: 直接设置; 2) 如果有本地文件,直接设置; 3) 从服务器获取,然后异步设置 SetCoverImage(strUrl, info.CoverImageFileName, row[1].Text, row); return; CLEAR: this.pictureBox1.Image = null; }
// 设置封面图像 // 按照这样的次序:1) 如果是 http: 直接设置; 2) 如果有本地文件,直接设置; 3) 从服务器获取,然后异步设置 void SetCoverImage(string strUrl, string strLocalImageFileName, string strBiblioRecPath, DpRow row) { if (StringUtil.HasHead(strUrl, "http:") == true) this.pictureBox1.LoadAsync(strUrl); else { if (string.IsNullOrEmpty(strLocalImageFileName) == false) this.pictureBox1.LoadAsync(strLocalImageFileName); else { RegisterBiblioInfo info = null; if (row != null) info = row.Tag as RegisterBiblioInfo; if (info != null && info.CoverImageRquested == true) return; // 通过 dp2library 协议获得图像文件 if (this.AsyncGetImage != null) { AsyncGetImageEventArgs e = new AsyncGetImageEventArgs(); e.RecPath = strBiblioRecPath; e.ObjectPath = strUrl; e.FileName = ""; e.Row = row; this.AsyncGetImage(this, e); // 修改状态,表示已经发出请求 if (row != null) { if (info != null) info.CoverImageRquested = true; } else { this.CoverImageRequested = true; } } } } }
// 准备特定浏览行的封面图像 void PrepareCoverImage(DpRow row) { Debug.Assert(row != null, ""); RegisterBiblioInfo info = row.Tag as RegisterBiblioInfo; if (info == null) return; if (string.IsNullOrEmpty(info.CoverImageFileName) == false) return; string strMARC = info.OldXml; if (string.IsNullOrEmpty(strMARC) == true) return; string strUrl = ScriptUtil.GetCoverImageUrl(strMARC); if (string.IsNullOrEmpty(strUrl) == true) return; if (StringUtil.HasHead(strUrl, "http:") == true) return; if (info != null && info.CoverImageRquested == true) return; // 通过 dp2library 协议获得图像文件 if (this.AsyncGetImage != null) { AsyncGetImageEventArgs e = new AsyncGetImageEventArgs(); e.RecPath = row[1].Text; e.ObjectPath = strUrl; e.FileName = ""; e.Row = row; this.AsyncGetImage(this, e); // 修改状态,表示已经发出请求 if (row != null) { if (info != null) info.CoverImageRquested = true; } else { this.CoverImageRequested = true; } } }