Пример #1
0
        /// <summary>
        ///   Closes the buffer by flushing the contents of its XmlDocument object (if necessary) and dettaching itself
        ///   from its <see cref="XmlBased" /> profile. </summary>
        /// <remarks>
        ///   This method may be used to explictly deactivate the <see cref="XmlBased" /> profile buffer.
        ///   This means that the buffer is flushed (if <see cref="NeedsFlushing" /> is true) and it gets
        ///   dettached from the profile. The <see cref="Dispose" /> method automatically calls this method. </remarks>
        /// <seealso cref="Flush" />
        /// <seealso cref="Dispose" />
        public void Close()
        {
            if (m_profile == null)
            {
                return;
            }

            if (m_needsFlushing)
            {
                Flush();
            }

            m_doc = null;

            if (m_file != null)
            {
                m_file.Close();
                m_file = null;
            }

            if (m_profile != null)
            {
                m_profile.m_buffer = null;
            }
            m_profile = null;
        }
Пример #2
0
        /// <summary>
        ///   Initializes a new instance of the XmlBuffer class and optionally locks the file. </summary>
        /// <param name="profile">
        ///   The XmlBased object to associate with the buffer and to assign this object to. </param>
        /// <param name="lockFile">
        ///   If true and the file exists, the file is locked to prevent other processes from writing to it
        ///   until the buffer is closed. </param>
        /// <exception cref="InvalidOperationException">
        ///	  Attempting to lock the file  and the name is null or empty. </exception>
        /// <exception cref="SecurityException">
        ///	  Attempting to lock the file without the required permission. </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///	  Attempting to lock the file and ReadWrite access is not permitted by the operating system. </exception>
        internal XmlBuffer(XmlBased profile, bool lockFile)
        {
            m_profile = profile;

            if (lockFile)
            {
                m_profile.VerifyName();
                if (File.Exists(m_profile.Name))
                {
                    m_file = new FileStream(m_profile.Name, FileMode.Open, m_profile.ReadOnly ? FileAccess.Read : FileAccess.ReadWrite, FileShare.Read);
                }
            }
        }
Пример #3
0
 /// <summary>
 ///   Initializes a new instance of the XmlBased class based on another XmlBased object. </summary>
 /// <param name="profile">
 ///   The XmlBased profile object whose properties and events are used to initialize the object being constructed. </param>
 protected XmlBased(XmlBased profile)
     :
     base(profile)
 {
     m_encoding = profile.Encoding;
 }