private void Schematize(LogItemSchema schema, IEnumerable <LogField> items) { foreach (var item in items) { // is this a new item we haven't seen before? if (!schema.HasChild(item.Name)) { var typeName = item.Name; if (item is LogEntry) { // recurrse down the structure var s = new LogItemSchema() { Name = item.Name, Type = typeName }; schema.AddChild(s); Schematize(s, ((LogEntry)item).GetFields()); } else { // leaf node typeName = item.Value.GetType().Name; var leaf = new LogItemSchema() { Name = item.Name, Type = typeName }; schema.AddChild(leaf); } } } }
private void CreateSchema(PX4BinaryLog log) { LogItemSchema schema = new LogItemSchema() { Name = "Px4DataLog", Type = "Root" }; foreach (var fmt in log.GetFormats()) { LogItemSchema element = new LogItemSchema() { Name = fmt.Name }; int i = 0; foreach (var c in fmt.Columns) { LogItemSchema column = new LogItemSchema() { Name = c }; if (i < fmt.FormatString.Length) { column.Type = GetTypeName(fmt.FormatString[i]); } i++; element.AddChild(column); } schema.AddChild(element); } this.schema = schema; }
private void CreateSchema(object message) { Type t = message.GetType(); if (schemaCache.ContainsKey(t)) { return; } string name = t.Name; if (name.StartsWith("mavlink_")) { name = name.Substring(8); } else if (name.StartsWith("mavlink")) { name = name.Substring(7); } LogItemSchema item = new LogItemSchema() { Name = name, Type = t.Name }; foreach (FieldInfo fi in t.GetFields(BindingFlags.Public | BindingFlags.Instance)) { var field = new LogItemSchema() { Name = fi.Name, Type = fi.FieldType.Name }; item.AddChild(field); object value = fi.GetValue(message); // byte[] array is special, we return that as binhex encoded binary data. if (fi.FieldType.IsArray && fi.FieldType != typeof(byte[])) { field.IsArray = true; Type itemType = fi.FieldType.GetElementType(); Array a = (Array)value; for (int i = 0, n = a.Length; i < n; i++) { field.AddChild(new LogItemSchema() { Name = i.ToString(), Type = itemType.Name }); } } } schemaCache[t] = item; schema.AddChild(item); if (SchemaChanged != null) { SchemaChanged(this, EventArgs.Empty); } }
private LogItemSchema Clone() { LogItemSchema copy = new LogItemSchema() { Id = this.Id, Name = this.Name, Type = this.Type }; if (this.HasChildren) { lock (this.childItems) { foreach (var child in this.childItems) { var childClone = child.Clone(); copy.AddChild(childClone); } } } return(copy); }