ServerDlg SetDefaultAccount( string strServerUrl, string strTitle, string strComment, IWin32Window owner) { dp2Server server = this.MainForm.Servers[strServerUrl]; ServerDlg dlg = new ServerDlg(); GuiUtil.SetControlFont(dlg, this.Font); if (String.IsNullOrEmpty(strServerUrl) == true) { } else { dlg.ServerUrl = strServerUrl; } if (owner == null) { owner = this; } if (String.IsNullOrEmpty(strTitle) == false) { dlg.Text = strTitle; } dlg.Comment = strComment; dlg.UserName = server.DefaultUserName; this.MainForm.AppInfo.LinkFormState(dlg, "dp2_logindlg_state"); dlg.ShowDialog(owner); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == DialogResult.Cancel) { return(null); } server.DefaultUserName = dlg.UserName; server.DefaultPassword = (dlg.SavePassword == true) ? dlg.Password : ""; server.SavePassword = dlg.SavePassword; server.Url = dlg.ServerUrl; return(dlg); }
void Channels_AfterLogin(object sender, AfterLoginEventArgs e) { LibraryChannel channel = (LibraryChannel)sender; dp2Server server = this.MainForm.Servers[channel.Url]; if (server == null) { // e.ErrorInfo = "没有找到 URL 为 " + channel.Url + " 的服务器对象"; return; } #if SN if (server.Verified == false && StringUtil.IsInList("serverlicensed", channel.Rights) == false) { string strError = ""; string strTitle = "修改密码窗需要先设置序列号才能访问服务器 " + server.Name + " " + server.Url; int nRet = this.MainForm.VerifySerialCode(strTitle, "", true, out strError); if (nRet == -1) { channel.Close(); e.ErrorInfo = strTitle; #if NO MessageBox.Show(this.MainForm, "修改密码窗需要先设置序列号才能使用"); API.PostMessage(this.Handle, API.WM_CLOSE, 0, 0); #endif return; } } server.Verified = true; #else server.Verified = true; #endif }
// 检索 // return: // -1 error // 0 succeed public int DoSearch(string strProjectName, string strRecPath, string strXml, out string strUsedProjectName, out string strError) { strError = ""; strUsedProjectName = ""; if (strProjectName == "<默认>" || strProjectName == "<default>") { strProjectName = ""; } EventFinish.Reset(); EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在进行查重 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); try { this.ClearDupState(true); this.listView_browse.Items.Clear(); // 获得server url if (String.IsNullOrEmpty(this.LibraryServerName) == true) { strError = "尚未指定服务器名"; goto ERROR1; } dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName); if (server == null) { strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在..."; goto ERROR1; } this.SortColumns.Clear(); SortColumns.ClearColumnSortDisplay(this.listView_browse.Columns); string strBrowseStyle = "cols"; if (this.checkBox_includeLowCols.Checked == false) { strBrowseStyle += ",excludecolsoflowthreshold"; } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); long lRet = Channel.SearchDup( stop, strRecPath, strXml, strProjectName, "includeoriginrecord", // includeoriginrecord out strUsedProjectName, out strError); if (lRet == -1) { goto ERROR1; } long lHitCount = lRet; if (lHitCount == 0) { goto END1; // 查重发现没有命中 } long lStart = 0; long lPerCount = Math.Min(50, lHitCount); // 装入浏览格式 for (; ;) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } stop.SetMessage("正在装入浏览信息 " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ..."); lRet = Channel.GetDupSearchResult( stop, lStart, lPerCount, strBrowseStyle, // "cols,excludecolsoflowthreshold", out DupSearchResult[] searchresults, out strError); if (lRet == -1) { goto ERROR1; } if (lRet == 0) { break; } Debug.Assert(searchresults != null, ""); // 处理浏览结果 for (int i = 0; i < searchresults.Length; i++) { DupSearchResult result = searchresults[i]; ListViewUtil.EnsureColumns(this.listView_browse, 2 + (result.Cols == null ? 0 : result.Cols.Length), 200); if (this.checkBox_returnAllRecords.Checked == false) { // 遇到第一个权值较低的,就中断全部获取浏览过程 if (result.Weight < result.Threshold) { goto END1; } } /* * if (result.Cols == null) * { * strError = "返回的结果行错误 result.Cols == null"; * goto ERROR1; * } * * ListViewUtil.EnsureColumns(this.listView_browse, * 2 + result.Cols.Length, * 200); * */ ListViewItem item = new ListViewItem(); item.Text = result.Path; item.Tag = result; item.SubItems.Add(result.Weight.ToString()); if (result.Cols != null) { for (int j = 0; j < result.Cols.Length; j++) { item.SubItems.Add(result.Cols[j]); } } this.listView_browse.Items.Add(item); if (item.Text == this.RecordPath) { // 如果就是发起记录自己 2008/2/29 item.ImageIndex = ITEMTYPE_OVERTHRESHOLD; item.BackColor = Color.LightGoldenrodYellow; item.ForeColor = SystemColors.GrayText; // 表示就是发起记录自己 } else if (result.Weight >= result.Threshold) { item.ImageIndex = ITEMTYPE_OVERTHRESHOLD; item.BackColor = Color.LightYellow; item.Font = new Font(item.Font, FontStyle.Bold); } else { item.ImageIndex = ITEMTYPE_NORMAL; } } lStart += searchresults.Length; if (lStart >= lHitCount || lPerCount <= 0) { break; } } END1: this.SetDupState(); return((int)lHitCount); } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EventFinish.Set(); EnableControls(true); } ERROR1: return(-1); }
void Channels_BeforeLogin(object sender, BeforeLoginEventArgs e) { LibraryChannel channel = (LibraryChannel)sender; dp2Server server = this.MainForm.Servers[channel.Url]; if (server == null) { e.ErrorInfo = "没有找到 URL 为 " + channel.Url + " 的服务器对象"; e.Failed = true; e.Cancel = true; return; } if (e.FirstTry == true) { e.UserName = server.DefaultUserName; e.Password = server.DefaultPassword; e.Parameters = "location=dp2Catalog,type=worker"; /* * e.IsReader = false; * e.Location = "dp2Catalog"; * */ // 2014/9/13 e.Parameters += ",mac=" + StringUtil.MakePathList(SerialCodeForm.GetMacAddress(), "|"); #if SN // 从序列号中获得 expire= 参数值 string strExpire = this.MainForm.GetExpireParam(); if (string.IsNullOrEmpty(strExpire) == false) { e.Parameters += ",expire=" + strExpire; } #endif e.Parameters += ",client=dp2catalog|" + Program.ClientVersion; if (String.IsNullOrEmpty(e.UserName) == false) { return; // 立即返回, 以便作第一次 不出现 对话框的自动登录 } } // IWin32Window owner = this; ServerDlg dlg = SetDefaultAccount( e.LibraryServerUrl, null, e.ErrorInfo, owner); if (dlg == null) { e.Cancel = true; return; } e.UserName = dlg.UserName; e.Password = dlg.Password; e.SavePasswordShort = false; e.Parameters = "location=dp2Catalog,type=worker"; e.Parameters += ",client=dp2catalog|" + Program.ClientVersion; /* * e.IsReader = false; * e.Location = "dp2Catalog"; * */ e.SavePasswordLong = true; e.LibraryServerUrl = dlg.ServerUrl; }
int GetBrowseCols(List <string> pathlist, List <ListViewItem> itemlist, out string strError) { strError = ""; // 获得server url if (String.IsNullOrEmpty(this.LibraryServerName) == true) { strError = "尚未指定服务器名"; return(-1); } dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName); if (server == null) { strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在..."; return(-1); } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在填充浏览列 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); try { int nStart = 0; int nCount = 0; for (; ;) { nCount = pathlist.Count - nStart; if (nCount > 100) { nCount = 100; } if (nCount <= 0) { break; } Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; return(-1); } } stop.SetMessage("正在装入浏览信息 " + (nStart + 1).ToString() + " - " + (nStart + nCount).ToString()); string[] paths = new string[nCount]; pathlist.CopyTo(nStart, paths, 0, nCount); DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null; long lRet = this.Channel.GetBrowseRecords( this.stop, paths, "id,cols", out searchresults, out strError); if (lRet == -1) { return(-1); } if (searchresults == null || searchresults.Length == 0) { strError = "searchresults == null || searchresults.Length == 0"; return(-1); } for (int i = 0; i < searchresults.Length; i++) { DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i]; ListViewUtil.EnsureColumns(this.listView_browse, 2 + (record.Cols == null ? 0 : record.Cols.Length), 200); ListViewItem item = itemlist[nStart + i]; item.Text = record.Path; if (record.Cols != null) { for (int j = 0; j < record.Cols.Length; j++) { item.SubItems.Add(record.Cols[j]); } } } nStart += searchresults.Length; } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); } return(0); }
// 列出可用的查重方案名 public int ListProjectNames(string strPureRecPath, out string[] projectnames, out string strError) { strError = ""; projectnames = null; EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获取可用的查重方案名 ..."); stop.BeginLoop(); try { // 获得server url if (String.IsNullOrEmpty(this.LibraryServerName) == true) { strError = "尚未指定服务器名"; goto ERROR1; } dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName); if (server == null) { strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在..."; goto ERROR1; } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); DupProjectInfo[] dpis = null; string strBiblioDbName = dp2SearchForm.GetDbName(strPureRecPath); long lRet = Channel.ListDupProjectInfos( stop, strBiblioDbName, out dpis, out strError); if (lRet == -1) { goto ERROR1; } projectnames = new string[dpis.Length]; for (int i = 0; i < projectnames.Length; i++) { projectnames[i] = dpis[i].Name; } return((int)lRet); } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); } ERROR1: return(-1); }
public IEnumerator GetEnumerator() { // 首先按照服务器名的不同,划分为若干个区段 List <OneBatch> batchs = new List <OneBatch>(); { OneBatch batch = new OneBatch(); for (int index = 0; index < m_recpaths.Count; index++) { string s = m_recpaths[index]; // 解析记录路径 string strServerName = ""; string strPurePath = ""; dp2SearchForm.ParseRecPath(s, out strServerName, out strPurePath); // 服务器名发生变化了 if (batch.Count > 0 && strServerName != batch.ServerName) { batchs.Add(batch); batch = new OneBatch(); batch.ServerName = strServerName; batch.Add(strPurePath); continue; } if (string.IsNullOrEmpty(batch.ServerName) == true) { batch.ServerName = strServerName; } batch.Add(strPurePath); } if (batch.Count > 0) { batchs.Add(batch); } } // 进行循环获取 foreach (OneBatch temp in batchs) { // 获得server url dp2Server server = this.Servers.GetServerByName(temp.ServerName); if (server == null) { string strError = "名为 '" + temp.ServerName + "' 的服务器在检索窗中尚未定义..."; throw new Exception(strError); } string strServerUrl = server.Url; LibraryChannel channel = this.ChannelManager.GetChannel(strServerUrl); try { List <string> batch = new List <string>(); for (; batch.Count > 0 || temp.Count > 0;) { if (batch.Count == 0) { for (int i = 0; i < Math.Min(temp.Count, 100); i++) { batch.Add(temp[i]); } temp.RemoveRange(0, batch.Count); } // 每100个一批 if (batch.Count > 0) { REDO: string[] paths = new string[batch.Count]; batch.CopyTo(paths); DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null; string strError = ""; long lRet = channel.GetBrowseRecords( this.Stop, paths, "id,cols", out searchresults, out strError); if (lRet == -1) { throw new Exception(strError); } if (searchresults == null) { strError = "searchresults == null"; throw new Exception(strError); } for (int i = 0; i < searchresults.Length; i++) { DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i]; Debug.Assert(batch[i] == record.Path, ""); // 包含服务器名 record.Path = record.Path + "@" + temp.ServerName; yield return(record); } CONTINUE: if (batch.Count > searchresults.Length) { // 有本次没有获取到的记录 batch.RemoveRange(0, searchresults.Length); /* * if (index == m_recpaths.Count - 1) * goto REDO; // 当前已经是最后一轮了,需要继续做完 * */ // 否则可以留给下一轮处理 } else { batch.Clear(); } } } // } finally { Program.MainForm.ReturnChannel(channel); } } }
private void button_dp2library_changePassword_Click(object sender, EventArgs e) { string strError = ""; if (this.textBox_dp2library_userName.Text == "") { MessageBox.Show(this, "尚未输入用户名。"); this.textBox_dp2library_userName.Focus(); return; } if (this.textBox_dp2library_newPassword.Text != this.textBox_dp2library_confirmNewPassword.Text) { MessageBox.Show(this, "新密码 和 确认新密码不一致。请重新输入。"); this.textBox_dp2library_newPassword.Focus(); return; } stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在修改 dp2library 用户密码 ..."); stop.BeginLoop(); this.EnableControls(false); this.Update(); this.MainForm.Update(); try { long lRet = 0; // 获得server url if (String.IsNullOrEmpty(this.LibraryServerName) == true) { strError = "尚未指定服务器名"; goto ERROR1; } dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName); if (server == null) { strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在..."; goto ERROR1; } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); // 非强制修改密码,即本人修改 if (this.checkBox_dp2library_force.Checked == false) { // return: // -1 error // 0 登录未成功 // 1 登录成功 lRet = Channel.Login(this.textBox_dp2library_userName.Text, this.textBox_dp2library_oldPassword.Text, "location=dp2Catalog,type=worker,client=dp2catalog|" + Program.ClientVersion, /* * "", * false, * */ out strError); if (lRet == -1) { goto ERROR1; } if (lRet == 0) { strError = "旧密码不正确"; goto ERROR1; } try { lRet = Channel.ChangeUserPassword( stop, this.textBox_dp2library_userName.Text, this.textBox_dp2library_oldPassword.Text, this.textBox_dp2library_newPassword.Text, out strError); if (lRet == -1) { goto ERROR1; } } finally { string strError_1 = ""; Channel.Logout(out strError_1); } } // 强制修改密码 if (this.checkBox_dp2library_force.Checked == true) { UserInfo info = new UserInfo(); info.UserName = this.textBox_dp2library_userName.Text; info.Password = this.textBox_dp2library_newPassword.Text; // 当action为"resetpassword"时,则info.ResetPassword状态不起作用,无论怎样都要修改密码。resetpassword并不修改其他信息,也就是说info中除了Password/UserName以外其他成员的值无效。 lRet = Channel.SetUser( stop, "resetpassword", info, out strError); if (lRet == -1) { goto ERROR1; } } } finally { this.EnableControls(true); stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); } MessageBox.Show(this, "dp2library 用户 '" + this.textBox_dp2library_userName.Text + "' 密码修改成功。"); this.textBox_dp2library_userName.SelectAll(); this.textBox_dp2library_userName.Focus(); return; ERROR1: MessageBox.Show(this, strError); // 焦点重新定位到密码输入域 this.textBox_dp2library_oldPassword.Focus(); this.textBox_dp2library_oldPassword.SelectAll(); }
public IEnumerator GetEnumerator() { List <string> format_list = new List <string>(); int nContentIndex = format_list.Count; int nTimestampIndex = -1; int nMetadataIndex = -1; format_list.Add(this.Format); if ((this.GetBiblioInfoStyle & dp2Catalog.GetBiblioInfoStyle.Timestamp) != 0) { nTimestampIndex = format_list.Count; format_list.Add("timestamp"); } if ((this.GetBiblioInfoStyle & dp2Catalog.GetBiblioInfoStyle.Metadata) != 0) { nMetadataIndex = format_list.Count; format_list.Add("metadata"); } string[] formats = new string[format_list.Count]; format_list.CopyTo(formats); // 首先按照服务器名的不同,划分为若干个区段 List <OneBatch> batchs = new List <OneBatch>(); { OneBatch batch = new OneBatch(); for (int index = 0; index < m_recpaths.Count; index++) { string s = m_recpaths[index]; // 解析记录路径 string strServerName = ""; string strPurePath = ""; dp2SearchForm.ParseRecPath(s, out strServerName, out strPurePath); // 服务器名发生变化了 if (batch.Count > 0 && strServerName != batch.ServerName) { batchs.Add(batch); batch = new OneBatch(); batch.ServerName = strServerName; batch.Add(strPurePath); continue; } if (string.IsNullOrEmpty(batch.ServerName) == true) { batch.ServerName = strServerName; } batch.Add(strPurePath); } if (batch.Count > 0) { batchs.Add(batch); } } // 进行循环获取 foreach (OneBatch temp in batchs) { // 获得server url dp2Server server = this.Servers.GetServerByName(temp.ServerName); if (server == null) { string strError = "名为 '" + temp.ServerName + "' 的服务器在检索窗中尚未定义..."; throw new Exception(strError); } string strServerUrl = server.Url; LibraryChannel channel = this.ChannelManager.GetChannel(strServerUrl); try { List <string> batch = new List <string>(); for (; batch.Count > 0 || temp.Count > 0;) { if (batch.Count == 0) { for (int i = 0; i < Math.Min(temp.Count, 100); i++) { batch.Add(temp[i]); } temp.RemoveRange(0, batch.Count); } // 每100个一批 if (batch.Count > 0) { REDO: string strCommand = "@path-list:" + StringUtil.MakePathList(batch); string[] results = null; byte[] timestamp = null; string strError = ""; long lRet = channel.GetBiblioInfos( this.Stop, strCommand, "", formats, out results, out timestamp, out strError); if (lRet == -1) { throw new Exception(strError); } if (lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) { foreach (string path in batch) { BiblioItem item = new BiblioItem(); item.RecPath = path + "@" + temp.ServerName; item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + path + "' 不存在"; yield return(item); } goto CONTINUE; } // 如果results.Length表现正常,其实还可以继续处理 if (results != null && results.Length > 0) { } else { strError = "获得书目记录 '" + StringUtil.MakePathList(batch) + "' 时发生错误: " + strError; throw new Exception(strError); } } if (results == null) { strError = "results == null"; throw new Exception(strError); } for (int i = 0; i < results.Length / formats.Length; i++) { BiblioItem item = new BiblioItem(); item.RecPath = batch[i] + "@" + temp.ServerName; if (nContentIndex != -1) { item.Content = results[i * formats.Length + nContentIndex]; } if (nTimestampIndex != -1) { item.Timestamp = ByteArray.GetTimeStampByteArray(results[i * formats.Length + nTimestampIndex]); } if (nMetadataIndex != -1) { item.Metadata = results[i * formats.Length + nMetadataIndex]; } if (string.IsNullOrEmpty(item.Content) == true) { item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + item.RecPath + "' 不存在"; } yield return(item); } CONTINUE: if (batch.Count > results.Length / formats.Length) { // 有本次没有获取到的记录 batch.RemoveRange(0, results.Length / formats.Length); /* * if (index == m_recpaths.Count - 1) * goto REDO; // 当前已经是最后一轮了,需要继续做完 * */ // 否则可以留给下一轮处理 } else { batch.Clear(); } } } // } finally { Program.MainForm.ReturnChannel(channel); } } }