예제 #1
0
        /// <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;
        }
예제 #2
0
 /// <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;
     }
 }
예제 #3
0
 /// <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;
     }
 }
예제 #4
0
        /// <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);
            }
        }
예제 #5
0
        /// <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());
        }
예제 #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);
        }
예제 #8
0
 public void StreamXml(XmlElementStream s, System.IO.FileAccess stream_mode)
 {
     Contract.Requires(s != null);
     Contract.Requires(stream_mode != System.IO.FileAccess.ReadWrite);
 }