// 编辑配置文件 void menu_editCfgFile(object sender, System.EventArgs e) { if (this.SelectedNode == null) { MessageBox.Show(this, "尚未选择要编辑的配置文件节点"); return; } if (this.SelectedNode.ImageIndex != ResTree.RESTYPE_FILE) { MessageBox.Show(this, "所选择的节点不是配置文件类型。请选择要编辑的配置文件节点。"); return; } string strPath = this.GetPath(this.SelectedNode); if (DatabaseObject.IsDefaultFile(strPath) == true && EnableDefaultFileEditing == false) { MessageBox.Show(this, "数据库缺省的配置文件不能在此进行修改。"); return; } DatabaseObject obj = this.Root.LocateObject(strPath); if (obj == null) { MessageBox.Show(this, "路径为 '" + strPath + "' 的内存对象没有找到..."); return; } // 编辑配置文件 CfgFileEditDlg dlg = new CfgFileEditDlg(); dlg.Font = GuiUtil.GetDefaultFont(); dlg.Initial(obj, strPath); /* dlg.Initial(this.Servers, this.Channels, this.stopManager, this.ServerUrl, strPath); */ if (this.applicationInfo != null) this.applicationInfo.LinkFormState(dlg, "CfgFileEditDlg_state"); dlg.ShowDialog(this); if (this.applicationInfo != null) this.applicationInfo.UnlinkFormState(dlg); if (dlg.DialogResult == DialogResult.OK) { // 把修改记录到日志 ObjEvent objevent = new ObjEvent(); objevent.Obj = obj; objevent.Oper = ObjEventOper.Change; objevent.Path = strPath; this.Log.Add(objevent); } }
// 创建新对象 void DoNewObject(bool bInsertAsChild) { NewObjectDlg dlg = new NewObjectDlg(); dlg.Font = GuiUtil.GetDefaultFont(); dlg.Type = ResTree.RESTYPE_FILE; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; string strPath = ""; string strError = ""; DatabaseObject obj = new DatabaseObject(); obj.Name = dlg.textBox_objectName.Text; obj.Type = dlg.Type; obj.Changed = true; TreeNode node = new TreeNode(obj.Name, obj.Type, obj.Type); TreeNode nodeParent = null; if (bInsertAsChild == false) { // 插入同级 // 查重 TreeNode nodeDup = TreeViewUtil.FindNodeByText((TreeView)this, this.SelectedNode != null ? this.SelectedNode.Parent : null, dlg.textBox_objectName.Text); if (nodeDup != null) { strError = "同名对象已经存在。放弃操作。"; goto ERROR1; } if (this.SelectedNode == null) { strError = "尚未选择基准对象"; goto ERROR1; } nodeParent = this.SelectedNode.Parent; if (nodeParent == null) nodeParent = this.Nodes[0]; } else { // 插入下级 // 查重 TreeNode nodeDup = TreeViewUtil.FindNodeByText((TreeView)this, this.SelectedNode, dlg.textBox_objectName.Text); if (nodeDup != null) { strError = "同名对象已经存在。放弃操作。"; goto ERROR1; } nodeParent = this.SelectedNode; if (nodeParent == null) nodeParent = this.Nodes[0]; } nodeParent.Nodes.Add(node); strPath = TreeViewUtil.GetPath(nodeParent, '/'); DatabaseObject objParent = this.Root.LocateObject(strPath); if (objParent == null) { strError = "路径为 '" + strPath + "' 的内存对象没有找到..."; goto ERROR1; } obj.Parent = objParent; objParent.Children.Add(obj); strPath = TreeViewUtil.GetPath(node, '/'); // 把修改记录到日志 ObjEvent objevent = new ObjEvent(); objevent.Obj = obj; objevent.Oper = ObjEventOper.New; objevent.Path = strPath; this.Log.Add(objevent); /* int nRet = NewServerSideObject(strPath, dlg.Type, null, null, out strError); if (nRet == -1) goto ERROR1; // 刷新? FillAll(null); */ return; ERROR1: MessageBox.Show(this, strError); return; }
// 将树上全部对象以特定类型加入日志中 public void PutAllObjToLog(ObjEventOper oper, DatabaseObject root) { ObjEvent objevent = new ObjEvent(); objevent.Obj = root; objevent.Oper = oper; objevent.Path = root.MakePath(this.DbName); this.Log.Add(objevent); if (oper == ObjEventOper.Delete && root.Type == ResTree.RESTYPE_FOLDER) return; // 删除目录对象, 只要这个对象进入了日志, 其下级均不必再进入 // 递归 for (int i = 0; i < root.Children.Count; i++) { PutAllObjToLog(oper, (DatabaseObject)root.Children[i]); } }
// 将内存对象插入TreeView树 // (暂不改变服务器端的真正对象) // parameters: // nodeInsertPos 插入参考节点,在此前插入。如果==null,表示在parent下级末尾追加 public int InsertObject(TreeNode nodeParent, TreeNode nodeInsertPos, DatabaseObject obj, out string strError) { strError = ""; int nRet = 0; TreeNodeCollection children = null; if (nodeParent == null) { children = this.Nodes; } else { children = nodeParent.Nodes; } ArrayList aObject = new ArrayList(); if (obj.Type == -1 || obj.Type == ResTree.RESTYPE_DB) { aObject.AddRange(obj.Children); } else { aObject.Add(obj); } for (int i = 0; i < aObject.Count; i++) { DatabaseObject perObj = (DatabaseObject)aObject[i]; TreeNode nodeNew = new TreeNode(perObj.Name, perObj.Type, perObj.Type); Debug.Assert(perObj.Type != -1, "类型值尚未初始化"); Debug.Assert(perObj.Type != ResTree.RESTYPE_DB, "插入类型不能为DB"); if (nodeInsertPos == null) children.Add(nodeNew); else { int index = children.IndexOf(nodeInsertPos); if (index == -1) children.Add(nodeNew); else children.Insert(index, nodeNew); } string strPath = this.GetPath(nodeNew); // 把修改记录到日志 ObjEvent objevent = new ObjEvent(); objevent.Obj = perObj; objevent.Oper = ObjEventOper.New; objevent.Path = strPath; this.Log.Add(objevent); /* // 在服务器端兑现 if (this.StorageMode == StorageMode.Real) { MemoryStream stream = null; if (perObj.Type == ResTree.RESTYPE_FILE) stream = new MemoryStream(perObj.Content); string strPath = this.GetPath(nodeNew); nRet = NewServerSideObject(strPath, nodeNew.ImageIndex, stream, perObj.TimeStamp, out strError); if (nRet == -1) return -1; } */ if (perObj.Type == ResTree.RESTYPE_FOLDER) { // 递归 // ResTree.SetLoading(nodeNew); for (int j = 0; j < perObj.Children.Count; j++) { nRet = InsertObject(nodeNew, null, (DatabaseObject)perObj.Children[j], out strError); if (nRet == -1) return -1; } } if (nodeNew.Parent != null) nodeNew.Parent.Expand(); } return 0; }
// 删除对象 private void menu_deleteObject_Click(object sender, System.EventArgs e) { if (this.SelectedNode == null) { MessageBox.Show("尚未选择要删除的对象..."); return; } if (this.SelectedNode.ImageIndex == ResTree.RESTYPE_DB) { MessageBox.Show("这里不能删除数据库对象..."); return; } string strPath = this.GetPath(this.SelectedNode); DatabaseObject obj = this.Root.LocateObject(strPath); if (obj == null) { MessageBox.Show(this, "路径为 '" + strPath + "' 的内存对象没有找到..."); return; } /* this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); DigitalPlatform.GUI.Stop stop = null; if (stopManager != null) { stop = new DigitalPlatform.GUI.Stop(); stop.Register(this.stopManager); // 和容器关联 stop.Initial(new Delegate_doStop(this.DoStop), "正在删除对象: " + this.ServerUrl + "?" + strPath); stop.BeginLoop(); } byte [] baTimestamp = new byte [1]; byte [] baOutputTimestamp = null; // string strOutputPath = ""; string strError = ""; REDO: // 删除数据库对象 long lRet = channel.DoDeleteRecord(strPath, baTimestamp, out baOutputTimestamp, out strError); if (lRet == -1) { // 时间戳不匹配 if (channel.ErrorCode == ChannelErrorCode.TimestampMismatch) { baTimestamp = baOutputTimestamp; goto REDO; } } if (stopManager != null) { stop.EndLoop(); stop.Initial(null, ""); stop.Unregister(); // 和容器关联 } this.channel = null; if (lRet == -1) { MessageBox.Show(this, strError); return; } */ // 把修改记录到日志 ObjEvent objevent = new ObjEvent(); objevent.Obj = obj; objevent.Oper = ObjEventOper.Delete; objevent.Path = strPath; this.Log.Add(objevent); // 刷新? // FillAll(null); this.SelectedNode.Remove(); if (OnObjectDeleted != null) { OnObjectDeletedEventArgs newargs = new OnObjectDeletedEventArgs(); newargs.ObjectPath = strPath; OnObjectDeleted(this, newargs); } }