예제 #1
0
        public async Task <double> GetTotalBodySize(long id)
        {
            try
            {
                var harFile = await this._harFileRepository.GetByIdAsync(id);

                if (harFile == null)
                {
                    throw new Exception($"HarFile {id} not found.");
                }

                var harModel = HarConvert.Deserialize(harFile.HarContentString);

                var totalBodySize = harModel.Log.Entries.Sum(e => e.Response.BodySize);

                return(totalBodySize);
            }
            catch (Exception ex)
            {
                throw new Exception("Unhandled Service Exception", ex);
            }
        }
예제 #2
0
        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));
        }
예제 #3
0
 public void InitializeFixture()
 {
     m_actual = HarConvert.Deserialize(Resources.Sample);
 }
        public Har GetHarContent()
        {
            var harString = GetHarContentString();

            return(HarConvert.Deserialize(harString));
        }
예제 #5
0
 public void Deserialize_Null_Exception()
 {
     Assert.Catch <ArgumentNullException>(() => HarConvert.Deserialize(null));
 }
예제 #6
0
 public void InitializeFixture()
 {
     m_actual = HarConvert.DeserializeFromFile(@"Hars\Sample.har");
 }