private static void GetComplexType(DataKey key, Type t, object o, Dictionary <Type, Guid> derivedTypes) { PropertyInfo[] props = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in props) { if (!IsHidden(prop)) { DataNode node = GetNode(prop.Name, prop.GetValue(o, null), derivedTypes, IsReadOnly(prop)); if (node == null) { continue; } DataValue v = node as DataValue; if (v != null) { v.FormatString = GetFormatString(prop); } node.DisplayClass = GetMemberDisplayClass(prop); key.AddSubNode(node); } } FieldInfo[] fields = t.GetFields(); foreach (FieldInfo field in fields) { if (!IsHidden(field)) { DataNode node = GetNode(field.Name, field.GetValue(o), derivedTypes, IsReadOnly(field)); if (node == null) { continue; } DataValue v = node as DataValue; if (v != null) { v.FormatString = GetFormatString(field); } node.DisplayClass = GetMemberDisplayClass(field); key.AddSubNode(node); } } // Annotate with type GUID (if such a thing exists) if (derivedTypes.ContainsKey(t)) { key.Class = derivedTypes[t]; } key.FormatString = GetFormatString(t); }
/// <summary> /// Method called when a new frame arraives /// </summary> /// <param name="frame">The frame</param> protected override void OnInput(DataFrame frame) { DataNode[] nodes = frame.SelectNodes(SelectionPath); foreach (DataNode node in nodes) { try { MemoryStream stm = new MemoryStream(node.ToArray()); DataReader reader = new DataReader(stm); string name = node.Name; DataKey parentKey = node.Parent; node.RemoveNode(); while (stm.Position < stm.Length) { DynamicStreamDataKey2 key = new DynamicStreamDataKey2(name, Container, Graph.Logger, State); reader.ByteCount = 0; key.FromReader(reader); // The reader clearly didn't care if (reader.ByteCount == 0) { break; } parentKey.AddSubNode(key); frame.Current = key; } } catch (EndOfStreamException) { } catch (ThreadAbortException) { throw; } catch (Exception ex) { LogException(ex); } } WriteOutput(frame); }
private static void GetArrayType(DataKey key, Type t, object o, Dictionary <Type, Guid> derivedTypes, bool readOnly) { Array arr = (Array)o; for (int i = 0; i < arr.Length; ++i) { string name; object value = arr.GetValue(i); Type valuetype = value.GetType(); if (IsKeyDataPair(valuetype)) { Type g = value.GetType(); name = (string)g.GetProperty("Name").GetValue(value, null); value = g.GetProperty("Value").GetValue(value, null); } else { name = String.Format("Item{0}", i); } key.AddSubNode(GetNode(name, value, derivedTypes, readOnly)); } }
private void AddAsn1Object(string name, DataKey root, Asn1Object obj, int level, Logger logger) { Asn1Sequence seq = obj as Asn1Sequence; Asn1Set set = obj as Asn1Set; Asn1TaggedObject tag = obj as Asn1TaggedObject; string currName = name ?? obj.GetType().Name; System.Diagnostics.Trace.WriteLine(String.Format("{0} {1}", currName, obj.GetType())); if (seq != null) { if (!Config.IgnoreSequences) { DataKey key = new Asn1SequenceKey(currName, Config.NoVerify); foreach (Asn1Object o in seq) { AddAsn1Object(null, key, o, level + 1, logger); } root.AddSubNode(key); } else { root.AddValue(currName, obj.GetDerEncoded()); } } else if (set != null) { if (!Config.IgnoreSets) { DataKey key = new Asn1SetKey(currName, Config.NoVerify); foreach (Asn1Object o in set) { AddAsn1Object(null, key, o, level + 1, logger); } root.AddSubNode(key); } else { root.AddValue(currName, obj.GetDerEncoded()); } } else if (tag != null) { if (!Config.IgnoreTaggedObjects) { DataKey key = new Asn1TaggedObjectKey(currName, tag.TagNo, Config.NoVerify); root.AddSubNode(key); Asn1Object o = tag.GetObject(); DerOctetString oct = o as DerOctetString; AddAsn1Object("Object", key, tag.GetObject(), level + 1, logger); //if (oct != null) //{ // Asn1InputStream input = new Asn1InputStream(oct.GetOctetStream()); // try // { // Asn1Object next = input.ReadObject(); // if (next == null) // { // AddAsn1Object("Object", key, o, logger); // } // else // { // Asn1OctetStringObject newRoot = new Asn1OctetStringObject("Object"); // while (next != null) // { // AddAsn1Object(next.GetType().Name, newRoot, next, logger); // next = input.ReadObject(); // } // key.AddSubNode(newRoot); // } // } // catch (IOException) // { // AddAsn1Object("Object", key, o, logger); // } //} //else //{ // AddAsn1Object("Object", key, tag.GetObject(), logger); //} } else { root.AddValue(currName, obj.GetDerEncoded()); } } else { if (!Config.NoDecode) { DerStringBase str = obj as DerStringBase; DerObjectIdentifier oid = obj as DerObjectIdentifier; DerInteger i = obj as DerInteger; DerOctetString oct = obj as DerOctetString; DerBitString bits = obj as DerBitString; DerBoolean boo = obj as DerBoolean; DerNull n = obj as DerNull; DerUtcTime time = obj as DerUtcTime; DerGeneralizedTime gt = obj as DerGeneralizedTime; DerApplicationSpecific app = obj as DerApplicationSpecific; if (oct != null) { root.AddValue(new Asn1OctetStringValue(currName, oct.GetOctets())); } else if (bits != null) { root.AddSubNode(new Asn1BitStringKey(currName, bits.PadBits, bits.GetBytes())); } else if (str != null) { Type stringType = typeof(Asn1StringValue <>).MakeGenericType(str.GetType()); root.AddValue((DataValue)Activator.CreateInstance(stringType, currName, str.GetString())); } else if (oid != null) { root.AddValue(new Asn1ObjectIdentifierValue(currName, oid.Id)); } else if (i != null) { root.AddValue(new Asn1IntegerValue(currName, i.Value.ToByteArray())); } else if (boo != null) { root.AddValue(new Asn1BooleanValue(currName, boo.IsTrue)); } else if (n != null) { root.AddValue(new Asn1NullValue(currName)); } else if (time != null) { root.AddValue(new Asn1DateTimeValue(currName, time.ToDateTime())); } else if (gt != null) { root.AddValue(new Asn1GeneralizedTimeValue(currName, gt.ToDateTime())); } else if (app != null) { root.AddSubNode(new Asn1ApplicationSpecificValue(currName, app.ApplicationTag, app.GetContents())); } else { logger.LogError("Cannot convert type {0} to a class", obj.GetType().Name); root.AddValue(currName, obj.GetDerEncoded()); } } else { root.AddValue(currName, obj.GetDerEncoded()); } } }