// 从文件中装载创建一个ServerCollection对象 // parameters: // bIgnorFileNotFound 是否不抛出FileNotFoundException异常。 // 如果==true,函数直接返回一个新的空ServerCollection对象 // Exception: // FileNotFoundException 文件没找到 // SerializationException 版本迁移时容易出现 public static ServerCollection Load( string strFileName, bool bIgnorFileNotFound) { ServerCollection servers = null; try { using (Stream stream = File.Open(strFileName, FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); servers = (ServerCollection)formatter.Deserialize(stream); servers.m_strFileName = strFileName; return(servers); } } catch (FileNotFoundException ex) { if (bIgnorFileNotFound == false) { throw ex; } servers = new ServerCollection(); servers.m_strFileName = strFileName; // 让调主有一个新的空对象可用 return(servers); } }
// 将另一对象的数组内容灌入本对象 public void Import(ServerCollection servers) { this.Clear(); this.AddRange(servers); this.m_bChanged = true; // 新增加的动作 ServerChangedEventArgs e = new ServerChangedEventArgs(); e.Url = ""; e.ServerChangeAction = ServerChangeAction.Import; OnServerChanged(this, e); }
public void Initial(ServerCollection servers, RmsChannelCollection channels, DigitalPlatform.StopManager stopManager, string serverUrl, string strDatabaseObject) { this.Servers = servers; this.Channels = channels; this.stopManager = stopManager; this.ServerUrl = serverUrl; this.textBox_databaseObject.Text = strDatabaseObject; }
public void Initial(ServerCollection servers, RmsChannelCollection channels, DigitalPlatform.StopManager stopManager, string serverUrl, string strCfgFilePath) { this.Servers = servers; this.Channels = channels; this.stopManager = stopManager; this.ServerUrl = serverUrl; this.Path = strCfgFilePath; // this.textBox_path.Text = this.ServerUrl + "?" + this.Path; }
// 询问无法匹配的源路径如何处理 // return: // -1 出错 // 0 cancel全部处理 // 1 已经选择处理办法 public static int AskNotMatchOriginBox( IWin32Window owner, ApplicationInfo ap, ServerCollection Servers, RmsChannelCollection Channels, string strComment, string strSelectedLongPath, string strOrigin, DbNameMap map) { DbNameMapItemDlg dlg = new DbNameMapItemDlg(); dlg.Font = GuiUtil.GetDefaultFont(); dlg.Servers = Servers; dlg.Channels = Channels; dlg.Comment = strComment; dlg.AskMode = AskMode.AskNotMatchOrigin; dlg.Origin = strOrigin; dlg.Target = strSelectedLongPath; dlg.WriteMode = "append"; dlg.Text = "请指定映射关系"; if (ap != null) { ap.LinkFormState(dlg, "AskNotMatchOriginBox_state"); } dlg.ShowDialog(owner); if (ap != null) { ap.UnlinkFormState(dlg); } if (dlg.DialogResult != DialogResult.OK) { return(0); // cancel } string strError = ""; if (map.NewItem(dlg.Origin, dlg.Target, dlg.WriteMode, 0, // 插入最前面 out strError) == null) { MessageBox.Show(owner, strError); return(-1); } return(1); }
// 克隆。 // 新数组中的对象完全是新创建的。 public ServerCollection Dup() { ServerCollection newServers = new ServerCollection(); for (int i = 0; i < this.Count; i++) { Server newServer = new Server((Server)this[i]); newServers.Add(newServer); } newServers.m_strFileName = this.m_strFileName; newServers.m_bChanged = this.m_bChanged; newServers.ownerForm = this.ownerForm; return(newServers); }
public int Initial(ServerCollection servers, RmsChannelCollection channels, DigitalPlatform.StopManager stopManager, string serverUrl, out string strError) { this.Servers = servers; this.Channels = channels; this.stopManager = stopManager; this.ServerUrl = serverUrl; strError = ""; int nRet = Fill(this.Lang, out strError); if (nRet == -1) { return(-1); } return(0); }
// 初始化 // parameters: // userRightsDom 用户记录的dom对象。将直接引用这个对象 public void Initial(ServerCollection servers, RmsChannelCollection channels, DigitalPlatform.StopManager stopManager, string serverUrl, XmlDocument UserRightsDom) { this.Servers = servers; this.Channels = channels; this.stopManager = stopManager; this.ServerUrl = serverUrl; this.UserRightsDom = UserRightsDom; // 直接引用外界的dom对象 // 用服务器端获得的信息填充树 Cursor save = this.Cursor; this.Cursor = Cursors.WaitCursor; FillAll(null); InitialRightsParam(); this.Cursor = save; this.m_bChanged = false; }
// 根据原始路径准备即将写入的路径 // return: // -1 出错 // 0 用户放弃 // 1 成功 public static int PrepareOverwritePath( ServerCollection Servers, RmsChannelCollection Channels, IWin32Window owner, ref DbNameMap map, ref string strLongPath, out string strError) { strError = ""; // 从map中查询覆盖还是追加? ResPath respath = new ResPath(strLongPath); respath.MakeDbName(); REDO: DbNameMapItem mapItem = (DbNameMapItem)map["*"]; if (mapItem != null) { } else { mapItem = (DbNameMapItem)map[respath.FullPath.ToUpper()]; } if (mapItem == null) { OriginNotFoundDlg dlg = new OriginNotFoundDlg(); Font font = GuiUtil.GetDefaultFont(); if (font != null) dlg.Font = font; dlg.Message = "数据中声明的数据库路径 '" +respath.FullPath+ "' 在覆盖关系对照表中没有找到, 请选择覆盖方式: " ; dlg.Origin = respath.FullPath.ToUpper(); dlg.Servers = Servers; dlg.Channels = Channels; dlg.Map = map; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(owner); if (dlg.DialogResult != DialogResult.OK) { strError = "用户中断..."; return 0; } map = dlg.Map; goto REDO; } if (mapItem.Style == "skip") return 0; // 构造目标路径 // 1)从源路径中提取id。源路径来自备份文件数据 respath = new ResPath(strLongPath); string strID = respath.GetRecordId(); if (string.IsNullOrEmpty(strID) == true || mapItem.Style == "append") { strID = "?"; // 将来加一个对话框 } // 2)用目标库路径构造完整的记录路径 string strTargetFullPath = ""; if (mapItem.Target == "*") { respath = new ResPath(strLongPath); respath.MakeDbName(); strTargetFullPath = respath.FullPath; } else { strTargetFullPath = mapItem.Target; } respath = new ResPath(strTargetFullPath); respath.Path = respath.Path + "/" + strID; strLongPath = respath.FullPath; return 1; }
private void MainForm_Load(object sender, System.EventArgs e) { if (ApplicationDeployment.IsNetworkDeployed == true) { // MessageBox.Show(this, "network"); DataDir = Application.LocalUserAppDataPath; } else { // MessageBox.Show(this, "no network"); DataDir = Environment.CurrentDirectory; } // 从文件中装载创建一个ServerCollection对象 // parameters: // bIgnorFileNotFound 是否不抛出FileNotFoundException异常。 // 如果==true,函数直接返回一个新的空ServerCollection对象 // Exception: // FileNotFoundException 文件没找到 // SerializationException 版本迁移时容易出现 try { Servers = ServerCollection.Load(this.DataDir + "\\dp2batch_servers.bin", true); Servers.ownerForm = this; } catch (SerializationException ex) { MessageBox.Show(this, ex.Message); Servers = new ServerCollection(); // 设置文件名,以便本次运行结束时覆盖旧文件 Servers.FileName = this.DataDir + "\\dp2batch_servers.bin"; } this.Servers.ServerChanged += new ServerChangedEventHandle(Servers_ServerChanged); string strError = ""; int nRet = cfgCache.Load(this.DataDir + "\\cfgcache.xml", out strError); if (nRet == -1) { MessageBox.Show(this, strError); } cfgCache.TempDir = this.DataDir + "\\cfgcache"; cfgCache.InstantSave = true; // 设置窗口尺寸状态 if (AppInfo != null) { /* // 首次运行,尽量利用“微软雅黑”字体 if (this.IsFirstRun == true) { SetFirstDefaultFont(); } * */ SetFirstDefaultFont(); MainForm.SetControlFont(this, this.DefaultFont); AppInfo.LoadFormStates(this, "mainformstate"); } stopManager.Initial(this.toolBarButton_stop, this.toolStripStatusLabel_main, this.toolStripProgressBar_main); stopManager.LinkReverseButton(this.toolBarButton_begin); // //////////////// stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 this.Channels.AskAccountInfo += new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); /* this.Channels.procAskAccountInfo = new Delegate_AskAccountInfo(this.Servers.AskAccountInfo); */ // 简单检索界面准备工作 treeView_rangeRes.stopManager = this.stopManager; treeView_rangeRes.Servers = this.Servers; // 引用 treeView_rangeRes.Channels = this.Channels; // 引用 treeView_rangeRes.AppInfo = this.AppInfo; // 2013/2/15 treeView_rangeRes.Fill(null); this.textBox_import_fileName.Text = AppInfo.GetString( "page_import", "source_file_name", ""); this.textBox_import_range.Text = AppInfo.GetString( "page_import", "range", ""); this.textBox_import_dbMap.Text = AppInfo.GetString( "page_import", "dbmap", "").Replace(";", "\r\n"); this.checkBox_import_fastMode.Checked = AppInfo.GetBoolean( "page_import", "fastmode", true); textBox_startNo.Text = AppInfo.GetString( "rangePage", "startNumber", ""); textBox_endNo.Text = AppInfo.GetString( "rangePage", "endNumber", ""); checkBox_verifyNumber.Checked = Convert.ToBoolean( AppInfo.GetInt( "rangePage", "verifyrange", 0) ); checkBox_forceLoop.Checked = Convert.ToBoolean( AppInfo.GetInt( "rangePage", "forceloop", 0) ); checkBox_export_delete.Checked = Convert.ToBoolean( AppInfo.GetInt( "rangePage", "delete", 0) ); this.checkBox_export_fastMode.Checked = AppInfo.GetBoolean( "rangePage", "fastmode", true); this.radioButton_all.Checked = Convert.ToBoolean( AppInfo.GetInt( "rangePage", "all", 0) ); strLastOutputFileName = AppInfo.GetString( "rangePage", "lastoutputfilename", ""); nLastOutputFilterIndex = AppInfo.GetInt( "rangePage", "lastoutputfilterindex", 1); scriptManager.applicationInfo = AppInfo; scriptManager.CfgFilePath = this.DataDir + "\\projects.xml"; scriptManager.DataDir = this.DataDir; scriptManager.CreateDefaultContent -= new CreateDefaultContentEventHandler(scriptManager_CreateDefaultContent); scriptManager.CreateDefaultContent += new CreateDefaultContentEventHandler(scriptManager_CreateDefaultContent); // 按照上次保存的路径展开resdircontrol树 string strResDirPath = AppInfo.GetString( "rangePage", "resdirpath", ""); if (strResDirPath != null) { object[] pList = { strResDirPath }; this.BeginInvoke(new Delegate_ExpandResDir(ExpandResDir), pList); } checkBox_export_delete_CheckedChanged(null, null); }
private void MainForm_Closed(object sender, System.EventArgs e) { this.Channels.AskAccountInfo -= new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); this.Servers.ServerChanged -= new ServerChangedEventHandle(Servers_ServerChanged); // 保存到文件 // parameters: // strFileName 文件名。如果==null,表示使用装载时保存的那个文件名 Servers.Save(null); Servers = null; string strError; int nRet = cfgCache.Save(null, out strError); if (nRet == -1) MessageBox.Show(this, strError); // 保存窗口尺寸状态 if (AppInfo != null) { AppInfo.SaveFormStates(this, "mainformstate"); } AppInfo.SetString( "page_import", "source_file_name", this.textBox_import_fileName.Text); AppInfo.SetString( "page_import", "dbmap", this.textBox_import_dbMap.Text.Replace("\r\n", ";")); AppInfo.SetString( "page_import", "range", this.textBox_import_range.Text); AppInfo.SetBoolean( "page_import", "fastmode", this.checkBox_import_fastMode.Checked); AppInfo.SetString( "rangePage", "startNumber", textBox_startNo.Text); AppInfo.SetString( "rangePage", "endNumber", textBox_endNo.Text); AppInfo.SetInt( "rangePage", "verifyrange", Convert.ToInt32(checkBox_verifyNumber.Checked)); AppInfo.SetInt( "rangePage", "forceloop", Convert.ToInt32(checkBox_forceLoop.Checked)); AppInfo.SetInt( "rangePage", "delete", Convert.ToInt32(checkBox_export_delete.Checked)); AppInfo.SetBoolean( "rangePage", "fastmode", this.checkBox_export_fastMode.Checked); AppInfo.SetInt( "rangePage", "all", Convert.ToInt32(this.radioButton_all.Checked)); AppInfo.SetString( "rangePage", "lastoutputfilename", strLastOutputFileName); AppInfo.SetInt( "rangePage", "lastoutputfilterindex", nLastOutputFilterIndex); // 保存resdircontrol最后的选择 ResPath respath = new ResPath(treeView_rangeRes.SelectedNode); AppInfo.SetString( "rangePage", "resdirpath", respath.FullPath); //记住save,保存信息XML文件 AppInfo.Save(); AppInfo = null; // 避免后面再用这个对象 }
private void MainFormNew_Load(object sender, EventArgs e) { Searching(false); // 隐藏searching ToolStripLabel if (ApplicationDeployment.IsNetworkDeployed == true) { // MessageBox.Show(this, "network"); DataDir = Application.LocalUserAppDataPath; } else { // MessageBox.Show(this, "no network"); DataDir = Environment.CurrentDirectory; } this.SetMenuItemState(); //任延华加 2006/1/5 this.toolBarButton_stop.Enabled = false; //任延华加 2006/1/5 // 从文件中装载创建一个ServerCollection对象 // parameters: // bIgnorFileNotFound 是否不抛出FileNotFoundException异常。 // 如果==true,函数直接返回一个新的空ServerCollection对象 // Exception: // FileNotFoundException 文件没找到 // SerializationException 版本迁移时容易出现 try { Servers = ServerCollection.Load(this.DataDir + "\\servers.bin", true); Servers.ownerForm = this; } catch (SerializationException ex) { MessageBox.Show(this, ex.Message); Servers = new ServerCollection(); // 设置文件名,以便本次运行结束时覆盖旧文件 Servers.FileName = this.DataDir + "\\servers.bin"; } this.Servers.ServerChanged += new ServerChangedEventHandle(Servers_ServerChanged); string strError = ""; int nRet = cfgCache.Load(this.DataDir + "\\cfgcache.xml", out strError); if (nRet == -1) { if (IsFirstRun == false) MessageBox.Show(strError); } cfgCache.TempDir = this.DataDir + "\\cfgcache"; cfgCache.InstantSave = true; // 设置窗口尺寸状态 if (AppInfo != null) { SetFirstDefaultFont(); MainForm.SetControlFont(this, this.DefaultFont); AppInfo.LoadFormStates(this, "mainformstate"); } stopManager.Initial(toolBarButton_stop, (object)this.toolStripStatusLabel_main, (object)this.toolStripProgressBar_main); // 存在上次遗留的窗口 int nLastSearchWindow = this.AppInfo.GetInt( "main_form", "last_search_window", 1); if (nLastSearchWindow == 1) { MenuItem_openSearch_Click(null, null); // 打开一个检索窗 } if (IsFirstRun == true && this.Servers.Count == 0) { MessageBox.Show(this, "欢迎您安装使用dp2rms -- 资源管理。"); ManageServers(true); ManagePreference(); } }
public int Initial(ServerCollection servers, RmsChannelCollection channels, DigitalPlatform.StopManager stopManager, string serverUrl, out string strError) { this.Servers = servers; this.Channels = channels; this.stopManager = stopManager; this.ServerUrl = serverUrl; strError = ""; int nRet = Fill(this.Lang, out strError); if (nRet == -1) return -1; return 0; }
private void Form1_Load(object sender, System.EventArgs e) { if (ApplicationDeployment.IsNetworkDeployed == true) { // MessageBox.Show(this, "network"); DataDir = Application.LocalUserAppDataPath; } else { // MessageBox.Show(this, "no network"); DataDir = Environment.CurrentDirectory; } // 从文件中装载创建一个ServerCollection对象 // parameters: // bIgnorFileNotFound 是否不抛出FileNotFoundException异常。 // 如果==true,函数直接返回一个新的空ServerCollection对象 // Exception: // FileNotFoundException 文件没找到 // SerializationException 版本迁移时容易出现 try { Servers = ServerCollection.Load(this.DataDir + "\\manager_servers.bin", true); Servers.ownerForm = this; } catch (SerializationException ex) { MessageBox.Show(this, ex.Message); Servers = new ServerCollection(); // 设置文件名,以便本次运行结束时覆盖旧文件 Servers.FileName = this.DataDir + "\\manager_servers.bin"; } this.Servers.ServerChanged += new ServerChangedEventHandle(Servers_ServerChanged); // 从文件中装载创建一个LinkInfoCollection对象 // parameters: // bIgnorFileNotFound 是否不抛出FileNotFoundException异常。 // 如果==true,函数直接返回一个新的空ServerCollection对象 // Exception: // FileNotFoundException 文件没找到 // SerializationException 版本迁移时容易出现 try { LinkInfos = LinkInfoCollection.Load(this.DataDir + "\\manager_linkinfos.bin", true); } catch (SerializationException ex) { MessageBox.Show(this, ex.Message); LinkInfos = new LinkInfoCollection(); // 设置文件名,以便本次运行结束时覆盖旧文件 LinkInfos.FileName = this.DataDir + "\\manager_linkinfos.bin"; } // 设置窗口尺寸状态 if (AppInfo != null) { SetFirstDefaultFont(); MainForm.SetControlFont(this, this.DefaultFont); AppInfo.LoadFormStates(this, "mainformstate"); } stopManager.Initial(toolBarButton_stop, this.toolStripStatusLabel_main, this.toolStripProgressBar_main); stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 /* this.Channels.procAskAccountInfo = new Delegate_AskAccountInfo(this.Servers.AskAccountInfo); */ this.Channels.AskAccountInfo += new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); // 简单检索界面准备工作 treeView_res.AppInfo = this.AppInfo; // 便于treeview中popup菜单修改配置文件时保存dialog尺寸位置 treeView_res.stopManager = this.stopManager; treeView_res.Servers = this.Servers; // 引用 treeView_res.Channels = this.Channels; // 引用 treeView_res.Fill(null); // LinkInfos.Channels = this.Channels; int nRet = 0; string strError = ""; nRet = this.LinkInfos.Link(out strError); if (nRet == -1) MessageBox.Show(this, strError); }
// 根据原始路径准备即将写入的路径 // parameters: // strSelectedLongPath 用户选定的默认的目标库长路径。将优先出现在询问对话框的目标中 // return: // -1 出错 // 0 用户放弃 // 1 成功 // 2 要跳过本条 public static int PrepareOverwritePath( IWin32Window owner, ServerCollection Servers, RmsChannelCollection Channels, ApplicationInfo AppInfo, long lIndex, string strSelectedLongPath, ref DbNameMap map, ref string strLongPath, out string strError) { strError = ""; int nRet = 0; ResPath respath = new ResPath(strLongPath); respath.MakeDbName(); string strSourceDbPath = respath.FullPath; REDO: DbNameMapItem mapItem = null; mapItem = map.MatchItem(strSourceDbPath); if (mapItem != null) goto MAPITEMOK; if (mapItem == null) { if (string.IsNullOrEmpty(strSourceDbPath) == true) { string strText = "源数据文件中记录 " + lIndex.ToString() + " 没有来源数据库。\r\n请问对所有这样的数据,将作如何处理?"; // WriteLog("打开对话框 '" + strText.Replace("\r\n", "\\n") + "'"); nRet = DbNameMapItemDlg.AskNullOriginBox( owner, AppInfo, Servers, Channels, strText, strSelectedLongPath, map); // WriteLog("关闭对话框 '" + strText.Replace("\r\n", "\\n") + "'"); if (nRet == 0) { strError = "用户中断"; return 0; // 中断整个处理 } goto REDO; } else { string strText = "源数据文件中记录 " + lIndex.ToString() + " 的来源数据库 '" + strSourceDbPath + "' 没有明确的对应规则。\r\n请问对所有这样的数据,将作如何处理?"; // 没有找到对应的目标库 // WriteLog("打开对话框 '" + strText.Replace("\r\n", "\\n") + "'"); nRet = DbNameMapItemDlg.AskNotMatchOriginBox( owner, AppInfo, Servers, Channels, strText, strSelectedLongPath, strSourceDbPath/*strResPath*/, map); // WriteLog("关闭对话框 '" + strText.Replace("\r\n", "\\n") + "'"); if (nRet == 0) { strError = "用户中断"; return 0; // 中断整个处理 } goto REDO; } } MAPITEMOK: if (mapItem.Style == "skip") return 2; // 构造目标路径 // 1)从源路径中提取id。源路径来自备份文件数据 respath = new ResPath(strLongPath); string strID = respath.GetRecordId(); if (string.IsNullOrEmpty(strID) == true || mapItem.Style == "append") { strID = "?"; // 将来加一个对话框 } // 2)用目标库路径构造完整的记录路径 string strTargetFullPath = ""; if (mapItem.Target == "*") { respath = new ResPath(strLongPath); respath.MakeDbName(); strTargetFullPath = respath.FullPath; } else { strTargetFullPath = mapItem.Target; } respath = new ResPath(strTargetFullPath); respath.Path = respath.Path + "/" + strID; strLongPath = respath.FullPath; return 1; }
public void Initial(ServerCollection servers, RmsChannelCollection channels, DigitalPlatform.StopManager stopManager, string serverUrl, string strDbName) { this.Servers = servers; this.Channels = channels; this.stopManager = stopManager; this.ServerUrl = serverUrl; this.DbName = strDbName; if (this.DbName != "") { // 获得数据库Style string strError = ""; this.DbStyle = this.GetDbStyle( this.DbName, out strError); if (this.DbStyle == -1) throw new Exception(strError); // 用服务器端获得的信息填充树 Cursor save = this.Cursor; this.Cursor = Cursors.WaitCursor; FillAll(null); this.Cursor = save; } }
// 询问无法匹配的源路径如何处理 // return: // -1 出错 // 0 cancel全部处理 // 1 已经选择处理办法 public static int AskNotMatchOriginBox( IWin32Window owner, ApplicationInfo ap, ServerCollection Servers, RmsChannelCollection Channels, string strComment, string strSelectedLongPath, string strOrigin, DbNameMap map) { DbNameMapItemDlg dlg = new DbNameMapItemDlg(); dlg.Font = GuiUtil.GetDefaultFont(); dlg.Servers = Servers; dlg.Channels = Channels; dlg.Comment = strComment; dlg.AskMode = AskMode.AskNotMatchOrigin; dlg.Origin = strOrigin; dlg.Target = strSelectedLongPath; dlg.WriteMode = "append"; dlg.Text = "请指定映射关系"; if (ap != null) ap.LinkFormState(dlg, "AskNotMatchOriginBox_state"); dlg.ShowDialog(owner); if (ap != null) ap.UnlinkFormState(dlg); if (dlg.DialogResult != DialogResult.OK) return 0; // cancel string strError = ""; if (map.NewItem(dlg.Origin, dlg.Target, dlg.WriteMode, 0, // 插入最前面 out strError) == null) { MessageBox.Show(owner, strError); return -1; } return 1; }
/// <summary> /// 初始化 /// </summary> /// <param name="servers">服务器信息集合</param> /// <param name="cfgcache">配置文件缓存</param> public void Initial(ServerCollection servers, CfgCache cfgcache) { this.Servers = servers; /* this.Channels.procAskAccountInfo = new Delegate_AskAccountInfo(this.Servers.AskAccountInfo); */ this.Channels.AskAccountInfo -= new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); this.Channels.AskAccountInfo += new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); this.cfgCache = cfgcache; }
private void MainFormNew_FormClosed(object sender, FormClosedEventArgs e) { this.Servers.ServerChanged -= new ServerChangedEventHandle(Servers_ServerChanged); // 保存到文件 // parameters: // strFileName 文件名。如果==null,表示使用装载时保存的那个文件名 Servers.Save(null); Servers = null; string strError; int nRet = cfgCache.Save(null, out strError); if (nRet == -1) MessageBox.Show(this, strError); // 保存窗口尺寸状态 if (AppInfo != null) { // 只要存在Search窗口 this.AppInfo.SetInt( "main_form", "last_search_window", this.TopSearchForm != null ? 1 : 0); /* // MDI子窗口是否最大化 if (this.ActiveMdiChild != null) { this.applicationInfo.SetString( "mdiwindows", "window_state", Enum.GetName(typeof(FormWindowState), this.ActiveMdiChild.WindowState)); } */ AppInfo.SaveFormStates(this, "mainformstate"); } //记住save,保存信息XML文件 AppInfo.Save(); AppInfo = null; // 避免后面再用这个对象 }
// 克隆。 // 新数组中的对象完全是新创建的。 public ServerCollection Dup() { ServerCollection newServers = new ServerCollection(); for(int i=0;i<this.Count;i++) { Server newServer = new Server((Server)this[i]); newServers.Add(newServer); } newServers.m_strFileName = this.m_strFileName; newServers.m_bChanged = this.m_bChanged; newServers.ownerForm = this.ownerForm; return newServers; }
// 初始化,在打开前调用 public void Initial(ServerCollection servers, RmsChannelCollection channels) { this.resTree.Servers = servers; this.resTree.Channels = channels; }
private void Form1_Closed(object sender, System.EventArgs e) { this.Channels.AskAccountInfo -= new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); // 如果缺了此句,则Servers.Save会出现问题 this.Servers.ServerChanged -= new ServerChangedEventHandle(Servers_ServerChanged); // 保存到文件 // parameters: // strFileName 文件名。如果==null,表示使用装载时保存的那个文件名 Servers.Save(null); Servers = null; LinkInfos.Save(null); LinkInfos = null; // 保存窗口尺寸状态 if (AppInfo != null) { AppInfo.SaveFormStates(this, "mainformstate"); } //记住save,保存信息XML文件 AppInfo.Save(); AppInfo = null; // 避免后面再用这个对象 }
// 从文件中装载创建一个ServerCollection对象 // parameters: // bIgnorFileNotFound 是否不抛出FileNotFoundException异常。 // 如果==true,函数直接返回一个新的空ServerCollection对象 // Exception: // FileNotFoundException 文件没找到 // SerializationException 版本迁移时容易出现 public static ServerCollection Load( string strFileName, bool bIgnorFileNotFound) { ServerCollection servers = null; try { using (Stream stream = File.Open(strFileName, FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); servers = (ServerCollection)formatter.Deserialize(stream); servers.m_strFileName = strFileName; return servers; } } catch (FileNotFoundException ex) { if (bIgnorFileNotFound == false) throw ex; servers = new ServerCollection(); servers.m_strFileName = strFileName; // 让调主有一个新的空对象可用 return servers; } }