예제 #1
0
        internal Type GetTypeOfFirstStartObject(KeyRecord record)
        { 
            _context.CurrentKey = _context.KeyList.IndexOf(record);
 
            // This means we're at the end of the Deferred Content 
            // Break out and return null
            if (record.ValuePosition == _binaryReader.BaseStream.Length) 
            {
                return null;
            }
 
            _binaryReader.BaseStream.Seek(record.ValuePosition, SeekOrigin.Begin);
 
            if (Read_RecordType() != Baml2006RecordType.ElementStart) 
            {
                throw new XamlParseException(); 
            }

            return BamlSchemaContext.GetClrType(_binaryReader.ReadInt16());
        } 
예제 #2
0
        private void Process_DefAttributeKeyString() 
        {
            Read_RecordSize(); 
            Int16 keyStringId = _binaryReader.ReadInt16(); 
            Int32 valuePosition = _binaryReader.ReadInt32();
            bool isShared = _binaryReader.ReadBoolean(); 
            bool isSharedSet = _binaryReader.ReadBoolean();
            string value = _context.SchemaContext.GetString(keyStringId);

            KeyRecord key = new KeyRecord(isShared, isSharedSet, valuePosition, value); 
            if (_context.CurrentFrame.IsDeferredContent)
            { 
                _context.KeyList.Add(key); 
            }
            else 
            {
                _context.CurrentFrame.Key = key;
            }
        } 
예제 #3
0
        private void Process_KeyElementStart()
        {
            Int16 typeId = _binaryReader.ReadInt16();
            byte flags = _binaryReader.ReadByte(); 
            Int32 valuePosition = _binaryReader.ReadInt32();
            bool isShared = _binaryReader.ReadBoolean(); 
            bool isSharedSet = _binaryReader.ReadBoolean(); 

            XamlType type = _context.SchemaContext.GetXamlType(typeId); 

            _context.PushScope();
            _context.CurrentFrame.XamlType = type;
 
            // Store a key record that can be accessed later.
            // This is a complex scenario so we need to write to the keyList 
            KeyRecord key = new KeyRecord(isShared, isSharedSet, valuePosition, _context.SchemaContext); 
            key.Flags = flags;
            key.KeyNodeList.Writer.WriteStartObject(type); 


            _context.InsideKeyRecord = true;
 
            // Push the current writer onto a stack and add the KeyNodeList writer.
            // All subsequent calls will be added to that writer. 
            _xamlWriterStack.Push(_xamlNodesWriter); 
            _xamlNodesWriter = key.KeyNodeList.Writer;
 
            if (_context.PreviousFrame.IsDeferredContent)
            {
                _context.KeyList.Add(key);
            } 
            else
            { 
                _context.PreviousFrame.Key = key; 
            }
        } 
예제 #4
0
        internal XamlReader ReadObject(KeyRecord record)
        { 
            // This means we're at the end of the Deferred Content 
            // Break out and return null
            if (record.ValuePosition == _binaryReader.BaseStream.Length) 
            {
                return null;
            }
 
            _binaryReader.BaseStream.Seek(record.ValuePosition, SeekOrigin.Begin);
 
            _context.CurrentKey = _context.KeyList.IndexOf(record); 

            if (_xamlMainNodeQueue.Count > 0) 
            {
                //
                throw new XamlParseException();
            } 

            if (Read_RecordType() != Baml2006RecordType.ElementStart) 
            { 
                throw new XamlParseException();
            } 

            XamlWriter oldQueueWriter = _xamlNodesWriter;

            // estimates from statistical examiniation of Theme Resource Data. 
            // small RD entries appear to have about a 2.2 bytes to XamlNode ration.
            // larger RD entries are less dense (due to data) at about 4.25. 
            // Presizing the XamlNodeLists save upto 50% in memory useage for same. 
            int initialSizeOfNodeList = (record.ValueSize < 800)
                        ? (int)(record.ValueSize / 2.2) 
                        : (int)(record.ValueSize / 4.25);

            initialSizeOfNodeList = (initialSizeOfNodeList < 8) ? 8 : initialSizeOfNodeList;
 
            var result = new XamlNodeList(_xamlNodesReader.SchemaContext, initialSizeOfNodeList);
            _xamlNodesWriter = result.Writer; 
 
            Baml2006ReaderFrame baseFrame = _context.CurrentFrame;
            Process_ElementStart(); 

            while (baseFrame != _context.CurrentFrame)
            {
                Process_OneBamlRecord(); 
            }
            _xamlNodesWriter.Close(); 
 
            _xamlNodesWriter = oldQueueWriter;
            return result.GetReader(); 
        }
예제 #5
0
        private void Process_DefAttributeKeyType() 
        { 
            Int16 typeId = _binaryReader.ReadInt16();
            byte flags = _binaryReader.ReadByte(); 
            Int32 valuePosition = _binaryReader.ReadInt32();
            bool isShared = _binaryReader.ReadBoolean();
            bool isSharedSet = _binaryReader.ReadBoolean();
 
            Type type = Baml2006SchemaContext.KnownTypes.GetKnownType(typeId);
            if (type == null) 
            { 
                type = BamlSchemaContext.GetClrType(typeId);
            } 
            KeyRecord key = new KeyRecord(isShared, isSharedSet, valuePosition, type);
            if (_context.CurrentFrame.IsDeferredContent)
            {
                _context.KeyList.Add(key); 
            }
            else 
            { 
                _context.CurrentFrame.Key = key;
            } 
        }
예제 #6
0
 private bool CanCache(KeyRecord keyRecord, object value)
 {
     if (keyRecord.SharedSet) 
     {
         return keyRecord.Shared; 
     } 
     else
     { 
         return true;
     }
 }
예제 #7
0
        private object CreateObject(KeyRecord key) 
        {
            System.Xaml.XamlReader xamlReader = _reader.ReadObject(key); 
            // v3 Markup Compiler will occasionally produce deferred
            // content with keys but no values.  We need to allow returning
            // null in this scenario to match v3 compat and not throw an
            // error. 
            if (xamlReader == null)
                return null; 
 
            Uri baseUri = (_rootElement is IUriContext) ? ((IUriContext)_rootElement).BaseUri : _baseUri;
            if (_xamlLoadPermission != null) 
            {
                _xamlLoadPermission.Assert();
                try
                { 
                    return WpfXamlLoader.LoadDeferredContent(
                        xamlReader, _objectWriterFactory, false /*skipJournaledProperites*/, 
                        _rootElement, _objectWriterSettings, baseUri); 
                }
                finally 
                {
                    CodeAccessPermission.RevertAssert();
                }
            } 
            else
            { 
                return WpfXamlLoader.LoadDeferredContent( 
                        xamlReader, _objectWriterFactory, false /*skipJournaledProperites*/,
                        _rootElement, _objectWriterSettings, baseUri); 
            }
        }
예제 #8
0
 private Type GetTypeOfFirstObject(KeyRecord keyRecord)
 { 
     Type rootType = _reader.GetTypeOfFirstStartObject(keyRecord);
     return rootType ?? typeof(String); 
 } 
예제 #9
0
 private object GetKeyValue(KeyRecord key, IServiceProvider serviceProvider)
 {
     if (key.KeyString != null) 
     {
         return key.KeyString; 
     } 
     else if (key.KeyType != null)
     { 
         return key.KeyType;
     }
     else
     { 
         System.Xaml.XamlReader reader = key.KeyNodeList.GetReader();
         object value = EvaluateMarkupExtensionNodeList(reader, serviceProvider); 
         return value; 
     }
 }