Example #1
0
        public static XElement ToXml(this BitMapItem item)
        {
            var elem = new XElement(
                EventManifestSchema.Namespace + "map",
                new XAttribute("value", string.Format(CultureInfo.InvariantCulture, "{0:X}", item.Value)));

            if (item.Symbol != null)
            {
                elem.Add(new XAttribute("symbol", item.Symbol));
            }
            AddOptionalMessage(elem, item.Message);
            return(elem);
        }
Example #2
0
        private Tuple <Map, MapEntry> ReadMap(BinaryReader r)
        {
            long offset = r.BaseStream.Position;

            uint magic = r.ReadUInt32();

            if (magic != CrimsonTags.VMAP && magic != CrimsonTags.BMAP)
            {
                throw new InternalException("Unknown map magic {0}", magic);
            }

            uint length     = r.ReadUInt32();
            uint nameOffset = r.ReadUInt32();
            uint flags      = r.ReadUInt32();
            uint count      = r.ReadUInt32();

            var itemEntries = new List <MapItemEntry>();

            for (uint i = 0; i < count; ++i)
            {
                var value     = r.ReadUInt32();
                var messageId = r.ReadUInt32();
                itemEntries.Add(new MapItemEntry {
                    Value = value, MessageId = messageId
                });
            }

            if (r.BaseStream.Position != offset + length)
            {
                throw new IOException();
            }

            string name     = r.ReadCountedStringAt(nameOffset);
            var    mapEntry = new MapEntry {
                Flags = (MapFlags)flags,
                Name  = name,
                Items = itemEntries
            };
            var map = magic == CrimsonTags.VMAP ? new ValueMap(name) : (Map) new BitMap(name);

            foreach (var itemEntry in itemEntries)
            {
                var value = Located.Create(itemEntry.Value);
                var ls    = ResolveMessage(itemEntry.MessageId);

                MapItem item;
                if (magic == CrimsonTags.VMAP)
                {
                    item = new ValueMapItem(
                        (ValueMap)map, value, ls);
                }
                else
                {
                    item = new BitMapItem((BitMap)map, value, ls);
                }
                map.Items.Add(item);
            }

            MarkObject(offset, map);

            return(Tuple.Create(map, mapEntry));
        }