public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            if (obj.IsNullObj)
            {
                return(null);
            }

            ClrObject keyClrObj = obj.GetRefFld("key");
            ClrObject valClrObj = obj.GetRefFld("val");

            if (keyClrObj.IsNullObj)
            {
                return(null);
            }

            IClrObjMappingModel keyObj = factory.BuildModel(keyClrObj);

            if (keyObj is EmptyClrObjectModel)
            {
                return(null);
            }

            IClrObjMappingModel valObj = factory.BuildModel(valClrObj);

            return(new DictionaryEntryModel(keyObj, valObj));
        }
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            var rawElelments = ProcessReferenceConcurrentDictionary(obj);

            var model = new HashtableMappingModel(rawElelments.Count, obj);

            foreach (var pair in rawElelments)
            {
                model.Elements.Add(factory.BuildModel(pair.Key), factory.BuildModel(pair.Value));
            }

            return(model);
        }
示例#3
0
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            ClrObject fld = obj.GetRefFld(entriesTableFldName);
            List <Tuple <ClrObject, ClrObject> > values = ClrCollectionHelper.EnumerateHashtable(fld);

            var hashtable = new Hashtable(values.Count);

            foreach (var keyValuePair in values)
            {
                ClrObject val = keyValuePair.Item2;
                if (val.IsNullObj)
                {
                    continue;
                }


                var       key   = val.GetStringFld("Key");
                ClrObject value = val.GetRefFld("Value");

                if (key == null || value.IsNullObj)
                {
                    continue;
                }

                IClrObjMappingModel valModel = factory.BuildModel(value);
                hashtable.Add(key, valModel);
            }

            var hashTableMapping = new HashtableMappingModel(hashtable, obj);

            return(hashTableMapping);
        }
        public static IClrObjMappingModel EnumerateList(ClrObject clrObject, ModelMapperFactory factory)
        {
            var result = new ArrayMappingModel
            {
                Obj = clrObject
            };
            ClrObject fld = clrObject.GetRefFld("_items");

            if (fld.Type == null)
            {
                return(result);
            }
            ClrType tp = fld.Type.ComponentType;

            if ((!tp.IsValueClass) && (!tp.IsString))
            {
                // TODO: add support of reading strings.
                List <ClrObject> enumeration = ClrCollectionHelper.EnumerateListOfRefTypes(clrObject);
                foreach (ClrObject o in enumeration)
                {
                    IClrObjMappingModel model = factory.BuildModel(o);
                    result.Elements.Add(model);
                }
            }

            return(result);
        }
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            // TODO: remove the hack
            var fld = obj.GetRefFld("<Values>k__BackingField");

            if (fld.IsNullObj)
            {
                return(null);
            }
            var values = factory.BuildModel(fld) as HashtableMappingModel;

            if (values == null)
            {
                return(null);
            }

            var rs = new SitecoreMVCRenderingPropertiesModel
            {
                Obj              = obj,
                Cacheable        = string.Equals(values[@"Cacheable"] as string, "1", StringComparison.OrdinalIgnoreCase),
                Cache_VaryByData = string.Equals(values[@"Cache_VaryByData"] as string, "1", StringComparison.OrdinalIgnoreCase),
                CacheKey         = values[@"CacheKey"] as string ?? "[NoCacheKey]"
            };

            ID.TryParse(values[@"RenderingItemPath"], out rs.RenderingItemPath);
            return(rs);
        }
示例#6
0
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            Dictionary <ClrObject, ClrObject> clrDictionary = ReadClrObjects(obj);
            HashtableMappingModel             model;

            if (clrDictionary == null)
            {
                return(new HashtableMappingModel(obj));
            }

            model = new HashtableMappingModel(clrDictionary.Count, obj);
            foreach (var pair in clrDictionary)
            {
                model.Elements.Add(factory.BuildModel(pair.Key), factory.BuildModel(pair.Value));
            }

            return(model);
        }
示例#7
0
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            ClrObject target = GetTargetObject(obj);

#if TRACE
            Trace.TraceInformation($"{obj.HexAddress} WeakRef points on {target.HexAddress} with {target.Type?.Name ?? "no"} type");
#endif

            return(factory.BuildModel(target));
        }
示例#8
0
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            ClrObject tablesFld = obj.GetRefFld("m_tables");

            ClrObject bucketsFld = tablesFld.GetRefFld("m_buckets");
            ClrType   type       = bucketsFld.Type;
            ClrHeap   heap       = type.Heap;

            IEnumerable <ClrObject> values = ClrCollectionHelper.EnumerateArrayOfRefTypes(bucketsFld).Where(t => !t.IsNullObj);


            ClrInstanceField valueField = type.ComponentType.GetFieldByName("m_value");

            ClrInstanceField keyField = type.ComponentType.GetFieldByName("m_key");
            var hashtableModel        = new HashtableMappingModel
            {
                Obj = obj
            };

            foreach (ClrObject val in values)
            {
                ClrObject keyObj = val.GetRefFld("m_key");
                if (keyObj.IsNullObj)
                {
                    continue;
                }

                ClrObject valObj = val.GetRefFld("m_value");

                hashtableModel.Elements.Add(
                    key: factory.BuildModel(keyObj),
                    value: factory.BuildModel(valObj));
            }

            return(hashtableModel);
        }
示例#9
0
        protected ArrayMappingModel ReadArray([ClrObjAndTypeNotEmpty] ClrObject clrObject,
                                              [NotNull] ModelMapperFactory factory)
        {
            var result = new ArrayMappingModel
            {
                Obj = clrObject
            };

            ClrObject[] arrayContent = this.EnumerationHelper.DoEnumerateArrayType(clrObject);
            if (arrayContent != null)
            {
                foreach (ClrObject o in arrayContent)
                {
                    o.ReEvaluateType();
                    IClrObjMappingModel nested = factory.BuildModel(o);
                    result.Elements.Add(nested);
                }
            }

            return(result);
        }
示例#10
0
        public override IClrObjMappingModel ReadEntity(ClrObject set, ModelMapperFactory factory)
        {
            var       heap      = set.Type.Heap;
            ClrObject container = set.GetRefFld("container");

            var m_bucketsArray = container.GetRefFld("m_tables").GetRefFld("m_buckets");

            var totalElements = m_bucketsArray.Type.GetArrayLength(m_bucketsArray.Address);

            var result = new ArrayMappingModel
            {
                Obj = set
            };

            for (int i = 0; i < totalElements; i++)
            {
                var nodeAddress = (ulong)m_bucketsArray.Type.GetArrayElementValue(m_bucketsArray.Address, i);

                if (nodeAddress == 0)
                {
                    continue;
                }

                var type = heap.GetObjectType(nodeAddress);

                if (type == null)
                {
                    continue;
                }
                var node = new ClrObject(nodeAddress, type);

                var key = node.GetRefFld("m_key");
                if (!key.IsNullObj)
                {
                    result.AddElement(factory.BuildModel(key));
                }
            }

            return(result);
        }
示例#11
0
        public override IClrObjMappingModel ReadEntity(ClrObject obj, [NotNull] ModelMapperFactory factory)
        {
            Assert.ArgumentNotNull(factory, "factory");

            if (obj.IsNullObj)
            {
                return(EmptyClrObjectModel.Instance);
            }

            var result = new EventHandlerModel
            {
                Obj    = obj,
                target = obj.GetRefFld("_target")
            };

            ClrObject invocationList = obj.GetRefFld(@"_invocationList");

            if (invocationList.IsNullObj)
            {
                // Not multicast delegate
                ClrMethod methodDescriptor;

                if (!TryReadMethodPtr(obj, out methodDescriptor))
                {
                    if (!TryResolveMethodFromTarget(obj, out methodDescriptor))
                    {
                        return(result);
                    }
                }

                result.Info = methodDescriptor;
                return(result);
            }

            // Multicast Delegate
            // TODO: Consider changing ArrayMapping
            result.InvokationList = factory.BuildModel(invocationList) as ArrayMappingModel;

            return(result);
        }
        public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory)
        {
            var hashtableModel = new HashtableMappingModel
            {
                Obj = obj
            };

            ClrObject entriesField = obj.GetRefFld(entriesFldName);

            if (entriesField == null || entriesField.Type == null)
            {
                // Object contains this field, but value is null.
                // Most likely dictionary is either in the middle of construction, or destruction.
                // Anyway we can assume it is empty.
                return(hashtableModel);
            }

            ClrType type = entriesField.Type;

            ClrHeap heap = type.Heap;

            var componentType = type.ComponentType;

            if (componentType == null)
            {
                // TODO :Try reload type.
                return(null);
            }

            ClrInstanceField valueField = componentType.GetFieldByName("value");

            ClrInstanceField keyField = componentType.GetFieldByName("key");

            int len = type.GetArrayLength(entriesField.Address);

            ulong entriesFieldAddress = entriesField.Address;

            for (int i = 0; i < len; i++)
            {
                ulong addr = type.GetArrayElementAddress(entriesFieldAddress, i);

                if (addr == 0)
                {
                    continue;
                }
                try
                {
                    var key = keyField.GetValue(addr, true);
                    if (!(key is ulong))
                    {
                        continue;
                    }
                    var keyPointer = (ulong)key;
                    if (keyPointer == 0)
                    {
                        continue;
                    }

                    var val = valueField.GetValue(addr, true);

                    ulong valuePointer;
                    if (val is ulong)
                    {
                        valuePointer = (ulong)val;
                    }
                    else
                    {
                        valuePointer = 0;
                    }

                    var keyObj = new ClrObject(keyPointer, heap);
                    var valObj = new ClrObject(valuePointer, heap);

                    hashtableModel.Elements.Add(factory.BuildModel(keyObj),
                                                factory.BuildModel(valObj));
                }
                catch (Exception)
                {
                    Trace.TraceError("Count not read {0} object", obj.HexAddress);

                    // Do nothing for now
                }
            }

            return(hashtableModel);
        }