public static void Main(string[] args) { if (args.Length < 1) throw new ArgumentException ("usage : samples"); var format = "| {0,-18} | {1,-13} | {2,-41} | {3,-18} | {4,-18} | {5,-13} | {6,-10} |"; // var stream = new FileStream (args [0], FileMode.Open); var inspector = new Common.Inspector.Inspector (args [0]); Console.WriteLine (format, "Timestamp", "Category", "Name", "Value", "Value HEX", "Type", "Unit"); Console.WriteLine ("--------------------------------------------------------------------" + "-------------------------------------------------------------------------------------"); inspector.UpdatedSample += (sender, e) => { var timestamp = new TimeSpan (0, 0, 0, 0, Convert.ToInt32 (e.Timestamp)).ToString ("G"); foreach (var c in e.Counters) { object value; string hexvalue = ""; if (c.Type == Common.Type.Long && c.Unit == Common.Unit.Time) value = new TimeSpan (Convert.ToInt64 (c.Value)).ToString ("G"); else if (c.Type == Common.Type.TimeInterval) value = new TimeSpan (Convert.ToInt64 (c.Value) * 10).ToString ("G"); else value = c.Value; switch (c.Type) { case Common.Type.String: hexvalue = ""; break; case Common.Type.Double: hexvalue = "0x" + String.Join ("", new List<byte> (BitConverter.GetBytes ((double) c.Value)).ConvertAll<string>(b => b.ToString("x2"))); break; case Common.Type.Int: case Common.Type.UInt: hexvalue = String.Format ("0x{0:x8}", c.Value); break; default: hexvalue = String.Format ("0x{0:x16}", c.Value); break; } Console.WriteLine (format, timestamp, c.CategoryName, c.Name, value, hexvalue, c.TypeName, c.UnitName); } }; inspector.Run (); }
public RunModule() { Post ["/run"] = parameters => { if (!Request.Form ["recipe_id"].HasValue) return Response.AsJson ("", HttpStatusCode.BadRequest); try { var recipe = Recipe.FindByID<Recipe> (Request.Form ["recipe_id"]); var run = new Run () { Recipe = recipe }.Save<Run> (); foreach (var file in Request.Files) { if (file.Key.Equals ("samples")) { var filename = Path.GetTempFileName (); using (var output = new FileStream (filename, FileMode.OpenOrCreate | FileMode.Truncate, FileAccess.Write, FileShare.Read)) file.Value.CopyTo (output); var inspector = new Common.Inspector.Inspector (filename); var cache = new Dictionary<ulong, Models.Counter> (); inspector.UpdatedSample += (sender, e) => { var timestamp = e.Timestamp; foreach (var counter in e.Counters) { if (!cache.ContainsKey (counter.Index)) { cache.Add (counter.Index, Models.Counter.FindByCategoryAndName (counter.CategoryName, counter.Name) ?? new Models.Counter () { Category = counter.CategoryName, Name = counter.Name, Type = counter.TypeName, Unit = counter.UnitName, Variance = counter.VarianceName }.Save<Models.Counter> ()); } new Sample () { Run = run, Counter = cache [counter.Index], Timestamp = timestamp, Value = counter.Value } .Save<Sample> (); } }; inspector.Run (); } } } catch (Exception e) { Console.WriteLine (e); } return Response.AsJson (""); }; }