public void TestHarImport() { TempFile temp = new TempFile(".har"); temp.Write(Resources.demohar); TrafficViewerFile tvf = new TrafficViewerFile(); var parser = new HarParser(); parser.Parse(temp.Path, tvf, ParsingOptions.GetDefaultProfile()); Assert.AreEqual(3, tvf.RequestCount); tvf.Close(false); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: Har2Exd <HAR file path> <EXD file path>"); Console.WriteLine("Exit codes: 1 - No args, 2 - Incorrect har path, 3 - Parsing error, 4 - Export error."); Environment.ExitCode = 1; } else { string harFilePath = args[0]; string exdFilePath = args[1]; if (!File.Exists(harFilePath)) { Console.WriteLine("Could not find har file: '{0}'", harFilePath); Environment.ExitCode = 2; } else { TrafficViewerFile tvf = new TrafficViewerFile(); try { Console.WriteLine("Importing from '{0}'...", harFilePath); ITrafficParser harParser = new HarParser(); harParser.Parse(harFilePath, tvf, ParsingOptions.GetDefaultProfile()); } catch (Exception ex) { Console.WriteLine("Parsing exception: '{0}'", ex.Message); Environment.ExitCode = 3; } //now export try { Console.WriteLine("Exporting to '{0}'...", exdFilePath); var exporter = new ManualExploreExporter(); exporter.Export(tvf, new FileStream(exdFilePath, FileMode.Create, FileAccess.ReadWrite)); } catch (Exception ex) { Console.WriteLine("Export exception: '{0}'", ex.Message); Environment.ExitCode = 4; } tvf.Close(false); Console.WriteLine("Done."); } } }
public WithingsLoader(string path) { _path = path; _jsonParser = new JsonParser(path); _harParser = new HarParser(Path.Combine(path, "healthmate.withings.com.har")); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: Traffic2Exd <traffic file path> <EXD file path>"); Console.WriteLine("Supported import formats: .har, .txt, .htd"); Console.WriteLine("If the EXD file already exists the tool will append to it."); Console.WriteLine("Exit codes: 1 - No args, 2 - Incorrect file path, 3 - Parsing error, 4 - Export error, 5 - Unsupported Exception."); Environment.ExitCode = 1; } else { string trafficFilePath = args[0]; string exdFilePath = args[1]; if (!File.Exists(trafficFilePath)) { Console.WriteLine("Could not find har file: '{0}'", trafficFilePath); Environment.ExitCode = 2; } else { TrafficViewerFile tvf = new TrafficViewerFile(); try { if (File.Exists(exdFilePath)) { Console.WriteLine("EXD file {0} already exists. Appending to it.", exdFilePath); ConfigurationParser exdParser = new ConfigurationParser(); exdParser.Parse(exdFilePath, tvf, ParsingOptions.GetDefaultProfile()); } Console.WriteLine("Importing from '{0}'...", trafficFilePath); ITrafficParser parser = null; if (trafficFilePath.ToLower().EndsWith(".har")) { parser = new HarParser(); } else if (trafficFilePath.ToLower().EndsWith(".txt")) { parser = new DefaultTrafficParser(); } else if (trafficFilePath.ToLower().EndsWith(".htd")) { TrafficViewerFile tvf2 = new TrafficViewerFile(); tvf2.Open(trafficFilePath); int id = -1; TVRequestInfo info = null; while ((info = tvf2.GetNext(ref id)) != null) { tvf.AddRequestResponse(tvf2.LoadRequestData(info.Id), tvf2.LoadResponseData(info.Id)); } } else { Console.WriteLine("File extension is unsupported. Supported extensions/formats: .har, .txt, .htd"); Environment.ExitCode = 5; } if (parser != null) { parser.Parse(trafficFilePath, tvf, ParsingOptions.GetRawProfile()); } } catch (Exception ex) { Console.WriteLine("Parsing exception: '{0}'", ex.Message); Environment.ExitCode = 3; } //now export try { Console.WriteLine("Exporting to '{0}'...", exdFilePath); var exporter = new ManualExploreExporter(); exporter.Export(tvf, new FileStream(exdFilePath, FileMode.Create, FileAccess.ReadWrite)); } catch (Exception ex) { Console.WriteLine("Export exception: '{0}'", ex.Message); Environment.ExitCode = 4; } tvf.Close(false); Console.WriteLine("Done."); } } }