public static object LoadDeferredContent(System.Xaml.XamlReader xamlReader, IXamlObjectWriterFactory writerFactory,
                                                 bool skipJournaledProperties, Object rootObject, XamlObjectWriterSettings parentSettings, Uri baseUri)
        {
            XamlObjectWriterSettings settings = XamlReader.CreateObjectWriterSettings(parentSettings);

            // Don't set settings.RootObject because this isn't the real root
            return(Load(xamlReader, writerFactory, skipJournaledProperties, rootObject, settings, baseUri));
        }
        public static object Load(System.Xaml.XamlReader xamlReader, bool skipJournaledProperties, Uri baseUri)
        {
            XamlObjectWriterSettings settings = XamlReader.CreateObjectWriterSettings();
            object result = WpfXamlLoader.Load(xamlReader, null, skipJournaledProperties, null, settings, baseUri);

            EnsureXmlNamespaceMaps(result, xamlReader.SchemaContext);
            return(result);
        }
Ejemplo n.º 3
0
        private object LoadAsync(XmlReader reader, ParserContext parserContext)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

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

            _xmlReader = reader;
            object rootObject = null;

            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);
                }
            }
            _baseUri = parserContext.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();

            try
            {
                _textReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);

                _stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());

                System.Xaml.XamlObjectWriterSettings objectSettings = XamlReader.CreateObjectWriterSettings();
                objectSettings.AfterBeginInitHandler = delegate(object sender, System.Xaml.XamlObjectEventArgs args)
                {
                    if (rootObject == null)
                    {
                        rootObject      = args.Instance;
                        _styleConnector = rootObject as IStyleConnector;
                    }

                    UIElement uiElement = args.Instance as UIElement;
                    if (uiElement != null)
                    {
                        uiElement.SetPersistId(_persistId++);
                    }

                    DependencyObject dObject = args.Instance as DependencyObject;
                    if (dObject != null && _stack.CurrentFrame.XmlnsDictionary != null)
                    {
                        XmlnsDictionary dictionary = _stack.CurrentFrame.XmlnsDictionary;
                        dictionary.Seal();

                        XmlAttributeProperties.SetXmlnsDictionary(dObject, dictionary);
                    }
                };

                _objectWriter            = new System.Xaml.XamlObjectWriter(_textReader.SchemaContext, objectSettings);
                _parseCancelled          = false;
                _skipJournaledProperties = parserContext.SkipJournaledProperties;

                XamlMember synchronousModeProperty   = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "SynchronousMode");
                XamlMember synchronousRecordProperty = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "AsyncRecords");

                System.Xaml.XamlReader xamlReader = _textReader;

                IXamlLineInfo         xamlLineInfo         = xamlReader as IXamlLineInfo;
                IXamlLineInfoConsumer xamlLineInfoConsumer = _objectWriter as IXamlLineInfoConsumer;
                bool shouldPassLineNumberInfo = false;
                if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) &&
                    (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo))
                {
                    shouldPassLineNumberInfo = true;
                }

                bool async = false;
                bool lastPropWasSyncMode    = false;
                bool lastPropWasSyncRecords = false;

                while (!_textReader.IsEof)
                {
                    WpfXamlLoader.TransformNodes(xamlReader, _objectWriter, true /*onlyLoadOneNode*/, _skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, _stack, _styleConnector);

                    if (xamlReader.NodeType == System.Xaml.XamlNodeType.StartMember)
                    {
                        if (xamlReader.Member == synchronousModeProperty)
                        {
                            lastPropWasSyncMode = true;
                        }
                        else if (xamlReader.Member == synchronousRecordProperty)
                        {
                            lastPropWasSyncRecords = true;
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.Value)
                    {
                        if (lastPropWasSyncMode == true)
                        {
                            if (xamlReader.Value as String == "Async")
                            {
                                async = true;
                            }
                        }
                        else if (lastPropWasSyncRecords == true)
                        {
                            if (xamlReader.Value is int)
                            {
                                _maxAsynxRecords = (int)xamlReader.Value;
                            }
                            else if (xamlReader.Value is String)
                            {
                                _maxAsynxRecords = Int32.Parse(xamlReader.Value as String, TypeConverterHelper.InvariantEnglishUS);
                            }
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.EndMember)
                    {
                        lastPropWasSyncMode    = false;
                        lastPropWasSyncRecords = false;
                    }

                    if (async && rootObject != null)
                    {
                        break;
                    }
                }
            }
            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);
            }

            if (!_textReader.IsEof)
            {
                Post();
                //ThreadStart threadStart = new ThreadStart(ReadXamlAsync);
                //Thread thread = new Thread(threadStart);
                //thread.Start();
            }
            else
            {
                TreeBuildComplete();
            }

            if (rootObject is DependencyObject)
            {
                if (parserContext.BaseUri != null && !String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                {
                    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, parserContext.BaseUri);
                }
                //else
                //    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, BaseUriHelper.PackAppBaseUri);
                WpfXamlLoader.EnsureXmlNamespaceMaps(rootObject, schemaContext);
            }

            Application app = rootObject as Application;

            if (app != null)
            {
                app.ApplicationMarkupBaseUri = GetBaseUri(settings.BaseUri);
            }

            return(rootObject);
        }
        // Token: 0x0600238A RID: 9098 RVA: 0x000AD808 File Offset: 0x000ABA08
        private object LoadAsync(XmlReader reader, ParserContext parserContext)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }
            this._xmlReader = reader;
            object rootObject = null;

            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);
                }
            }
            this._baseUri = parserContext.BaseUri;
            XamlXmlReaderSettings xamlXmlReaderSettings = new XamlXmlReaderSettings();

            xamlXmlReaderSettings.IgnoreUidsOnPropertyElements = true;
            xamlXmlReaderSettings.BaseUri         = parserContext.BaseUri;
            xamlXmlReaderSettings.ProvideLineInfo = true;
            XamlSchemaContext schemaContext = (parserContext.XamlTypeMapper != null) ? parserContext.XamlTypeMapper.SchemaContext : XamlReader.GetWpfSchemaContext();

            try
            {
                this._textReader = new XamlXmlReader(reader, schemaContext, xamlXmlReaderSettings);
                this._stack      = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());
                XamlObjectWriterSettings xamlObjectWriterSettings = XamlReader.CreateObjectWriterSettings();
                xamlObjectWriterSettings.AfterBeginInitHandler = delegate(object sender, XamlObjectEventArgs args)
                {
                    if (rootObject == null)
                    {
                        rootObject           = args.Instance;
                        this._styleConnector = (rootObject as IStyleConnector);
                    }
                    UIElement uielement = args.Instance as UIElement;
                    if (uielement != null)
                    {
                        UIElement uielement2 = uielement;
                        XamlReader < > 4__this = this;
                        int persistId = this._persistId;
                        < > 4__this._persistId = persistId + 1;
                        uielement2.SetPersistId(persistId);
                    }
                    DependencyObject dependencyObject = args.Instance as DependencyObject;
                    if (dependencyObject != null && this._stack.CurrentFrame.XmlnsDictionary != null)
                    {
                        XmlnsDictionary xmlnsDictionary = this._stack.CurrentFrame.XmlnsDictionary;
                        xmlnsDictionary.Seal();
                        XmlAttributeProperties.SetXmlnsDictionary(dependencyObject, xmlnsDictionary);
                    }
                };
Ejemplo n.º 5
0
        // Token: 0x06002267 RID: 8807 RVA: 0x000AAD70 File Offset: 0x000A8F70
        public static object LoadDeferredContent(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, XamlObjectWriterSettings parentSettings, Uri baseUri)
        {
            XamlObjectWriterSettings settings = XamlReader.CreateObjectWriterSettings(parentSettings);

            return(WpfXamlLoader.Load(xamlReader, writerFactory, skipJournaledProperties, rootObject, settings, baseUri));
        }