// Token: 0x060020F3 RID: 8435 RVA: 0x000978FC File Offset: 0x00095AFC
        public void WritePIMapping(string xmlNamespace, string clrNamespace, string assemblyName)
        {
            this.VerifyWriteState();
            this.ProcessMarkupExtensionNodes();
            XamlPIMappingNode xamlPIMappingNode = new XamlPIMappingNode(0, 0, this._depth, xmlNamespace, clrNamespace, assemblyName);

            if (!this._xamlTypeMapper.PITable.Contains(xmlNamespace))
            {
                ClrNamespaceAssemblyPair clrNamespaceAssemblyPair = new ClrNamespaceAssemblyPair(clrNamespace, assemblyName);
                this._xamlTypeMapper.PITable.Add(xmlNamespace, clrNamespaceAssemblyPair);
            }
            this._bamlRecordWriter.WritePIMapping(xamlPIMappingNode);
        }
Пример #2
0
            internal void SetMappingProcessingInstruction(string xamlNamespace, ClrNamespaceAssemblyPair pair)
            {
                string clrNs = GetClrNsUri(pair.ClrNamespace, pair.AssemblyName);

                lock (syncObject)
                {
                    if (_piNamespaces == null)
                    {
                        _piNamespaces = new Dictionary <string, string>();
                    }
                    _piNamespaces[xamlNamespace] = clrNs;

                    // We potentially have a new namespace, so invalidate the cached list of namespaces
                    _allXamlNamespaces = null;
                }
            }
Пример #3
0
            internal XamlTypeMapperSchemaContext(XamlTypeMapper typeMapper)
                : base()
            {
                _typeMapper          = typeMapper;
                _sharedSchemaContext = (WpfSharedXamlSchemaContext)XamlReader.GetWpfSchemaContext();

                // Copy all the NamespaceMapEntrys from our parent into _nsDefinitions
                if (typeMapper._namespaceMaps != null)
                {
                    _nsDefinitions = new Dictionary <string, FrugalObjectList <string> >();
                    foreach (NamespaceMapEntry mapEntry in _typeMapper._namespaceMaps)
                    {
                        FrugalObjectList <string> clrNsList;
                        if (!_nsDefinitions.TryGetValue(mapEntry.XmlNamespace, out clrNsList))
                        {
                            clrNsList = new FrugalObjectList <string>(1);
                            _nsDefinitions.Add(mapEntry.XmlNamespace, clrNsList);
                        }
                        string clrNs = GetClrNsUri(mapEntry.ClrNamespace, mapEntry.AssemblyName);
                        clrNsList.Add(clrNs);
                    }
                }

                // Copy all the PIs from our parent into _piNamespaces
                if (typeMapper.PITable.Count > 0)
                {
                    _piNamespaces = new Dictionary <string, string>(typeMapper.PITable.Count);
                    foreach (DictionaryEntry entry in typeMapper.PITable)
                    {
                        ClrNamespaceAssemblyPair pair = (ClrNamespaceAssemblyPair)entry.Value;
                        string clrNs = GetClrNsUri(pair.ClrNamespace, pair.AssemblyName);
                        _piNamespaces.Add((string)entry.Key, clrNs);
                    }
                }

                _clrNamespaces = new HashSet <string>();
            }
Пример #4
0
        /// <summary>
        ///  Programmatic counterpart to the <?Mapping ... ?> XAML PI.  For example, <para/>
        ///    <?Mapping XmlNamespace="swc" ClrNamespace="System.Windows.ComponentModel" Assembly="PresentationFramework" ?>
        /// </summary>
        /// <param name="xmlNamespace">
        /// The "swc" argument in the mapping PI example.
        /// </param>
        /// <param name="clrNamespace">
        /// The "System.Windows.ComponentModel" argument in the mapping PI example.
        /// </param>
        /// <param name="assemblyName">
        /// The "PresentationFramework" argument in the mapping PI example.
        /// </param>
        public void AddMappingProcessingInstruction(
            string  xmlNamespace,
            string  clrNamespace,
            string  assemblyName )
        {
            if( null == xmlNamespace )
            {
                throw new ArgumentNullException("xmlNamespace");
            }
            if( null == clrNamespace )
            {
                throw new ArgumentNullException("clrNamespace");
            }
            if( null == assemblyName )
            {
                throw new ArgumentNullException("assemblyName");
            }

            // Parameter validation : Check for String.Empty as well?

            // Add mapping to the table keyed by xmlNamespace
            ClrNamespaceAssemblyPair pair = new ClrNamespaceAssemblyPair(clrNamespace, assemblyName);
            PITable[xmlNamespace] = pair;

            // Add mapping to the table keyed by assembly and clrnamespace
            string upperAssemblyName = assemblyName.ToUpper(
                                              TypeConverterHelper.InvariantEnglishUS);
            String fullName = clrNamespace + "#" + upperAssemblyName;

            _piReverseTable[fullName] = xmlNamespace;

            // Add mapping to the SchemaContext
            if (_schemaContext != null)
            {
                _schemaContext.SetMappingProcessingInstruction(xmlNamespace, pair);
            }
        }
Пример #5
0
        /// <summary>
        /// Write a mapping processing instruction to baml stream
        /// </summary>
        public void WritePIMapping(
            string    xmlNamespace,
            string    clrNamespace,
            string    assemblyName)
        {
            VerifyWriteState();
            ProcessMarkupExtensionNodes();

            XamlPIMappingNode piMapping = new XamlPIMappingNode(
                                                     0,
                                                     0,
                                                     _depth,
                                                     xmlNamespace,
                                                     clrNamespace,
                                                     assemblyName);
            if (!_xamlTypeMapper.PITable.Contains(xmlNamespace))
            {
                ClrNamespaceAssemblyPair mapping = new ClrNamespaceAssemblyPair(clrNamespace, assemblyName);
                _xamlTypeMapper.PITable.Add(xmlNamespace, mapping);
            }
            // Write it out anyway.  It is redundant but we are being asked to write it so write it.
            // In the round trip case this will preserve the exact file data.
            _bamlRecordWriter.WritePIMapping(piMapping);
        }
        // Parses the mapping protocol uri that specifies the namespace and assembly
        // referenced by the uri.
        private void HandleMappingProtocol(
                string mappingUri)
        {
            MappingParser parser = new MappingParser(mappingUri, MappingProtocol.Length);
            if (!parser.Parse())
                ThrowException(SRID.ParserMappingUriInvalid, mappingUri);

            // Always set up the mapping for this in the XamlTypeMapper immediately upon seeing the
            // mapping URI, since it can be needed in the very next read operation and must be in place.
            if (!XamlTypeMapper.PITable.Contains(mappingUri))
            {
                string assemblyName = parser.Assembly;
                bool isLocalAssembly = assemblyName == null || assemblyName.Length < 1;
#if PBTCOMPILER
                if (isLocalAssembly)
                    assemblyName = ReflectionHelper.LocalAssemblyName;
#endif
                ClrNamespaceAssemblyPair usingData = new ClrNamespaceAssemblyPair(parser.Namespace, assemblyName);

#if PBTCOMPILER
                usingData.LocalAssembly = isLocalAssembly;
#endif

                XamlTypeMapper.PITable.Add(mappingUri, usingData);
            }

            // Generate a pseudo mapping instruction in the BAML from the URI
            WritePI(mappingUri, parser.Namespace, parser.Assembly);
        }
Пример #7
0
            // Returns a Hashtable of ns -> NamespaceMapEntry[] containing all mappings that are
            // different from what would be returned by the shared context.
            // We don't use _typeMapper.NamespaceMapHashList because we don't want to duplicate all
            // the reflection done by the shared SchemaContext.
            // Thread safety: we assume this is called on the parser thread, and so it's safe to
            // iterate the _typeMapper's data structures.
            internal Hashtable GetNamespaceMapHashList()
            {
                // Copy the ctor-provided namespace mappings into the result
                Hashtable result = new Hashtable();

                if (_typeMapper._namespaceMaps != null)
                {
                    foreach (NamespaceMapEntry mapEntry in _typeMapper._namespaceMaps)
                    {
                        NamespaceMapEntry clone = new NamespaceMapEntry
                        {
                            XmlNamespace = mapEntry.XmlNamespace,
                            ClrNamespace = mapEntry.ClrNamespace,
                            AssemblyName = mapEntry.AssemblyName,
                            AssemblyPath = mapEntry.AssemblyPath
                        };
                        AddToMultiHashtable(result, mapEntry.XmlNamespace, clone);
                    }
                }

                // Copy the Mapping PIs into the result
                foreach (DictionaryEntry piEntry in _typeMapper.PITable)
                {
                    ClrNamespaceAssemblyPair mapping  = (ClrNamespaceAssemblyPair)piEntry.Value;
                    NamespaceMapEntry        mapEntry = new NamespaceMapEntry
                    {
                        XmlNamespace = (string)piEntry.Key,
                        ClrNamespace = mapping.ClrNamespace,
                        AssemblyName = mapping.AssemblyName,
                        AssemblyPath = _typeMapper.AssemblyPathFor(mapping.AssemblyName)
                    };
                    AddToMultiHashtable(result, mapEntry.XmlNamespace, mapEntry);
                }

                // Add any clr-namespaces that were resolved using custom assembly paths
                lock (syncObject)
                {
                    foreach (string clrNs in _clrNamespaces)
                    {
                        string clrNamespace, assembly;
                        SplitClrNsUri(clrNs, out clrNamespace, out assembly);
                        if (!string.IsNullOrEmpty(assembly))
                        {
                            string assemblyPath = _typeMapper.AssemblyPathFor(assembly);
                            if (!string.IsNullOrEmpty(assemblyPath))
                            {
                                NamespaceMapEntry mapEntry = new NamespaceMapEntry
                                {
                                    XmlNamespace = clrNs,
                                    ClrNamespace = clrNamespace,
                                    AssemblyName = assembly,
                                    AssemblyPath = assemblyPath
                                };
                                AddToMultiHashtable(result, mapEntry.XmlNamespace, mapEntry);
                            }
                        }
                    }
                }

                // Convert all the lists to arrays
                object[] keys = new object[result.Count];
                result.Keys.CopyTo(keys, 0);
                foreach (object key in keys)
                {
                    List <NamespaceMapEntry> list = (List <NamespaceMapEntry>)result[key];
                    result[key] = list.ToArray();
                }

                return(result);
            }
Пример #8
0
        // Read a single record and process it.  Return false if there are no 
        // more records to process.
        internal virtual bool ReadRecord(BamlRecord bamlRecord)
        {
            bool moreData = true; 

#if !STRESS 
            try 
            {
#endif 
                switch (bamlRecord.RecordType)
                {
                    case BamlRecordType.DocumentStart:
                        ReadDocumentStartRecord((BamlDocumentStartRecord)bamlRecord); 
                        break;
 
                    case BamlRecordType.DocumentEnd: 
                        ReadDocumentEndRecord();
                        moreData = false; 
                        break;

                    case BamlRecordType.XmlnsProperty:
                        ReadXmlnsPropertyRecord((BamlXmlnsPropertyRecord)bamlRecord); 
                        break;
 
                    case BamlRecordType.PIMapping: 
                        {
                            // If this mapping has not already been set up, then set it now 
                            BamlPIMappingRecord piMappingRecord = (BamlPIMappingRecord)bamlRecord;
                            if (!XamlTypeMapper.PITable.Contains(piMappingRecord.XmlNamespace))
                            {
                                BamlAssemblyInfoRecord assemblyInfo = MapTable.GetAssemblyInfoFromId(piMappingRecord.AssemblyId); 
                                // Add information to the MappingPI hashtable
                                ClrNamespaceAssemblyPair mapping = new ClrNamespaceAssemblyPair( 
                                                                        piMappingRecord.ClrNamespace, 
                                                                        assemblyInfo.AssemblyFullName);
                                XamlTypeMapper.PITable.Add(piMappingRecord.XmlNamespace, mapping); 
                            }
                            break;
                        }
 
                    case BamlRecordType.AssemblyInfo:
                        MapTable.LoadAssemblyInfoRecord((BamlAssemblyInfoRecord)bamlRecord); 
                        break; 

                    case BamlRecordType.TypeInfo: 
                    case BamlRecordType.TypeSerializerInfo:
                        MapTable.LoadTypeInfoRecord((BamlTypeInfoRecord)bamlRecord);
                        break;
 
                    case BamlRecordType.AttributeInfo:
                        MapTable.LoadAttributeInfoRecord((BamlAttributeInfoRecord)bamlRecord); 
                        break; 

                    case BamlRecordType.StringInfo: 
                        MapTable.LoadStringInfoRecord((BamlStringInfoRecord)bamlRecord);
                        break;

                    case BamlRecordType.LiteralContent: 
                        ReadLiteralContentRecord((BamlLiteralContentRecord)bamlRecord);
                        break; 
 
                    case BamlRecordType.ElementStart:
                    case BamlRecordType.StaticResourceStart: 
                        if (((BamlElementStartRecord)bamlRecord).IsInjected)
                        {
                            CurrentContext.SetFlag(ReaderFlags.InjectedElement);
                        } 
                        else
                        { 
                            ReadElementStartRecord((BamlElementStartRecord)bamlRecord); 
                        }
                        break; 

                    case BamlRecordType.NamedElementStart:
                        // This is only used by template code, and only as a temporary record, so should never occur here.
                        // See comment on BamlNamedElementStartRecord 
                        Debug.Assert(false);
                        break; 
 
                    case BamlRecordType.ConnectionId:
                        ReadConnectionId((BamlConnectionIdRecord)bamlRecord); 
                        break;

                    case BamlRecordType.ElementEnd:
                    case BamlRecordType.StaticResourceEnd: 
                        if (CurrentContext.CheckFlag(ReaderFlags.InjectedElement))
                        { 
                            CurrentContext.ClearFlag(ReaderFlags.InjectedElement); 
                        }
                        else 
                        {
                            ReadElementEndRecord(false);
                        }
                        break; 

                    case BamlRecordType.PropertyComplexStart: 
                        ReadPropertyComplexStartRecord((BamlPropertyComplexStartRecord)bamlRecord); 
                        break;
 
                    case BamlRecordType.PropertyComplexEnd:
                        ReadPropertyComplexEndRecord();
                        break;
 
                    case BamlRecordType.Property:
                        ReadPropertyRecord((BamlPropertyRecord)bamlRecord); 
                        break; 

                    case BamlRecordType.PropertyStringReference: 
                        ReadPropertyStringRecord((BamlPropertyStringReferenceRecord)bamlRecord);
                        break;

                    case BamlRecordType.PropertyTypeReference: 
                        ReadPropertyTypeRecord((BamlPropertyTypeReferenceRecord)bamlRecord);
                        break; 
 
                    case BamlRecordType.PropertyWithExtension:
                        ReadPropertyWithExtensionRecord((BamlPropertyWithExtensionRecord)bamlRecord); 
                        break;

                    case BamlRecordType.PropertyWithConverter:
                        ReadPropertyConverterRecord((BamlPropertyWithConverterRecord)bamlRecord); 
                        break;
 
                    case BamlRecordType.PropertyCustom: 
                        ReadPropertyCustomRecord((BamlPropertyCustomRecord)bamlRecord);
                        break; 

                    case BamlRecordType.PropertyArrayStart:
                        ReadPropertyArrayStartRecord((BamlPropertyArrayStartRecord)bamlRecord);
                        break; 

                    case BamlRecordType.PropertyArrayEnd: 
                        ReadPropertyArrayEndRecord(); 
                        break;
 
                    case BamlRecordType.PropertyIListStart:
                        ReadPropertyIListStartRecord((BamlPropertyIListStartRecord)bamlRecord);
                        break;
 
                    case BamlRecordType.PropertyIListEnd:
                        ReadPropertyIListEndRecord(); 
                        break; 

                    case BamlRecordType.PropertyIDictionaryStart: 
                        ReadPropertyIDictionaryStartRecord((BamlPropertyIDictionaryStartRecord)bamlRecord);
                        break;

                    case BamlRecordType.PropertyIDictionaryEnd: 
                        ReadPropertyIDictionaryEndRecord();
                        break; 
 
                    case BamlRecordType.DefAttribute:
                        ReadDefAttributeRecord((BamlDefAttributeRecord)bamlRecord); 
                        break;

                    case BamlRecordType.DefAttributeKeyType:
                        ReadDefAttributeKeyTypeRecord((BamlDefAttributeKeyTypeRecord)bamlRecord); 
                        break;
 
                    case BamlRecordType.PresentationOptionsAttribute: 
                        ReadPresentationOptionsAttributeRecord((BamlPresentationOptionsAttributeRecord)bamlRecord);
                        break; 

                    case BamlRecordType.RoutedEvent:
                        {
                            Debug.Assert(ReaderFlags.DependencyObject == CurrentContext.ContextType); 
                            DependencyObject currentParent = GetCurrentObjectData() as DependencyObject;
                            BamlRoutedEventRecord bamlRoutedEventRecord = (BamlRoutedEventRecord)bamlRecord; 
 
                            //
 


                            ThrowException(SRID.ParserBamlEvent, bamlRoutedEventRecord.Value);
                        } 
                        break;
 
                    case BamlRecordType.Text: 
                    case BamlRecordType.TextWithId:
                    case BamlRecordType.TextWithConverter: 
                        ReadTextRecord((BamlTextRecord)bamlRecord);
                        break;

                    case BamlRecordType.DeferableContentStart: 
                        ReadDeferableContentStart((BamlDeferableContentStartRecord)bamlRecord);
                        break; 
 
                    case BamlRecordType.KeyElementStart:
                        ReadKeyElementStartRecord((BamlKeyElementStartRecord)bamlRecord); 
                        break;

                    case BamlRecordType.KeyElementEnd:
                        ReadKeyElementEndRecord(); 
                        break;
 
                    case BamlRecordType.ConstructorParametersStart: 
                        ReadConstructorParametersStartRecord();
                        break; 

                    case BamlRecordType.ConstructorParametersEnd:
                        ReadConstructorParametersEndRecord();
                        break; 

                    case BamlRecordType.ConstructorParameterType: 
                        ReadConstructorParameterTypeRecord((BamlConstructorParameterTypeRecord)bamlRecord); 
                        break;
 
                    case BamlRecordType.ContentProperty:
                        ReadContentPropertyRecord((BamlContentPropertyRecord)bamlRecord);
                        break;
 
                    case BamlRecordType.StaticResourceId:
                        ReadStaticResourceIdRecord((BamlStaticResourceIdRecord)bamlRecord); 
                        break; 

                    case BamlRecordType.PropertyWithStaticResourceId: 
                        ReadPropertyWithStaticResourceIdRecord((BamlPropertyWithStaticResourceIdRecord)bamlRecord);
                        break;

                    case BamlRecordType.LineNumberAndPosition:  // Should be skipped in ReadNextRecordWithDebugExtension. 
                    case BamlRecordType.LinePosition:           // Should be skipped in ReadNextRecordWithDebugExtension.
                    default: 
                        ThrowException(SRID.ParserUnknownBaml, ((int)bamlRecord.RecordType).ToString(CultureInfo.CurrentCulture)); 
                        break;
                } 

#if !STRESS
            }
 
            catch (Exception e)
            { 
                // Don't wrap critical exceptions or already-wrapped exceptions. 
                if (CriticalExceptions.IsCriticalException(e) || e is XamlParseException )
                { 
                    throw;
                }

                XamlParseException.ThrowException( ParserContext, 
                                               LineNumber,
                                               LinePosition, 
                                               String.Empty /*message*/, 
                                               e );
 

            }
#endif
            return moreData; 
        }