Example #1
0
        void DisassembleRecord(BamlContext ctx, BamlRecord record)
        {
            if (BamlNode.IsFooter(record))
            {
                while (scopeStack.Count > 0 && !BamlNode.IsMatch(scopeStack.Peek(), record))
                {
                    scopeStack.Pop();
                    output.Unindent();
                }
                if (scopeStack.Count > 0)
                {
                    scopeStack.Pop();
                    output.Unindent();
                }
            }

            output.WriteDefinition(record.Type.ToString(), BamlToolTipReference.Create(GetRecordReference(record)), TextTokenKind.Keyword, true);

            Action <BamlContext, BamlRecord> handler;

            if (handlerMap.TryGetValue(record.Type, out handler))
            {
                output.Write(" [", TextTokenKind.Text);
                handler(ctx, record);
                output.Write("]", TextTokenKind.Text);
            }

            output.WriteLine();

            if (BamlNode.IsHeader(record))
            {
                scopeStack.Push(record);
                output.Indent();
            }
        }
Example #2
0
 /// <summary>
 ///   Convert from Baml read by a baml reader into an object tree.
 ///   The context gives mapping information.  Return the number of
 ///   baml records processed.
 /// </summary>
 //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
 internal virtual void ConvertBamlToObject(
     BamlRecordReader reader,          // Current reader that is processing records
     BamlRecord bamlRecord,            // Record read in that triggered serializer
     ParserContext context)            // Context
 {
     throw new InvalidOperationException(SR.Get(SRID.InvalidDeSerialize));
 }
Example #3
0
        private bool AreEquivalent(BamlRecord expectedRecord, BamlRecord actualRecord)
        {
            _context = actualRecord;
            if (!AreEqual(expectedRecord.GetType(), actualRecord.GetType()) ||
                !AreEqual(expectedRecord.Type, actualRecord.Type))
            {
                return(false);
            }

            List <string> propertiesToCheck;

            if (!TryGetRecordPropertiesToCheck(expectedRecord, out propertiesToCheck))
            {
                return(true);
            }

            foreach (string propertyName in propertiesToCheck)
            {
                _context = string.Format("Property '{0}' of '{1}'", propertyName, actualRecord);

                _expectedValue = expectedRecord.GetPropertyValue(propertyName);
                _actualValue   = actualRecord.GetPropertyValue(propertyName);

                if (!Equals(_expectedValue, _actualValue))
                {
                    if (!Equals(_expectedValue as IEnumerable, _actualValue as IEnumerable))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #4
0
        void DisassembleRecord(BamlContext ctx, BamlRecord record)
        {
            if (BamlNode.IsFooter(record))
            {
                while (scopeStack.Count > 0 && !BamlNode.IsMatch(scopeStack.Peek(), record))
                {
                    scopeStack.Pop();
                    output.DecreaseIndent();
                }
                if (scopeStack.Count > 0)
                {
                    scopeStack.Pop();
                    output.DecreaseIndent();
                }
            }

            output.Write(record.Type.ToString(), BamlToolTipReference.Create(GetRecordReference(record)), DecompilerReferenceFlags.Local | DecompilerReferenceFlags.Definition, BoxedTextColor.Keyword);

            if (handlerMap.TryGetValue(record.Type, out var handler))
            {
                output.Write(" [", BoxedTextColor.Text);
                handler(ctx, record);
                output.Write("]", BoxedTextColor.Text);
            }

            output.WriteLine();

            if (BamlNode.IsHeader(record))
            {
                scopeStack.Push(record);
                output.IncreaseIndent();
            }
        }
Example #5
0
        /// <summary>
        ///   If the Style represented by a group of baml records is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed
        ///   collection of baml records.  For Style, this is the type of the first element record
        ///   in the record collection, skipping over the Style element itself.
        /// </summary>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
        internal override object GetDictionaryKey(BamlRecord startRecord, ParserContext parserContext)
        {
            Type       styleTargetType    = Style.DefaultTargetType;
            bool       styleTargetTypeSet = false;
            object     targetType         = null;
            int        numberOfElements   = 0;
            BamlRecord record             = startRecord;
            short      ownerTypeId        = 0;

            while (record != null)
            {
                if (record.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord elementStart = record as BamlElementStartRecord;
                    if (++numberOfElements == 1)
                    {
                        // save the type ID of the first element (i.e. <Style>)
                        ownerTypeId = elementStart.TypeId;
                    }
                    else if (numberOfElements == 2)
                    {
                        styleTargetType    = parserContext.MapTable.GetTypeFromId(elementStart.TypeId);
                        styleTargetTypeSet = true;
                        break;
                    }
                }
                else if (record.RecordType == BamlRecordType.Property && numberOfElements == 1)
                {
                    // look for the TargetType property on the <Style> element
                    BamlPropertyRecord propertyRecord = record as BamlPropertyRecord;
                    if (parserContext.MapTable.DoesAttributeMatch(propertyRecord.AttributeId, ownerTypeId, TargetTypePropertyName))
                    {
                        targetType = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                    }
                }
                else if (record.RecordType == BamlRecordType.PropertyComplexStart ||
                         record.RecordType == BamlRecordType.PropertyIListStart)
                {
                    // We didn't find the second element before a complex property like
                    // Style.Triggers, so return the default style target type:  FrameworkElement.
                    break;
                }
                record = record.Next;
            }

            if (targetType == null)
            {
                if (!styleTargetTypeSet)
                {
                    ThrowException(SRID.StyleNoDictionaryKey,
                                   parserContext.LineNumber,
                                   parserContext.LinePosition);
                }
                return(styleTargetType);
            }
            else
            {
                return(targetType);
            }
        }
Example #6
0
 // Does the given Baml Record have a Debug Baml Record in its Next link.
 internal static bool HasDebugExtensionRecord(bool isDebugBamlStream, BamlRecord bamlRecord)
 {
     if (isDebugBamlStream && (bamlRecord.Next != null))
     {
         if (IsDebugBamlRecordType(bamlRecord.Next.RecordType))
         {
             return(true);
         }
     }
     return(false);
 }
 // Does the given Baml Record have a Debug Baml Record in its Next link.
 internal static bool HasDebugExtensionRecord(bool isDebugBamlStream, BamlRecord bamlRecord)
 {
     if (isDebugBamlStream && (bamlRecord.Next != null))
     {
         if (IsDebugBamlRecordType(bamlRecord.Next.RecordType))
         {
             return true;
         }
     }
     return false;
 }
Example #8
0
        private static bool IsMergedDictionaryAttribute(BamlRecord record)
        {
            AttributeInfoRecord attributeRecord = record as AttributeInfoRecord;

            if (attributeRecord == null)
            {
                return(false);
            }

            return(attributeRecord.Name.Equals("MergedDictionaries") &&
                   attributeRecord.OwnerTypeId == ResourceDictionaryTypeId);
        }
Example #9
0
        private bool TryGetRecordPropertiesToCheck(BamlRecord expectedRecord, out List <string> propertiesToCheck)
        {
            foreach (var pair in _propertiesToCheck)
            {
                Type type = pair.Key;
                if (type.IsInstanceOfType(expectedRecord))
                {
                    propertiesToCheck = pair.Value;
                    return(true);
                }
            }

            propertiesToCheck = null;
            return(false);
        }
Example #10
0
 private static bool IsHeader(BamlRecord rec)
 {
     return(rec.Type switch
     {
         BamlRecordType.ConstructorParametersStart => true,
         BamlRecordType.DocumentStart => true,
         BamlRecordType.ElementStart => true,
         BamlRecordType.KeyElementStart => true,
         BamlRecordType.NamedElementStart => true,
         BamlRecordType.PropertyArrayStart => true,
         BamlRecordType.PropertyComplexStart => true,
         BamlRecordType.PropertyDictionaryStart => true,
         BamlRecordType.PropertyListStart => true,
         BamlRecordType.StaticResourceStart => true,
         _ => false
     });
Example #11
0
        public void AddMergedDictionaries(
            BamlDocument document, IEnumerable <string> importedFiles)
        {
            BamlRecord mergedDictionaryRecord = document.FirstOrDefault(IsMergedDictionaryAttribute);

            if (mergedDictionaryRecord != null)
            {
                HandleMergedDictionary(document, importedFiles, mergedDictionaryRecord as AttributeInfoRecord);
            }
            else
            {
                if (document.FindIndex(IsResourceDictionaryElementStart) == -1)
                {
                    //TODO: throw? (Let's hope people read the logs ^_^)
                    _logger.Error(string.Format(
                                      "Existing 'Themes/generic.xaml' in {0} is *not* a ResourceDictionary. " +
                                      "This will prevent proper WPF application merging.", _mainAssemblyName));
                    return;
                }

                int attributeInfosStartIndex = document.FindLastIndex(r => r is AssemblyInfoRecord);
                if (attributeInfosStartIndex == -1)
                {
                    _logger.Error("Invalid BAML detected. (no AssemblyInfoRecord)");
                    return;
                }

                var extraAttributes = GetMergedDictionariesAttributes().ToList();
                AdjustAttributeIds(document, (ushort)extraAttributes.Count);
                document.InsertRange(attributeInfosStartIndex + 1, extraAttributes);

                int defferableRecordIndex = document.FindIndex(r => r is DeferableContentStartRecord);
                if (attributeInfosStartIndex == -1)
                {
                    _logger.Error("Invalid BAML detected. (No DeferableContentStartRecord)");
                }

                document.InsertRange(defferableRecordIndex, GetDictionariesList(importedFiles));
            }
        }
        // Called by BamlRecordWriter records to persist a record.
        internal virtual void WriteBamlRecord(
            BamlRecord bamlRecord,
            int        lineNumber,
            int        linePosition)
        {
            try
            {
                bamlRecord.Write(BinaryWriter);

                if(DebugBamlStream)
                {
                    if(BamlRecordHelper.DoesRecordTypeHaveDebugExtension(bamlRecord.RecordType))
                    {
                        WriteDebugExtensionRecord(lineNumber, linePosition);
                    }
                }
            }
            catch (XamlParseException e)
            {
                _xamlTypeMapper.ThrowExceptionWithLine(e.Message, e.InnerException);
            }
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlTypeInfoRecord newRecord = (BamlTypeInfoRecord)record;
            newRecord._typeInfoFlags = _typeInfoFlags;
            newRecord._assemblyId = _assemblyId;
            newRecord._typeFullName = _typeFullName;
            newRecord._type = _type;
        }
Example #14
0
 static string GetRecordReference(BamlRecord record)
 {
     return(string.Format("Position: 0x{0:x}", record.Position));
 }
Example #15
0
 public BamlPathReference(BamlRecord rec, int startIdx, int endIdx)
 {
     this.rec      = rec;
     this.startIdx = startIdx;
     this.endIdx   = endIdx;
 }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlRoutedEventRecord newRecord = (BamlRoutedEventRecord)record;
            newRecord._attributeId = _attributeId;
        }
        // Helper to write out the baml record, with line numbers obtained from
        // the associated xaml node.
        private void WriteAndReleaseRecord(
            BamlRecord    bamlRecord,
            XamlNode      xamlNode)
        {
            int lineNumber = xamlNode != null ? xamlNode.LineNumber : 0;
            int linePosition = xamlNode != null ? xamlNode.LinePosition : 0;

            // If we are currently parsing a deferable content section, then queue
            // up the records for later writing
            if (_deferLoadingSupport && _deferElementDepth > 0)
            {
                if (InStaticResourceSection)
                {
                    // Gather all the BamlRecords within the StaticResource section
                    _staticResourceRecordList.Add(new ValueDeferRecord(bamlRecord, lineNumber, linePosition));
                }
                else
                {
                    ValueDeferRecord deferRec = new ValueDeferRecord(bamlRecord,
                                                                     lineNumber,
                                                                     linePosition);
                    if (_deferEndOfStartReached)
                    {
                        // If we are starting/ending a complex property, and we are at the same
                        // depth as the defered element, then track a mode so that we write to
                        // the _deferElement array instead of the key/value arrays.
                        if(_deferElementDepth == 1 && xamlNode is XamlPropertyComplexStartNode)
                        {
                            _deferComplexPropertyDepth++;
                        }

                        if(_deferComplexPropertyDepth > 0)
                        {
                            _deferElement.Add(deferRec);

                            if(_deferElementDepth == 1 && xamlNode is XamlPropertyComplexEndNode)
                            {
                                _deferComplexPropertyDepth--;
                            }
                        }
                        else if (_deferKeyCollecting)
                        {
                            ((KeyDeferRecord)_deferKeys[_deferKeys.Count-1]).RecordList.Add(deferRec);
                        }
                        else
                        {
                            _deferValues.Add(deferRec);
                        }
                    }
                    else
                    {
                        _deferElement.Add(deferRec);
                    }
                }
            }
            else
            {
                WriteBamlRecord(bamlRecord,
                                lineNumber,
                                linePosition);

                BamlRecordManager.ReleaseWriteRecord(bamlRecord);
            }
        }
Example #18
0
        /// <summary>
        ///   If the object created by this serializer is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed 
        ///   collection of baml records.  How the key is determined is up to the
        ///   individual serializer.  By default, there is no key retrieved.
        /// </summary>
#if !PBTCOMPILER
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
#endif        
        internal virtual object GetDictionaryKey(
            BamlRecord    bamlRecord, 
            ParserContext parserContext)
        {
            return null;
        }
Example #19
0
 public BamlElement(BamlRecord header)
 {
     Header = header;
 }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlAssemblyInfoRecord newRecord = (BamlAssemblyInfoRecord)record;
            newRecord._assemblyFullName = _assemblyFullName;
            newRecord._assembly = _assembly;
        }
Example #21
0
 void WriteRecordRef(BamlRecord record)
 {
     output.WriteReference(record.Type.ToString(), BamlToolTipReference.Create(GetRecordReference(record)), TextTokenKind.Keyword, true);
 }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlDocumentStartRecord newRecord = (BamlDocumentStartRecord)record;
            newRecord._maxAsyncRecords = _maxAsyncRecords;
            newRecord._loadAsync = _loadAsync;
            newRecord._filePos = _filePos;
            newRecord._debugBaml = _debugBaml;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlTextWithConverterRecord newRecord = (BamlTextWithConverterRecord)record;
            newRecord._converterTypeId = _converterTypeId;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlTextWithIdRecord newRecord = (BamlTextWithIdRecord)record;
            newRecord._valueId = _valueId;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlPropertyWithStaticResourceIdRecord newRecord = (BamlPropertyWithStaticResourceIdRecord)record;
            newRecord._attributeId = _attributeId;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlStaticResourceIdRecord newRecord = (BamlStaticResourceIdRecord)record;
            newRecord._staticResourceId = _staticResourceId;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlOptimizedStaticResourceRecord newRecord = (BamlOptimizedStaticResourceRecord)record;
            newRecord._valueId = _valueId;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlTypeInfoWithSerializerRecord newRecord = (BamlTypeInfoWithSerializerRecord)record;
            newRecord._serializerTypeId = _serializerTypeId;
            newRecord._serializerType = _serializerType;
        }
Example #29
0
 /// <summary>
 ///   Convert from Baml read by a baml reader into an object tree.
 ///   The context gives mapping information.  Return the number of
 ///   baml records processed.
 /// </summary>
 //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
 internal virtual void ConvertBamlToObject (
     BamlRecordReader    reader,       // Current reader that is processing records
     BamlRecord          bamlRecord,   // Record read in that triggered serializer
     ParserContext       context)      // Context
 {
     throw new InvalidOperationException(SR.Get(SRID.InvalidDeSerialize));
 }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlAttributeInfoRecord newRecord = (BamlAttributeInfoRecord)record;
            newRecord._ownerId = _ownerId;
            newRecord._attributeId = _attributeId;
            newRecord._name = _name;
            newRecord._ownerType = _ownerType;
            newRecord._Event = _Event;
            newRecord._dp = _dp;
            newRecord._ei = _ei;
            newRecord._pi = _pi;
            newRecord._smi = _smi;
            newRecord._gmi = _gmi;
            newRecord._dpOrMiOrPi = _dpOrMiOrPi;
        }
        internal BamlRecord CloneRecord(BamlRecord record)
        {
            BamlRecord newRecord;
            
            switch (record.RecordType)
            {
                case BamlRecordType.ElementStart:
                    if (record is BamlNamedElementStartRecord)
                    {
                        newRecord= new BamlNamedElementStartRecord();
                    }
                    else
                    {
                        newRecord = new BamlElementStartRecord();
                    }
                    break;
                    
                case BamlRecordType.PropertyCustom:
                    if (record is BamlPropertyCustomWriteInfoRecord)
                    {
                        newRecord = new BamlPropertyCustomWriteInfoRecord();
                    }
                    else
                    {
                        newRecord = new BamlPropertyCustomRecord();
                    }
                    break;
            
                default:
                    newRecord = AllocateRecord(record.RecordType);
                    break;
            }

            record.Copy(newRecord);
            
            return newRecord;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlStringInfoRecord newRecord = (BamlStringInfoRecord)record;
            newRecord._value = _value;
        }
 internal ValueDeferRecord (
     BamlRecord record,
     int        lineNumber,
     int        linePosition) : base(lineNumber, linePosition)
 {
     _record = record;
     _updateOffset = false;
 }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlContentPropertyRecord newRecord = (BamlContentPropertyRecord)record;
            newRecord._attributeId = _attributeId;
        }
Example #35
0
        /// <summary>
        ///   If the object created by this serializer is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed
        ///   collection of baml records.  How the key is determined is up to the
        ///   individual serializer.  By default, there is no key retrieved.
        /// </summary>
#if !PBTCOMPILER
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
#endif
        internal virtual object GetDictionaryKey(
            BamlRecord bamlRecord,
            ParserContext parserContext)
        {
            return(null);
        }
Example #36
0
 void WriteRecordRef(BamlRecord record) => output.Write(record.Type.ToString(), BamlToolTipReference.Create(GetRecordReference(record)), DecompilerReferenceFlags.Local, BoxedTextColor.Keyword);
Example #37
0
 public BamlPathReference(BamlRecord rec, int startIdx, int endIdx)
 {
     this.rec = rec;
     this.startIdx = startIdx;
     this.endIdx = endIdx;
 }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlNamedElementStartRecord newRecord = (BamlNamedElementStartRecord)record;
            newRecord._isTemplateChild = _isTemplateChild;
            newRecord._runtimeName = _runtimeName;
        }
 private void ProcessRecord(BamlRecord record, AssemblyDefinition containingAssembly)
 {
 }
        /// <summary>
        ///   If the Template represented by a group of baml records is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed
        ///   collection of baml records.  For ControlTemplate, this is the styleTargetType.
        ///   For DataTemplate, this is the DataTemplateKey containing the DataType.
        /// </summary>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
        internal override object GetDictionaryKey(BamlRecord startRecord,  ParserContext parserContext)
        {
            object     key = null;
            int        numberOfElements = 0;
            BamlRecord record = startRecord;
            short      ownerTypeId = 0;

            while (record != null)
            {
                if (record.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord elementStart = record as BamlElementStartRecord;
                    if (++numberOfElements == 1)
                    {
                        // save the type ID of the first element (i.e. <ControlTemplate>)
                        ownerTypeId = elementStart.TypeId;
                    }
                    else
                    {
                        // We didn't find the key before a reading the
                        // VisualTree nodes of the template
                        break;
                    }
                }
                else if (record.RecordType == BamlRecordType.Property && numberOfElements == 1)
                {
                    // look for the TargetType property on the <ControlTemplate> element
                    // or the DataType property on the <DataTemplate> element
                    BamlPropertyRecord propertyRecord = record as BamlPropertyRecord;
                    short attributeOwnerTypeId;
                    string attributeName;
                    BamlAttributeUsage attributeUsage;
                    parserContext.MapTable.GetAttributeInfoFromId(propertyRecord.AttributeId, out attributeOwnerTypeId, out attributeName, out attributeUsage);
                    if (attributeOwnerTypeId == ownerTypeId)
                    {
                        if (attributeName == TargetTypePropertyName)
                        {
                            key = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                        }
                        else if (attributeName == DataTypePropertyName)
                        {
                            object dataType = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                            Exception ex = TemplateKey.ValidateDataType(dataType, null);
                            if (ex != null)
                            {
                                ThrowException(SRID.TemplateBadDictionaryKey,
                                               parserContext.LineNumber,
                                               parserContext.LinePosition,
                                               ex);
                            }
                            // 
                            key = new DataTemplateKey(dataType);
                        }
                    }
                }
                else if (record.RecordType == BamlRecordType.PropertyComplexStart ||
                         record.RecordType == BamlRecordType.PropertyIListStart ||
                         record.RecordType == BamlRecordType.ElementEnd)
                {
                    // We didn't find the targetType before a complex property like
                    // FrameworkTemplate.VisualTree or the </ControlTemplate> tag or
                    // TableTemplate.Tree or the </TableTemplate> tag
                    break;
                }
                record = record.Next;
            }

            if (key == null)
            {
                ThrowException(SRID.StyleNoDictionaryKey,
                               parserContext.LineNumber,
                               parserContext.LinePosition,
                               null);
            }

            return key;
        }
Example #41
0
 private static bool IsResourceDictionaryElementStart(BamlRecord record)
 {
     return(record is ElementStartRecord && ((ElementStartRecord)record).TypeId == ResourceDictionaryTypeId);
 }
Example #42
0
        void ProcessProperty(BamlRecord rec, string path)
        {
            int idx = -1;
            List <BamlPathReference> refers = new List <BamlPathReference>();
            string prev    = null;
            char   prevSym = '.';

            for (int i = 0; i < path.Length; i++)
            {
                if (char.IsLetterOrDigit(path[i]) || path[i] == '_')
                {
                    if (idx == -1)
                    {
                        idx = i;
                    }
                }
                else if (i - idx > 0 && idx != -1 && (path[i] == '.' || path[i] == ')'))
                {
                    string name = path.Substring(idx, i - idx);
                    bool   hasImport;
                    var    ms = GetMember(name, out hasImport);
                    if (ms != null)
                    {
                        foreach (var m in ms)
                        {
                            Confuser.Database.AddEntry(DB_SRC, m.FullName, string.Format(
                                                           "BAML Prop Ref @ {0}:{1}:{2} => Not renamed", docName, rec.Position, path));
                            (m as IAnnotationProvider).Annotations[RenOk] = false;
                        }
                    }
                    //if (p != null && prevSym == '.')
                    //{
                    //    var specProp = p.SingleOrDefault(_ => _.DeclaringType.Name == prev);
                    //    if (specProp != null)
                    //    {
                    //        BamlPathReference refer = new BamlPathReference(rec, idx, i - 1);
                    //        refers.Add(refer);
                    //        ((specProp as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                    //    }
                    //    else
                    //        foreach (var prop in p)
                    //        {
                    //            BamlPathReference refer = new BamlPathReference(rec, idx, i - 1);
                    //            refers.Add(refer);
                    //            ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                    //        }
                    //}

                    idx     = -1;
                    prev    = name;
                    prevSym = path[i];
                }
                else
                {
                    prevSym = path[i];
                    idx     = -1;
                }
            }
            if (idx != -1)
            {
                string name = path.Substring(idx);
                bool   hasImport;
                var    ms = GetMember(name, out hasImport);
                //if (p != null)
                //    foreach (var prop in p)
                //    {
                //        BamlPathReference refer = new BamlPathReference(rec, idx, path.Length - 1);
                //        refers.Add(refer);
                //        ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                //    }
                if (ms != null)
                {
                    foreach (var m in ms)
                    {
                        Confuser.Database.AddEntry(DB_SRC, m.FullName, string.Format(
                                                       "BAML Prop Ref @ {0}:{1}:{2} => Not renamed", docName, rec.Position, path));
                        (m as IAnnotationProvider).Annotations[RenOk] = false;
                    }
                }
            }
            else
            {
                string name = path;
                bool   hasImport;
                var    ms = GetMember(name, out hasImport);
                //if (p != null)
                //    foreach (var prop in p)
                //    {
                //        BamlPathReference refer = new BamlPathReference(rec, idx, path.Length - 1);
                //        refers.Add(refer);
                //        ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                //    }
                if (ms != null)
                {
                    foreach (var m in ms)
                    {
                        Confuser.Database.AddEntry(DB_SRC, m.FullName, string.Format(
                                                       "BAML Prop Ref @ {0}:{1}:{2} => Not renamed", docName, rec.Position, path));
                        (m as IAnnotationProvider).Annotations[RenOk] = false;
                    }
                }
            }

            foreach (var i in refers)
            {
                i.refers = refers;
            }
        }
        /// <summary>
        ///   If the Template represented by a group of baml records is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed
        ///   collection of baml records.  For ControlTemplate, this is the styleTargetType.
        ///   For DataTemplate, this is the DataTemplateKey containing the DataType.
        /// </summary>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
        internal override object GetDictionaryKey(BamlRecord startRecord, ParserContext parserContext)
        {
            object     key = null;
            int        numberOfElements = 0;
            BamlRecord record           = startRecord;
            short      ownerTypeId      = 0;

            while (record != null)
            {
                if (record.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord elementStart = record as BamlElementStartRecord;
                    if (++numberOfElements == 1)
                    {
                        // save the type ID of the first element (i.e. <ControlTemplate>)
                        ownerTypeId = elementStart.TypeId;
                    }
                    else
                    {
                        // We didn't find the key before a reading the
                        // VisualTree nodes of the template
                        break;
                    }
                }
                else if (record.RecordType == BamlRecordType.Property && numberOfElements == 1)
                {
                    // look for the TargetType property on the <ControlTemplate> element
                    // or the DataType property on the <DataTemplate> element
                    BamlPropertyRecord propertyRecord = record as BamlPropertyRecord;
                    short              attributeOwnerTypeId;
                    string             attributeName;
                    BamlAttributeUsage attributeUsage;
                    parserContext.MapTable.GetAttributeInfoFromId(propertyRecord.AttributeId, out attributeOwnerTypeId, out attributeName, out attributeUsage);
                    if (attributeOwnerTypeId == ownerTypeId)
                    {
                        if (attributeName == TargetTypePropertyName)
                        {
                            key = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                        }
                        else if (attributeName == DataTypePropertyName)
                        {
                            object    dataType = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                            Exception ex       = TemplateKey.ValidateDataType(dataType, null);
                            if (ex != null)
                            {
                                ThrowException(SRID.TemplateBadDictionaryKey,
                                               parserContext.LineNumber,
                                               parserContext.LinePosition,
                                               ex);
                            }
                            //
                            key = new DataTemplateKey(dataType);
                        }
                    }
                }
                else if (record.RecordType == BamlRecordType.PropertyComplexStart ||
                         record.RecordType == BamlRecordType.PropertyIListStart ||
                         record.RecordType == BamlRecordType.ElementEnd)
                {
                    // We didn't find the targetType before a complex property like
                    // FrameworkTemplate.VisualTree or the </ControlTemplate> tag or
                    // TableTemplate.Tree or the </TableTemplate> tag
                    break;
                }
                record = record.Next;
            }

            if (key == null)
            {
                ThrowException(SRID.StyleNoDictionaryKey,
                               parserContext.LineNumber,
                               parserContext.LinePosition,
                               null);
            }

            return(key);
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlConnectionIdRecord newRecord = (BamlConnectionIdRecord)record;
            newRecord._connectionId = _connectionId;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlLinePositionRecord newRecord = (BamlLinePositionRecord)record;
            newRecord._linePosition = _linePosition;
        }
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);

            BamlDeferableContentStartRecord newRecord = (BamlDeferableContentStartRecord)record;
            newRecord._contentSize = _contentSize;
            newRecord._contentSizePosition = _contentSizePosition;
            newRecord._valuesBuffer = _valuesBuffer;
        }
Example #47
0
 static string GetRecordReference(BamlRecord record) => $"Position: 0x{record.Position:x}";
        // This should only be called from BamlRecordWriter -- it gets a record from the record
        // cache that must be freed with ReleaseRecord before GetRecord is called again.
        internal BamlRecord GetWriteRecord(BamlRecordType recordType)
        {
            // Create the cache of records used in writing, on demand

            if( _writeCache == null )
            {
                _writeCache = new BamlRecord[(int)BamlRecordType.LastRecordType];
            }

            BamlRecord record = _writeCache[(int)recordType];
            if (null == record)
            {
                record = AllocateWriteRecord(recordType);
            }
            else
            {
                _writeCache[(int)recordType] = null;
            }

            // It is important to set RecordSize for variable size records
            // to a negative number to indicate that it has not been set yet.
            // Fixed size records should ignore this set.
            record.RecordSize = -1;
            return record;
        }
        //+---------------------------------------------------------------------------------------------
        //
        //  ReleaseWriteRecord
        //
        //  Frees a record originally claimed with GetWriteRecord. Note that records in the
        //  read cache are implicitly recycled, and records in the write cache are explicitly
        //  recycled (i.e., there's a ReleaseWriteRecord, but no ReleaseReadRecord).
        //
        //+---------------------------------------------------------------------------------------------

        internal void ReleaseWriteRecord(BamlRecord record)
        {
            // Put the write record back into the cache, if we're allowed to recycle it.

            if( !record.IsPinned )
            {
                Debug.Assert(null == _writeCache[(int)record.RecordType]);
                if (null != _writeCache[(int)record.RecordType])
                {
                    // This is really an internal error.
                    throw new InvalidOperationException(SR.Get(SRID.ParserMultiBamls));
                }
                _writeCache[(int)record.RecordType] = record;
            }
        }
 internal virtual void Copy(BamlRecord record)
 {
     record._flags = _flags;
     record._nextRecord = _nextRecord;
 }
Example #51
0
        void ProcessProperty(BamlRecord rec, string path)
        {
            int idx = -1;
            List<BamlPathReference> refers = new List<BamlPathReference>();
            string prev = null;
            char prevSym = '.';
            for (int i = 0; i < path.Length; i++)
            {
                if (char.IsLetterOrDigit(path[i]) || path[i] == '_')
                {
                    if (idx == -1)
                        idx = i;
                }
                else if (i - idx > 0 && idx != -1 && (path[i] == '.' || path[i] == ')'))
                {
                    string name = path.Substring(idx, i - idx);
                    bool hasImport;
                    var ms = GetMember(name, out hasImport);
                    if (ms != null)
                        foreach (var m in ms)
                        {
                            Confuser.Database.AddEntry(DB_SRC, m.FullName, string.Format(
                                "BAML Prop Ref @ {0}:{1}:{2} => Not renamed", docName, rec.Position, path));
                            (m as IAnnotationProvider).Annotations[RenOk] = false;
                        }
                    //if (p != null && prevSym == '.')
                    //{
                    //    var specProp = p.SingleOrDefault(_ => _.DeclaringType.Name == prev);
                    //    if (specProp != null)
                    //    {
                    //        BamlPathReference refer = new BamlPathReference(rec, idx, i - 1);
                    //        refers.Add(refer);
                    //        ((specProp as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                    //    }
                    //    else
                    //        foreach (var prop in p)
                    //        {
                    //            BamlPathReference refer = new BamlPathReference(rec, idx, i - 1);
                    //            refers.Add(refer);
                    //            ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                    //        }
                    //}

                    idx = -1;
                    prev = name;
                    prevSym = path[i];
                }
                else
                {
                    prevSym = path[i];
                    idx = -1;
                }
            }
            if (idx != -1)
            {
                string name = path.Substring(idx);
                bool hasImport;
                var ms = GetMember(name, out hasImport);
                //if (p != null)
                //    foreach (var prop in p)
                //    {
                //        BamlPathReference refer = new BamlPathReference(rec, idx, path.Length - 1);
                //        refers.Add(refer);
                //        ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                //    }
                if (ms != null)
                    foreach (var m in ms)
                    {
                        Confuser.Database.AddEntry(DB_SRC, m.FullName, string.Format(
                            "BAML Prop Ref @ {0}:{1}:{2} => Not renamed", docName, rec.Position, path));
                        (m as IAnnotationProvider).Annotations[RenOk] = false;
                    }
            }
            else
            {
                string name = path;
                bool hasImport;
                var ms = GetMember(name, out hasImport);
                //if (p != null)
                //    foreach (var prop in p)
                //    {
                //        BamlPathReference refer = new BamlPathReference(rec, idx, path.Length - 1);
                //        refers.Add(refer);
                //        ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(refer);
                //    }
                if (ms != null)
                    foreach (var m in ms)
                    {
                        Confuser.Database.AddEntry(DB_SRC, m.FullName, string.Format(
                            "BAML Prop Ref @ {0}:{1}:{2} => Not renamed", docName, rec.Position, path));
                        (m as IAnnotationProvider).Annotations[RenOk] = false;
                    }
            }

            foreach (var i in refers)
                i.refers = refers;
        }
Example #52
0
 void WriteRecordRef(BamlRecord record)
 {
     output.WriteReference(record.Type.ToString(), GetRecordReference(record), TextTokenType.Keyword, true);
 }