private bool TryReadNext(string method, TargetUri targetUri, out CapturedNetworkQuery query) { if (method is null) { throw new ArgumentNullException(nameof(method)); } if (targetUri is null) { throw new ArgumentNullException(nameof(targetUri)); } var urlPair = new CaptureNetwork.StringPair { String1 = targetUri?.QueryUri?.ToString(), String2 = targetUri?.ProxyUri?.ToString(), }; if (!_captured.TryGetValue(urlPair, out var byMethod) || !byMethod.TryGetValue(method, out var queries) || queries.Count == 0) { query = default(CapturedNetworkQuery); return(false); } query = queries.Dequeue(); return(true); }
public static bool TryDeserialize(object serializedObject, out CapturedNetworkData operation) { if (serializedObject is JObject jNetworkData) { operation = jNetworkData.ToObject <CapturedNetworkData>(); #if Deserialize_Manually if (jNetworkData["Operations"] is JArray jOperations) { operation.Operations = new List <CapturedNetworkOperation>(); foreach (var jNetworkOperation in jOperations) { var networkOperation = new CapturedNetworkOperation { Methods = new List <CapturedNetworkMethod>(), ProxyUrl = jNetworkOperation["ProxyUrl"]?.Value <string>(), QueryUrl = jNetworkOperation["QueryUrl"]?.Value <string>(), }; if (jNetworkOperation["Methods"] is JArray jMethods) { foreach (var jMethod in jMethods) { var networkMethod = new CapturedNetworkMethod { Method = jMethod["Method"]?.Value <string>(), Queries = new List <CapturedNetworkQuery>(), }; if (jMethod["Queries"] is JArray jQueries) { foreach (var jQuery in jQueries) { var networkQuery = new CapturedNetworkQuery { Ordinal = jQuery["Ordinal"].Value <int>(), Request = new CapturedNetworkRequest { Content = jQuery["Content"]?.Value <string>(), Headers = jQuery["Headers"]?.ToObject <List <string> >(), OptionFlags = jQuery["OptionFlags"].Value <int>(), } }; } } } } operation.Operations.Add(networkOperation); } } #endif return(true); } operation = default(CapturedNetworkData); return(false); }