/// <summary> /// Load the root xml document and call the control's SetData method. Register for the control's AfterTreeUpdate /// method so we can enable/disable various buttons. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ContentsTreeEditorDialog_Load(object sender, EventArgs e) { XmlDocument rootXml = new XmlDocument(); string msg = "Begin \r\n\r\n"; try { string treeXml = MetaTreeFactory.LockAndReadMetatreeXml(); msg += string.IsNullOrEmpty(treeXml) ? "treeXml is null" : "treeXml is not null"; msg += "\r\n\r\n"; rootXml.LoadXml(treeXml); msg += "LoadXml success \r\n\r\n"; contentsTreeEditorControl1.SetData(rootXml); msg += "SetData success \r\n\r\n"; if (!string.IsNullOrEmpty(_fullNodePath)) { msg += "_fullNodePath is not null: " + _fullNodePath + " \r\n\r\n"; msg += (contentsTreeEditorControl1 == null) ? "contentsTreeEditorControl1 is null" : "contentsTreeEditorControl1 is not null"; msg += "SetData success \r\n\r\n"; contentsTreeEditorControl1.SetCurrentNode(_fullNodePath); } if (contentsTreeEditorControl1 == null) { msg += "contentsTreeEditorControl1 is null \r\n\r\n"; } contentsTreeEditorControl1.AfterTreeUpdate += AfterTreeUpdate; } catch (Exception ex) { msg += "Unable to open the database contents tree for editing.\r\n\r\n" + ex.Message; MessageBoxMx.ShowError(msg); Close(); } }
/// <summary> /// Save the RootXml document after backing up the original. /// </summary> private bool SaveRootXml() { // don't do anything if there are no changes. If someone looks at the tree and makes no changes, // then presses OK, no reason to save a backup and non-existent changes. if (!contentsTreeEditorControl1.IsDirty) { return(true); } // get the new version of the Xml Data XmlDocument rootXml = contentsTreeEditorControl1.GetData(); // if GetData returned null then we were unable to update the xml from the tree. if (rootXml == null) { return(false); } // reformat XML so it is pretty and save to the SourceFile location StringBuilder rootXmlSb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { NewLineChars = "\n", Indent = true }; XmlWriter writer = XmlWriter.Create(rootXmlSb, settings); rootXml.WriteTo(writer); writer.Close(); SavedRootXml = rootXmlSb.ToString(); MetaTreeFactory.SaveMetaTreeXml(SavedRootXml); return(true); }
/// <summary> /// Always release the XML file when the form closes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ContentsTreeEditorDialog_FormClosed(object sender, FormClosedEventArgs e) { MetaTreeFactory.ReleaseMetaTreeXml(); // release control of tree }