/// <summary> /// Executes the parsing operation /// </summary> /// <param name="pathOfFileToImport"></param> /// <param name="currentFile"></param> /// <param name="options"></param> public void Parse(string pathOfFileToImport, ITrafficDataAccessor currentFile, ParsingOptions options) { _options = options; var exclusions = options.GetExclusions(); _status = TrafficParserStatus.Running; Har har = HarConvert.DeserializeFromFile(pathOfFileToImport); foreach (Entry entry in har.Log.Entries) { try { if (!IsExcluded(entry.Request.Url, exclusions)) { AddRequest(currentFile, entry); } } catch (Exception ex) { SdkSettings.Instance.Logger.Log(TraceLevel.Error, "URI Parser - Failed to add request: {0}", ex.Message); } } _status = TrafficParserStatus.Stopped; }
async Task ExecuteInternal(IPreprocessingStepCallback callback, Action <PreprocessingStepParams> onNext) { await callback.BecomeLongRunning(); callback.TempFilesCleanupList.Add(sourceFile.Uri); string tmpFileName = callback.TempFilesManager.GenerateNewName(); callback.SetStepDescription(string.Format("{0}: converting to text", sourceFile.FullPath)); var harTask = Task.Run(() => { try { return(HarConvert.DeserializeFromFile(sourceFile.Uri)); } catch (Newtonsoft.Json.JsonReaderException e) { throw new Exception(string.Format("HTTP archive is broken"), e); } }); if (await Task.WhenAny(callback.Cancellation.ToTask(), harTask) != harTask) { return; } await(new Writer()).Write( () => new FileStream(tmpFileName, FileMode.Create), s => s.Dispose(), ToText(harTask.Result, callback.Cancellation) ); onNext(new PreprocessingStepParams(tmpFileName, string.Format("{0}\\text", sourceFile.FullPath), Utils.Concat(sourceFile.PreprocessingSteps, stepName), sourceFile.FullPath)); }
protected override void ParseHistory() { RecordedHistory = new RecordedHistory(); var harData = HarConvert.DeserializeFromFile(Path); RecordedHistory.History = harData.Log.Entries.Select(e => new RecordedHistory.Item(e)).ToList(); IsParsed = true; }
async Task ExecuteInternal(IPreprocessingStepCallback callback, Action <PreprocessingStepParams> onNext) { await callback.BecomeLongRunning(); callback.TempFilesCleanupList.Add(sourceFile.Location); string tmpFileName = callback.TempFilesManager.GenerateNewName(); callback.SetStepDescription(string.Format("{0}: converting to text", sourceFile.FullPath)); var harTask = Task.Run(() => { Assembly dependencyResolveHandler(object s, ResolveEventArgs e) { if (new AssemblyName(e.Name).Name == "Newtonsoft.Json") // HarConvert needs Newtonsoft.Json v6, map it to whatever modern version shipped with the plugin { return(typeof(Newtonsoft.Json.JsonReaderException).Assembly); } return(null); } AppDomain.CurrentDomain.AssemblyResolve += dependencyResolveHandler; try { return(HarConvert.DeserializeFromFile(sourceFile.Location)); } catch (Newtonsoft.Json.JsonReaderException) { string fixedJsonFileName = callback.TempFilesManager.GenerateNewName(); try { TryFixJson(sourceFile.Location, fixedJsonFileName); return(HarConvert.DeserializeFromFile(fixedJsonFileName)); } catch (Newtonsoft.Json.JsonReaderException e) { throw new Exception(string.Format("HTTP archive is broken"), e); } finally { if (File.Exists(fixedJsonFileName)) { File.Delete(fixedJsonFileName); } } } finally { AppDomain.CurrentDomain.AssemblyResolve -= dependencyResolveHandler; } }); if (await Task.WhenAny(ToTask(callback.Cancellation), harTask) != harTask) { return; } await(new Writer()).Write( () => new FileStream(tmpFileName, FileMode.Create), s => s.Dispose(), ToText(harTask.Result, callback.Cancellation) ); onNext(new PreprocessingStepParams(tmpFileName, string.Format("{0}\\text", sourceFile.FullPath), sourceFile.PreprocessingHistory.Add(new PreprocessingHistoryItem(stepName)), sourceFile.FullPath)); }
public void InitializeFixture() { m_actual = HarConvert.DeserializeFromFile(@"Hars\Sample.har"); }