Exemplo n.º 1
0
 /// <summary>
 /// Saves tree of nodes (this and descendants) to an XML file.
 /// </summary>
 /// <param name="file">XML file. Must be full path. Can contain environment variables etc, see <see cref="APath.ExpandEnvVar"/>.</param>
 /// <param name="nodeWriter">Callback function that writes node's XML start element (see <see cref="XmlWriter.WriteStartElement(string)"/>) and attributes (see <see cref="XmlWriter.WriteAttributeString(string, string)"/>). Must not write children and end element. Also should not write value, unless your reader knows how to read it.</param>
 /// <param name="sett">XML formatting settings. Optional.</param>
 /// <param name="children">If not null, writes these nodes as if they were children of this node.</param>
 /// <exception cref="ArgumentException">Not full path.</exception>
 /// <exception cref="Exception">Exceptions of <see cref="XmlWriter.Create(string)"/> and other <b>XmlWriter</b> methods.</exception>
 /// <remarks>
 /// Uses <see cref="AFile.Save"/>. It ensures that existing file data is not damaged on exception etc.
 /// </remarks>
 /// <example><see cref="ATreeBase{T}"/></example>
 protected void XmlSave(string file, XmlNodeWriter nodeWriter, XmlWriterSettings sett = null, IEnumerable <T> children = null)
 {
     file = APath.NormalizeForNET_(file);
     sett ??= new XmlWriterSettings()
     {
         OmitXmlDeclaration = true, Indent = true, IndentChars = "  "
     };
     AFile.Save(file, temp => {
         using var x = XmlWriter.Create(temp, sett);
         XmlSave(x, nodeWriter, children);
     });
 }
Exemplo n.º 2
0
        void _SaveLayout()
        {
            try {
                if (ZResetLayoutAfterRestart)
                {
                    AFile.Delete(_xmlFile);
                    return;
                }
                AFile.CreateDirectoryFor(_xmlFile);
                var sett = new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true,
                    Indent             = true,
                    IndentChars        = "\t"
                };
                AFile.Save(_xmlFile, temp => {
                    using (var x = XmlWriter.Create(temp, sett)) {
                        x.WriteStartDocument();
                        x.WriteStartElement("panels");
                        x.WriteAttributeString("version", _asmVersion);
                        _firstSplit.Save(x);
                        x.WriteEndDocument();
                    }
                });
            }
            catch (Exception ex) {
#if DEBUG
                AOutput.QM2.Write(ex);                 //cannot Write or show dialog in ctor
#else
                _ = ex;
#endif
                //AOutput.Write(ex);
                //these don't work, maybe because now is closing app. Never mind, unlikely to fail, and not very important.
                //ADialog.ShowError("Failed to save panel/toolbar layout", _xmlFile, DFlags.Wider, expandedText: e.ToString());
                //MessageBox.Show("aaaa");
            }
        }