Esempio n. 1
0
 /// <summary>
 /// Reads XAML from the passed stream, building an object tree and returning the
 /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that
 /// uses the passed reader settings to allow validation of xaml.
 /// </summary>
 /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
 ///  other reader</param>
 /// <param name="context">Optional parser context.  May be null </param>
 /// <param name="parseMode">Sets synchronous or asynchronous parsing</param>
 /// <returns>object root generated after xml parsed</returns>
 // Note this is the internal entry point for XPS.  XPS calls here so
 // its reader is not wrapped with a Markup Compat Reader.
 internal static object Load(
     XmlReader reader,
     ParserContext parserContext,
     XamlParseMode parseMode)
 {
     return(Load(reader, parserContext, parseMode, useRestrictiveXamlReader: false));
 }
Esempio n. 2
0
        /// <summary>
        /// Reads XAML from the passed stream, building an object tree and returning the
        /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that
        /// uses the passed reader settings to allow validation of xaml.
        /// </summary>
        /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
        ///  other reader</param>
        /// <param name="context">Optional parser context.  May be null </param>
        /// <param name="parseMode">Sets synchronous or asynchronous parsing</param>
        /// <returns>object root generated after xml parsed</returns>
        // Note this is the internal entry point for XPS.  XPS calls here so
        // its reader is not wrapped with a Markup Compat Reader.
        internal static object Load(
            XmlReader reader,
            ParserContext parserContext,
            XamlParseMode parseMode)
        {
            if (parseMode == XamlParseMode.Uninitialized ||
                parseMode == XamlParseMode.Asynchronous)
            {
                XamlReader xamlReader = new XamlReader();
                return(xamlReader.LoadAsync(reader, parserContext));
            }

            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }

#if DEBUG_CLR_MEM
            bool clrTracingEnabled = false;
            // Use local pass variable to correctly log nested parses.
            int pass = 0;

            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
                (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
            {
                clrTracingEnabled = true;
                pass = ++_CLRXamlPass;
                CLRProfilerControl.CLRLogWriteLine("Begin_XamlParse_{0}", pass);
            }
#endif // DEBUG_CLR_MEM

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlBegin, parserContext.BaseUri);

            if (TraceMarkup.IsEnabled)
            {
                TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.Load);
            }
            object root = null;
            try
            {
                if (parserContext.BaseUri == null ||
                    String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                {
                    if (reader.BaseURI == null ||
                        String.IsNullOrEmpty(reader.BaseURI.ToString()))
                    {
                        parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                    }
                    else
                    {
                        parserContext.BaseUri = new Uri(reader.BaseURI);
                    }
                }

                System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
                settings.IgnoreUidsOnPropertyElements = true;
                settings.BaseUri         = parserContext.BaseUri;
                settings.ProvideLineInfo = true;

                XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ?
                                                  parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();
                System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);
                root = Load(xamlXmlReader, parserContext);
                reader.Close();
            }
            catch (Exception e)
            {
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri))
                {
                    throw;
                }
                RewrapException(e, parserContext.BaseUri);
            }
            finally
            {
                if (TraceMarkup.IsEnabled)
                {
                    TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.Load, root);
                }

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlEnd, parserContext.BaseUri);

#if DEBUG_CLR_MEM
                if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
                {
                    CLRProfilerControl.CLRLogWriteLine("End_XamlParse_{0}", pass);
                }
#endif // DEBUG_CLR_MEM
            }
            return(root);
        }
 // review - this needs to check that setparseMode is called only
 // once and only on the Root tag.
 internal void SetParseMode(XamlParseMode xamlParseMode)
 {
     // only update if we are allowed to update the parent nodes
     if (UpdateParentNodes)
     {
          // update the parseMode in the StartRecord.
         if (xamlParseMode == XamlParseMode.Asynchronous)
         {
             Debug.Assert(null != DocumentStartRecord);
             if (null != DocumentStartRecord)
             {
                 DocumentStartRecord.LoadAsync = true;
                 DocumentStartRecord.UpdateWrite(BinaryWriter);
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary> 
        /// Reads XAML from the passed stream, building an object tree and returning the
        /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that 
        /// uses the passed reader settings to allow validation of xaml.
        /// </summary>
        /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
        ///  other reader</param> 
        /// <param name="context">Optional parser context.  May be null </param>
        /// <param name="parseMode">Sets synchronous or asynchronous parsing</param> 
        /// <returns>object root generated after xml parsed</returns> 
        // Note this is the internal entry point for XPS.  XPS calls here so
        // its reader is not wrapped with a Markup Compat Reader. 
        internal static object Load(
            XmlReader reader,
            ParserContext parserContext,
            XamlParseMode parseMode) 
        {
            if (parseMode == XamlParseMode.Uninitialized || 
                parseMode == XamlParseMode.Asynchronous) 
            {
                XamlReader xamlReader = new XamlReader(); 
                return xamlReader.LoadAsync(reader, parserContext);
            }

            if (parserContext == null) 
            {
                parserContext = new ParserContext(); 
            } 

#if DEBUG_CLR_MEM 
            bool clrTracingEnabled = false;
            // Use local pass variable to correctly log nested parses.
            int pass = 0;
 
            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
               (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance)) 
            { 
                clrTracingEnabled = true;
                pass = ++_CLRXamlPass; 
                CLRProfilerControl.CLRLogWriteLine("Begin_XamlParse_{0}", pass);
            }
#endif // DEBUG_CLR_MEM
 
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlBegin, parserContext.BaseUri);
 
            if (TraceMarkup.IsEnabled) 
            {
                TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.Load); 
            }
            object root = null;
            try
            { 

                if (parserContext.BaseUri == null || 
                    String.IsNullOrEmpty(parserContext.BaseUri.ToString())) 
                {
                    if (reader.BaseURI == null || 
                        String.IsNullOrEmpty(reader.BaseURI.ToString()))
                    {
                        parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                    } 
                    else
                    { 
                        parserContext.BaseUri = new Uri(reader.BaseURI); 
                    }
                } 

                System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
                settings.IgnoreUidsOnPropertyElements = true;
                settings.BaseUri = parserContext.BaseUri; 
                settings.ProvideLineInfo = true;
 
                XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ? 
                    parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();
                System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings); 
                root = Load(xamlXmlReader, parserContext);
                reader.Close();
            }
            catch (Exception e) 
            {
                // Don't wrap critical exceptions or already-wrapped exceptions. 
                if(MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri)) 
                {
                    throw; 
                }
                RewrapException(e, parserContext.BaseUri);
            }
            finally 
            {
                if (TraceMarkup.IsEnabled) 
                { 
                    TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.Load, root);
                } 

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlEnd, parserContext.BaseUri);

#if DEBUG_CLR_MEM 
                if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
                { 
                    CLRProfilerControl.CLRLogWriteLine("End_XamlParse_{0}", pass); 
                }
#endif // DEBUG_CLR_MEM 
            }
            return root;
        }