/// <summary>Saves the stream's owner so a new one can be specified, but is then later restored to the previous owner, via <see cref="Dispose()"/></summary>
        /// <param name="stream">The underlying stream for this bookmark</param>
        /// <param name="new_owner"></param>
        public IKSoftStreamOwnerBookmark(XmlElementStream stream, object new_owner)
        {
            Contract.Requires <ArgumentNullException>(stream != null);

            m_oldOwner     = (m_stream = stream).Owner;
            m_stream.Owner = new_owner;
        }
 /// <summary>Returns the owner of the underlying stream to the previous owner</summary>
 public void Dispose()
 {
     if (m_stream != null)
     {
         m_stream.Owner = m_oldOwner;
         m_stream       = null;
     }
 }
 /// <summary>Returns the cursor of the underlying stream to the last saved cursor value</summary>
 public void Dispose()
 {
     if (m_stream != null)
     {
         m_stream.StreamElementEnd(m_mode, ref m_oldCursor);
         m_stream = null;
     }
 }
        /// <summary>Saves the stream's cursor so a new one can be specified, but then later restored to the saved cursor, via <see cref="Dispose()"/></summary>
        /// <param name="stream">The underlying stream for this bookmark</param>
        /// <param name="mode"></param>
        /// <param name="element_name">If null, no bookmarking is actually performed</param>
        public XmlElementStreamBookmark(XmlElementStream stream, FA mode, string element_name)
        {
            Contract.Requires <ArgumentNullException>(stream != null);

            m_stream    = null;
            m_mode      = mode;
            m_oldCursor = null;

            if (element_name != null)
            {
                (m_stream = stream).StreamElementBegin(mode, element_name, out m_oldCursor);
            }
        }
        /// <summary>Initialize a new element stream with write permissions</summary>
        /// <param name="owner">Initial owner object</param>
        /// <param name="root_name">Name of the document element</param>
        /// <returns></returns>
        public static XmlElementStream CreateForWrite(string root_name, object owner = null)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(root_name));

            var root = new XmlDocument();

            root.AppendChild(root.CreateElement(root_name));

            XmlElementStream @this = new XmlElementStream();

            @this.m_root = root;

            @this.AccessPermissions = FileAccess.Write;

            @this.Owner = owner;

            return(@this);
        }
        static dynamic XmlOpenFromStream(TagElementStreamFormat format, System.IO.Stream sourceStream,
                                         FileAccess permissions, object owner)
        {
            Contract.Requires(format.GetBaseFormat() == TagElementStreamFormat.Xml);

            if (format.IsText())
            {
                var stream = new XmlElementStream(sourceStream, permissions, owner);
                stream.InitializeAtRootElement();

                return(stream);
            }
            else if (format.IsBinary())             // haven't decided on a standard to use yet
            {
                throw new NotImplementedException("General binary XML files not yet implemented");
            }

            throw new Debug.UnreachableException(format.ToString());
        }
Esempio n. 7
0
        /// <summary>Initialize a new element stream with write permissions</summary>
        /// <param name="owner">Initial owner object</param>
        /// <param name="rootName">Name of the document element</param>
        /// <returns></returns>
        public static XmlElementStream CreateForWrite(string rootName, object owner = null)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(rootName));

            var root = new XmlDocument()
            {
                XmlResolver = null,
            };

            root.AppendChild(root.CreateElement(rootName));

            XmlElementStream @this = new XmlElementStream
            {
                Document = root,
                Owner    = owner,
            };

            @this.StreamMode = @this.StreamPermissions = System.IO.FileAccess.Write;

            @this.InitializeAtRootElement();

            return(@this);
        }
 public void StreamXml(XmlElementStream s, System.IO.FileAccess stream_mode)
 {
     Contract.Requires(s != null);
     Contract.Requires(stream_mode != System.IO.FileAccess.ReadWrite);
 }