public async Task <ISameNodeDetectionToken> GetToken(IEnumerableAsync <MessagePrefixesPair[]> input) { var processIdTask = processIdDetector.DetectProcessId(input); var candidateTypeInfo = webRtcStateInspector.CandidateTypeInfo; var candidateEventsTask = webRtcStateInspector.GetEvents(input).SelectMany( evts => evts.Where(e => e.ObjectType == candidateTypeInfo)).ToList(); var logsTask = GetLogs(input); await Task.WhenAll(processIdTask, candidateEventsTask, logsTask); if (processIdTask.Result.Length == 0) { return(new NullNodeDetectionToken()); } var iceCandidates = candidateEventsTask.Result.ToDictionarySafe(e => e.ObjectId, e => e, (e, e2) => e); if (iceCandidates.Count == 0 && logsTask.Result.Count == 0) { return(new NullNodeDetectionToken()); } return(new NodeDetectionToken( processIdTask.Result, iceCandidates.Select(c => new NodeDetectionToken.ICECandidateInfo(c.Key, ((ITriggerTime)c.Value.Trigger).Timestamp)), logsTask.Result )); }
public async Task <ISameNodeDetectionToken> GetToken(IEnumerableAsync <MessagePrefixesPair <Message>[]> input) { var candidateTypeInfo = webRtcStateInspector.CandidateTypeInfo; var peerConnectionTypeInfo = webRtcStateInspector.PeerConnectionTypeInfo; var eventsTask = webRtcStateInspector.GetEvents(input).SelectMany( evts => evts.OfType <SI.ObjectCreation>().Where(e => e.ObjectType == candidateTypeInfo || e.ObjectType == peerConnectionTypeInfo) ).ToList(); await eventsTask; var iceCandidates = eventsTask.Result .Where(e => e.ObjectType == candidateTypeInfo) .GroupBy(e => e.ObjectId) .Select(g => g.First()) .Select(e => new { idMatch = Regex.Match(e.ObjectId, @"^Cand-(.+)$", RegexOptions.IgnoreCase), e }) .Where(x => x.idMatch.Success) .Select(x => new NodeDetectionToken.ICECandidateInfo(x.idMatch.Groups[1].Value, ((ITriggerTime)x.e.Trigger).Timestamp)) .ToList(); if (iceCandidates.Count == 0) { return(null); } var processIds = new HashSet <uint>( eventsTask.Result .Where(e => e.ObjectType == peerConnectionTypeInfo) .GroupBy(e => e.ObjectId) .Select(g => g.First()) .Select(e => Regex.Match(e.ObjectId, @"^(\d+)-")) .Where(m => m.Success) .Select(m => uint.Parse(m.Groups[1].Value)) ); if (processIds.Count == 0) { return(null); } return(new NodeDetectionToken( processIds, iceCandidates )); }