Exemplo n.º 1
0
        /// <summary>
        /// Writes the final document back to the source.
        /// </summary>
        /// <param name="document">The document to write.</param>
        /// <param name="exception">Returns an exception if the write operation fails.</param>
        /// <returns>Returns true if the document was written successfully; false otherwise.</returns>
        public override bool Write(ICodeDocument document, out Exception exception)
        {
            Param.RequireNotNull(document, "document");
            exception = null;

            try
            {
                using (StreamWriter writer = new StreamWriter(this.path))
                {
                    document.Write(writer);
                    writer.Flush();
                }

                return(true);
            }
            catch (UnauthorizedAccessException ex)
            {
                exception = ex;
            }
            catch (IOException ex)
            {
                exception = ex;
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the final document back to the source.
        /// </summary>
        /// <param name="document">The document to write.</param>
        /// <param name="exception">Returns an exception if the write operation fails.</param>
        /// <returns>Returns true if the document was written successfully; false otherwise.</returns>
        public override bool Write(ICodeDocument document, out Exception exception)
        {
            Param.AssertNotNull(document, "document");

            exception = null;
            Document d = this.document;

            if (d == null)
            {
                if (this.projectItem != null)
                {
                    this.projectItem.Open(Constants.vsViewKindCode);
                    d = this.projectItem.Document;
                }
            }

            if (d != null)
            {
                try
                {
                    StringWriter writer = new StringWriter();
                    document.Write(writer);

                    TextDocument td   = (TextDocument)d.Object("TextDocument");
                    EditPoint    edit = td.StartPoint.CreateEditPoint();
                    edit.ReplaceText(td.EndPoint, writer.ToString(), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
                    return(true);
                }
                catch (COMException ex)
                {
                    exception = ex;
                    return(false);
                }
            }
            else
            {
                return(base.Write(document, out exception));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes the final document back to the source.
        /// </summary>
        /// <param name="document">The document to write.</param>
        /// <param name="exception">Returns an exception if the write operation fails.</param>
        /// <returns>Returns true if the document was written successfully; false otherwise.</returns>
        public override bool Write(ICodeDocument document, out Exception exception)
        {
            Param.AssertNotNull(document, "document");

            exception = null;
            Document d = this.document;

            if (d == null)
            {
                if (this.projectItem != null)
                {
                    this.projectItem.Open(Constants.vsViewKindCode);
                    d = this.projectItem.Document;
                }
            }

            if (d != null)
            {
                try
                {
                    StringWriter writer = new StringWriter();
                    document.Write(writer);

                    TextDocument td = (TextDocument)d.Object("TextDocument");
                    EditPoint edit = td.StartPoint.CreateEditPoint();
                    edit.ReplaceText(td.EndPoint, writer.ToString(), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
                    return true;
                }
                catch (COMException ex)
                {
                    exception = ex;
                    return false;
                }
            }
            else
            {
                return base.Write(document, out exception);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Writes the final document back to the source.
        /// </summary>
        /// <param name="document">The document to write.</param>
        /// <param name="exception">Returns an exception if the write operation fails.</param>
        /// <returns>Returns true if the document was written successfully; false otherwise.</returns>
        public override bool Write(ICodeDocument document, out Exception exception)
        {
            Param.RequireNotNull(document, "document");
            exception = null;

            try
            {
                using (StreamWriter writer = new StreamWriter(this.path))
                {
                    document.Write(writer);
                    writer.Flush();
                }

                return true;
            }
            catch (UnauthorizedAccessException ex)
            {
                exception = ex;
            }
            catch (IOException ex)
            {
                exception = ex;
            }

            return false;
        }