internal DeferrableContent(Stream stream, Baml2006SchemaContext schemaContext, 
     IXamlObjectWriterFactory objectWriterFactory, IServiceProvider serviceProvider,
     object rootObject)
 {
     ObjectWriterParentSettings = objectWriterFactory.GetParentSettings();
     if (ObjectWriterParentSettings.AccessLevel != null)
     {
         XamlLoadPermission loadPermission = 
             new XamlLoadPermission(ObjectWriterParentSettings.AccessLevel);
         loadPermission.Demand();
         this.LoadPermission = loadPermission;
     }
     bool assemblyTargetsFramework2 = false;
     // The local assembly can be null if it is not specified in the XamlReaderSettings.
     if (schemaContext.LocalAssembly != null)
     {
         assemblyTargetsFramework2 = schemaContext.LocalAssembly.ImageRuntimeVersion.StartsWith("v2", StringComparison.Ordinal);
     }
     // There is an incompatibility between the framework versions 3 and 4 regarding MarkupExtension resources.
     // In version 3, MarkupExtension resources did not provide values when looked up.
     // In version 4, they do.
     if (assemblyTargetsFramework2)
     {
         ObjectWriterParentSettings.SkipProvideValueOnRoot = true;
     }
     this.Stream = stream;
     this.SchemaContext = schemaContext;
     this.ObjectWriterFactory = objectWriterFactory;
     this.ServiceProvider = serviceProvider;
     this.RootObject = rootObject;
 }
Пример #2
0
        public Baml2006ReaderContext(Baml2006SchemaContext schemaContext)
        {
            if (schemaContext == null)
            {
                throw new ArgumentNullException("schemaContext");
            }

            _schemaContext = schemaContext;
        }
Пример #3
0
        public Baml2006Reader(Stream stream)
        { 
            if (stream == null) 
            {
                throw new ArgumentNullException("stream"); 
            }

            var schemaContext = new Baml2006SchemaContext(null);
            var settings = new Baml2006ReaderSettings(); 

            Initialize(stream, schemaContext, settings); 
        } 
Пример #4
0
        public Baml2006Reader(string fileName)
        { 
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            } 

            var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); 
            var schemaContext = new Baml2006SchemaContext(null); 
            var settings = System.Windows.Markup.XamlReader.CreateBamlReaderSettings();
            settings.OwnsStream = true; 

            Initialize(stream, schemaContext, settings);
        }
Пример #5
0
        public Baml2006Reader(Stream stream, XamlReaderSettings xamlReaderSettings) 
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream"); 
            }
            if (xamlReaderSettings == null) 
            { 
                throw new ArgumentNullException("xamlReaderSettings");
            } 
            Baml2006SchemaContext schemaContext;
            if (xamlReaderSettings.ValuesMustBeString)
            {
                schemaContext = new Baml2006SchemaContext(xamlReaderSettings.LocalAssembly, System.Windows.Markup.XamlReader.XamlV3SharedSchemaContext); 
            }
            else 
            { 
                schemaContext = new Baml2006SchemaContext(xamlReaderSettings.LocalAssembly);
            } 
            var settings = new Baml2006ReaderSettings(xamlReaderSettings);

            Initialize(stream, schemaContext, settings);
        } 
Пример #6
0
        internal Baml2006Reader(Stream stream, 
            Baml2006SchemaContext schemaContext, 
            Baml2006ReaderSettings settings)
        { 
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            } 

            if (schemaContext == null) 
            { 
                throw new ArgumentNullException("schemaContext");
            } 

            Initialize(stream, schemaContext, settings ?? new Baml2006ReaderSettings());
        }
Пример #7
0
        private void Initialize(Stream stream, 
            Baml2006SchemaContext schemaContext, 
            Baml2006ReaderSettings settings)
        { 
            schemaContext.Settings = settings;
            _settings = settings;
            _context = new Baml2006ReaderContext(schemaContext);
            _xamlMainNodeQueue = new XamlNodeQueue(schemaContext); 
            _xamlNodesReader = _xamlMainNodeQueue.Reader;
            _xamlNodesWriter = _xamlMainNodeQueue.Writer; 
            _lookingForAKeyOnAMarkupExtensionInADictionaryDepth = -1; 

            _isBinaryProvider = !settings.ValuesMustBeString; 

            // Since the reader owns the stream and is responsible for its lifetime
            // it can safely hand out shared streams.
            if (_settings.OwnsStream) 
            {
                stream = new SharedStream(stream); 
            } 

            _binaryReader = new BamlBinaryReader(stream); 

            _context.TemplateStartDepth = -1;

            if (!_settings.IsBamlFragment) 
            {
                Process_Header(); 
            } 
        }
Пример #8
0
 internal Baml2006Reader(
     Stream stream, 
     Baml2006SchemaContext baml2006SchemaContext, 
     Baml2006ReaderSettings baml2006ReaderSettings,
     object root) 
     : this(stream, baml2006SchemaContext, baml2006ReaderSettings)
 {
     _root = root;
 }