コード例 #1
0
        /// <summary>
        /// Saves the content of the range in the given stream as a WPF payload.
        /// </summary>
        /// <param name="range">
        /// The range whose content is to be serialized.
        /// </param>
        /// <param name="stream">
        /// When the stream is not null, it is a request to unconditionally
        /// creatte WPF package in this stream.
        /// If this parameter is null, then the package is created
        /// only when necessary - when there are images in the range.
        /// The new MemoryStream is created in this case and assigned to this
        /// parameter on exit.
        /// </param>
        /// <param name="useFlowDocumentAsRoot">
        /// </param>
        /// <param name="preserveTextElements">
        /// If set false, custom TextElements will be upcasted to known types.
        /// </param>
        /// <returns>
        /// A xaml part of serialized content.
        /// </returns>
        internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            // Create the wpf package in the stream
            WpfPayload wpfPayload = new WpfPayload(/*package:*/ null);

            // Create a string representing serialized xaml
            StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

            TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements);
            string xamlText = stringWriter.ToString();

            // Decide whether we need to create a package
            if (stream != null || wpfPayload._images != null)
            {
                // There are images in the content. Need to create a package
                if (stream == null)
                {
                    stream = new MemoryStream();
                }

                // Create a package in the stream
                using (wpfPayload.CreatePackage(stream))
                {
                    // Create the entry part for xaml content of the WPF package
                    PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart();

                    // Write the part's content
                    Stream xamlPartStream = xamlEntryPart.GetStream();
                    using (xamlPartStream)
                    {
                        StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream);
                        using (xamlPartWriter)
                        {
                            xamlPartWriter.Write(xamlText);
                        }
                    }

                    // Write relationships from xaml entry part to all images
                    wpfPayload.CreateComponentParts(xamlEntryPart);
                }

                Invariant.Assert(wpfPayload._images == null); // must have beed cleared in CreateComponentParts
            }

            return(xamlText);
        }
コード例 #2
0
        // Token: 0x06003F1E RID: 16158 RVA: 0x0012055C File Offset: 0x0011E75C
        internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }
            WpfPayload    wpfPayload   = new WpfPayload(null);
            StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

            TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements);
            string text = stringWriter.ToString();

            if (stream != null || wpfPayload._images != null)
            {
                if (stream == null)
                {
                    stream = new MemoryStream();
                }
                using (wpfPayload.CreatePackage(stream))
                {
                    PackagePart packagePart = wpfPayload.CreateWpfEntryPart();
                    Stream      stream2     = packagePart.GetStream();
                    using (stream2)
                    {
                        StreamWriter streamWriter = new StreamWriter(stream2);
                        using (streamWriter)
                        {
                            streamWriter.Write(text);
                        }
                    }
                    wpfPayload.CreateComponentParts(packagePart);
                }
                Invariant.Assert(wpfPayload._images == null);
            }
            return(text);
        }
コード例 #3
0
        /// <summary>
        /// Saves the content of the range in the given stream as a WPF payload.
        /// </summary>
        /// <param name="range">
        /// The range whose content is to be serialized.
        /// </param>
        /// <param name="stream">
        /// When the stream is not null, it is a request to unconditionally
        /// creatte WPF package in this stream.
        /// If this parameter is null, then the package is created
        /// only when necessary - when there are images in the range.
        /// The new MemoryStream is created in this case and assigned to this
        /// parameter on exit.
        /// </param>
        /// <param name="useFlowDocumentAsRoot">
        /// </param>
        /// <param name="preserveTextElements">
        /// If set false, custom TextElements will be upcasted to known types.
        /// </param>
        /// <returns>
        /// A xaml part of serialized content.
        /// </returns>
        internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            // Create the wpf package in the stream
            WpfPayload wpfPayload = new WpfPayload(/*package:*/null);

            // Create a string representing serialized xaml
            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
            TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements);
            string xamlText = stringWriter.ToString();

            // Decide whether we need to create a package
            if (stream != null || wpfPayload._images != null)
            {
                // There are images in the content. Need to create a package
                if (stream == null)
                {
                    stream = new MemoryStream();
                }

                // Create a package in the stream
                using (wpfPayload.CreatePackage(stream))
                {
                    // Create the entry part for xaml content of the WPF package
                    PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart();

                    // Write the part's content
                    Stream xamlPartStream = xamlEntryPart.GetStream();
                    using (xamlPartStream)
                    {
                        StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream);
                        using (xamlPartWriter)
                        {
                            xamlPartWriter.Write(xamlText);
                        }
                    }

                    // Write relationships from xaml entry part to all images
                    wpfPayload.CreateComponentParts(xamlEntryPart);
                }

                Invariant.Assert(wpfPayload._images == null); // must have beed cleared in CreateComponentParts
            }

            return xamlText;
        }