public static void Test() { List <NOMPT> points; var run = Snapshot.IsRunningViewerStatus(); Snapshot.WriteRunningViewerStatus(); points = _randomPoints(); Snapshot.Store(points, "random:points"); points = _randomPoints(); Snapshot.Store(points, "random:points"); points = _randomPoints(); Snapshot.Store(points, "random:points"); points = _randomPoints(); Snapshot.Store(points, "more random/^%@#$%points"); points = _randomPoints(); Snapshot.Store(points, "more random/^%@#$%points"); points = _randomPoints(); Snapshot.Store(points, "more random/^%@#$%points"); Snapshot.LimitHistory(); List <SnapshotCategory> all = Snapshot.GetCollection(); all[0].Selected = all[0].Collection[0]; var headers = all[0].GetSelectedSnapshotHeaderTitles(); var types = all[0].GetSelectedSnapshotHeaderTypes(); string name = all[0].Name; SnapshotItem sItem = all[0].GetSelectedItem(); for (int i = 0; i < headers.Count; i++) { string header = headers[i]; var typ = types[i]; switch (typ) { case TypeCode.Boolean: break; case TypeCode.Char: break; case TypeCode.SByte: break; case TypeCode.Byte: break; case TypeCode.Int16: break; case TypeCode.UInt16: break; case TypeCode.Int32: List <int> iList = sItem.GetIntegerArray(header); break; case TypeCode.UInt32: break; case TypeCode.Int64: break; case TypeCode.UInt64: break; case TypeCode.Single: List <float> flist = sItem.GetFloatArray(header); break; case TypeCode.Double: List <double> dList = sItem.GetDoubleArray(header); break; case TypeCode.Decimal: break; case TypeCode.DateTime: break; case TypeCode.String: List <string> sList = sItem.GetStringArray(header); break; default: break; } } foreach (var item in all) { item.LineColor = Color.Red; } Snapshot.WriteSettings(all); run = Snapshot.IsRunningViewerStatus(); }
public static string Store <T>(List <T> data, string name, string sub) { if (!Snapshot.IsRunningViewerStatus()) { return(null); } if (string.IsNullOrWhiteSpace(name)) { return(null); } string dir = GetDirectory(name); // data StringBuilder sb = new StringBuilder(); sb.AppendLine(name); // [name0, type0], [name1, type1], etc.... var fObj = data.First(); var fields = fObj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); PropertyInfo[] properties = fObj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); List <FieldInfo> outFields = new List <FieldInfo>(); List <PropertyInfo> outProps = new List <PropertyInfo>(); string str = ""; string[] permitted = new string[] { "String", "Single", "Double", "Int32" }; str += ("<Int32>" + "<[*]>,"); foreach (var field in fields) { if (permitted.Contains(field.FieldType.Name)) { outFields.Add(field); str += ("<" + field.FieldType.Name + ">" + "<" + field.Name + ">,"); } } foreach (PropertyInfo property in properties) { if (permitted.Contains(property.PropertyType.Name)) { outProps.Add(property); str += ("<" + property.PropertyType.Name + ">" + "<" + property.Name + ">,"); } } Type type = fObj.GetType(); if (type.Name == "Double") { str += ("<Double>" + "<" + name + ">,"); } else if (type.Name == "Single") { str += ("<Single>" + "<" + name + ">,"); } else if (type.Name == "Int32") { str += ("<Int32>" + "<" + name + ">,"); } sb.AppendLine(str); // < Name >< String >, < X >< Single >, < Y >< Single >, < Zdble >< Double >, < Number >< Int32 > int ic = -1; foreach (var obj in data) { ic++; // value.. matching str = ic.ToString() + ", "; foreach (FieldInfo field in outFields) { object value = field.GetValue(obj); if (field.FieldType.Name == "String") { str += ("\"" + value + "\", "); } else { str += (value != null) ? value.ToString() : ""; str += ", "; } } foreach (PropertyInfo property in outProps) { object value = property.GetValue(obj); if (property.PropertyType.Name == "String") { str += ("\"" + value + "\", "); } else { str += (value != null) ? value.ToString() : ""; str += ", "; } } if (type.Name == "Double") { str += obj.ToString(); str += ", "; } else if (type.Name == "Single") { str += obj.ToString(); str += ", "; } else if (type.Name == "Int32") { str += obj.ToString(); str += ", "; } sb.AppendLine(str); } string astr = sb.ToString(); string filename = SnapshotItem.getfilename(dir, sub); File.WriteAllText(filename, astr); Snapshot.LimitHistory(); return(filename); }