public IEnumerableAsync <Timeline.Event[]> GetEvents(IEnumerableAsync <StateInspector.Event[]> input)
 {
     return(input.Select <StateInspector.Event, Timeline.Event>((evt, buffer) =>
     {
         resultEvents = buffer;
         evt.Visit(this);
     }, YieldFinalEvents));
 }
Beispiel #2
0
 public static IEnumerableAsync <MessagePrefixesPair[]> MatchPrefixes(this IEnumerableAsync <Message[]> input, IPrefixMatcher prefixMatcher)
 {
     return(input.Select(
                msgs => msgs.Select(
                    m => new MessagePrefixesPair(m, prefixMatcher.Match(m.Text))
                    ).ToArray()
                ));
 }
Beispiel #3
0
 public static IEnumerableAsync <MessagePrefixesPair <M>[]> MatchTextPrefixes <M>(this IEnumerableAsync <M[]> input, IPrefixMatcher prefixMatcher)
     where M : ITriggerText
 {
     return(input.Select(
                msgs => msgs.Select(
                    m => new MessagePrefixesPair <M>(m, prefixMatcher.Match(m.Text))
                    ).ToArray()
                ));
 }
 public IEnumerableAsync <Timeline.Event[]> GetEvents(IEnumerableAsync <Message[]> input)
 {
     return(input.Select <Message, Timeline.Event>((evt, buffer) =>
     {
         lastMessage = evt;
     }, (buffer) =>
     {
         var trigger = lastMessage != null ? triggetSelector(lastMessage) : null;
         if (trigger != null)
         {
             buffer.Enqueue(new EndOfTimelineEvent(trigger, null));
         }
     }));
 }
Beispiel #5
0
 public static IEnumerableAsync <Event[]> TrackTemplates(this ICodepathTracker codepathTracker, IEnumerableAsync <Event[]> events)
 {
     return(events.Select(batch =>
     {
         if (codepathTracker != null)
         {
             foreach (var e in batch)
             {
                 codepathTracker.RegisterUsage(e.TemplateId);
             }
         }
         return batch;
     }));
 }
Beispiel #6
0
 internal static IEnumerableAsync <Adapter> CreateOrUpdateBatch(IEnumerableAsync <Adapter> keyAndConnectorKvps, Guid integrationId, string resourceType)
 {
     return(AzureStorageRepository.Connection(
                azureStorageRepository =>
     {
         var adapters = keyAndConnectorKvps
                        .Select(adapter => Convert(adapter));
         return azureStorageRepository
         .CreateOrReplaceBatch(adapters,
                               adapter => adapter.GetId(),
                               (successAdapter) => successAdapter,
                               (failedAdapter) => failedAdapter)
         .Select(adapter => Convert(adapter));
     }));
 }
Beispiel #7
0
 public static IEnumerableAsync <TSelect> SelectOptionalAsync <TItem, TSelect, TResult>(this IEnumerableAsync <TItem> enumerable,
                                                                                        Func <TItem,
                                                                                              Func <TSelect, ISelectionResult <TSelect> >,
                                                                                              Func <ISelectionResult <TSelect> >,
                                                                                              Task <ISelectionResult <TSelect> > > selectionAsync)
 {
     return(enumerable
            .Select(
                (item) => selectionAsync(item,
                                         (selected) => new Selection <TSelect>(selected),
                                         () => new SelectionSkipped <TSelect>()))
            .Await()
            .Where(select => select.HasValue)
            .Select(select => select.Value));
 }
Beispiel #8
0
        public static TResult SelectOptional <TItem, TSelect, TCarry, TResult>(this IEnumerableAsync <TItem> enumerable,
                                                                               TCarry carry,
                                                                               Func <TItem, TCarry, Func <TSelect, TCarry, ISelectionResult <TSelect> >, Func <TCarry, ISelectionResult <TSelect> >, ISelectionResult <TSelect> > selection,
                                                                               Func <IEnumerableAsync <TSelect>, TCarry, TResult> aggregation)
        {
            var aggregatedItems = enumerable
                                  .Select(
                item => selection(item, carry,
                                  (selected, carryUpdated) =>
            {
                carry = carryUpdated;
                return(new Selection <TSelect>(selected));
            },
                                  (carryUpdated) =>
            {
                carry = carryUpdated;
                return(new SelectionSkipped <TSelect>());
            }))
                                  .Where(item => item.HasValue)
                                  .Select(item => item.Value);

            return(aggregation(aggregatedItems, carry));
        }
Beispiel #9
0
 public IEnumerableAsync <Event[]> GetEvents(IEnumerableAsync <Message[]> input)
 {
     return(input.Select <Message, Event>(GetEvents));
 }
 IEnumerableAsync <Event[]> IMediaStateInspector.GetEvents(IEnumerableAsync <MessagePrefixesPair[]> input)
 {
     return(input.Select <MessagePrefixesPair, Event>(GetEvents, GetFinalEvents, e => e.SetTags(tags)));
 }
 IEnumerableAsync <Event[]> ICITimelineEvents.GetEvents(IEnumerableAsync <CDL.Message[]> input)
 {
     return(input.Select <CDL.Message, Event>(GetEvents, GetFinalEvents));
 }
 IEnumerableAsync <Event[]> IMessagingEvents.GetEvents(IEnumerableAsync <Message[]> input)
 {
     return(input.Select <Message, Event>(GetEvents));
 }
 public static Task <IRefs <T> > AsRefsAsync <T>(this IEnumerableAsync <IRef <T> > refs)
     where T : IReferenceable
 {
     return(refs.Select(r => r.id).AsRefsAsync <T>());
 }
Beispiel #14
0
 IEnumerableAsync <Event[]> ITimelineEvents.GetEvents(IEnumerableAsync <MessagePrefixesPair <Message>[]> input)
 {
     return(input.Select <MessagePrefixesPair <Message>, Event>(GetEvents, GetFinalEvents, e => e.SetTags(tags)));
 }
 IEnumerableAsync <Event[]> ITimelineEvents.GetEvents(IEnumerableAsync <MessagePrefixesPair[]> input)
 {
     return(input.Select <MessagePrefixesPair, Event>(GetEvents, GetFinalEvents));
 }
Beispiel #16
0
 public IEnumerableAsync <Timeline.Event[]> GetEvents(IEnumerableAsync <Messaging.Event[]> input)
 {
     return(input.Select <Messaging.Event, Timeline.Event> (GetEvents));
 }
 public IEnumeratorAsync <KeyValuePair <TKey, TValue> > GetEnumerator()
 => enumerable
 .Select(
     item => this.valueSelector(item).PairWithKey(this.keySelector(item)))
 .GetEnumerator();
 IEnumerableAsync <Event[]> IWebRtcStateInspector.GetEvents(IEnumerableAsync <MessagePrefixesPair[]> input)
 {
     return(input.Select <MessagePrefixesPair, Event>(GetEvents, GetFinalEvents));
 }
Beispiel #19
0
		IEnumerableAsync<Event[]> IWebRtcStateInspector.GetEvents(IEnumerableAsync<MessagePrefixesPair<Message>[]> input)
		{
			return input.Select<MessagePrefixesPair<Message>, Event>(GetEvents, GetFinalEvents, e => e.SetTags(tags));
		}
Beispiel #20
0
        /// <summary>
        /// Makes sure events have correct timestamp and go in correct order.
        /// Chromedriver log has a problem that timestamps at beginning of lines like [1525678451.879]
        /// seem to be rounded up to next 100ms boundary which results to inaccurate views.
        /// Most important messages like Network.requestWillBeSent have "timestamp" as a json field.
        /// That "timestamp" is nr os seconds from unknown origin. Luckily some messages also have
        /// "wallTime" in json payload that can help interpret "timestamp".
        /// Another problem is that "timestamp" of Network.requestWillBeSent might not match
        /// timing.requestTime in Network.responseReceived. The latter seems to be more accurate.
        /// However if a request is served from cache its timing.requestTime is totally wrong and
        /// should be ignored in favor of  Network.requestWillBeSent's "timestamp".
        /// </summary>
        static IEnumerableAsync <Message[]> FixTimestamps(IEnumerableAsync <Message[]> messages)
        {
            DateTime?timestampBase            = null;
            var      pendingMessages          = new List <MessageEntry>();
            var      queue                    = new VCSKicksCollection.PriorityQueue <MessageEntry>(new Comparer());
            var      queuedRequestStarts      = new Dictionary <string, MessageEntry>();
            double?  lastDequeuedTimestamp    = null;
            Action <Queue <Message> > dequeue = (outputQueue) =>
            {
                var entry = queue.Dequeue();
                if (!entry.IsInvalidated)
                {
                    if (lastDequeuedTimestamp == null || entry.Timestamp != null)
                    {
                        lastDequeuedTimestamp = entry.Timestamp;
                    }
                    outputQueue.Enqueue(entry.Msg);
                    if (entry.Type == MessageEntry.EntryType.StartRequest)
                    {
                        queuedRequestStarts.Remove(entry.RequestId);
                    }
                }
            };
            Action <MessageEntry> enqueue = null;

            enqueue = (r) =>
            {
                var rebased = r.Rebase(timestampBase.Value);
                queue.Enqueue(rebased);
                if (r.Type == MessageEntry.EntryType.StartRequest)
                {
                    queuedRequestStarts[r.RequestId] = rebased;
                }
                else if (r.Type == MessageEntry.EntryType.ResponseWithTiming)
                {
                    MessageEntry queuedRequest;
                    if (queuedRequestStarts.TryGetValue(r.RequestId, out queuedRequest) && !queuedRequest.IsInvalidated && !queuedRequest.IsServedFromCache)
                    {
                        if (lastDequeuedTimestamp == null || r.ResponseTiming_RequestTime > lastDequeuedTimestamp.Value)
                        {
                            enqueue(queuedRequest.InvalidateAndMakeFixedStartRequest(r.ResponseTiming_RequestTime));
                        }
                    }
                }
                else if (r.Type == MessageEntry.EntryType.ServedFromCache)
                {
                    MessageEntry queuedRequest;
                    if (queuedRequestStarts.TryGetValue(r.RequestId, out queuedRequest))
                    {
                        queuedRequest.IsServedFromCache = true;
                    }
                }
            };
            Action flushPendingMessages = () =>
            {
                foreach (var pendingMessage in pendingMessages)
                {
                    enqueue(pendingMessage);
                }
                pendingMessages.Clear();
            };
            int queueSize = 4096;

            return(messages.Select <Message, Message>((m, outputQueue) => {
                var newEntry = new MessageEntry(m);

                if (timestampBase == null && newEntry.Timestamp != null && newEntry.WallTime != null)
                {
                    timestampBase = TimeUtils.UnixTimestampMillisToDateTime(
                        newEntry.WallTime.Value * 1000d).ToUnspecifiedTime().AddSeconds(
                        -newEntry.Timestamp.Value);
                    flushPendingMessages();
                }

                if (timestampBase == null)
                {
                    pendingMessages.Add(newEntry);
                }
                else
                {
                    enqueue(newEntry);
                }

                if (queue.Count >= queueSize * 2)
                {
                    while (queue.Count > queueSize)
                    {
                        dequeue(outputQueue);
                    }
                }
            },
                                                      (outputQueue) =>
            {
                while (queue.Count > 0)
                {
                    dequeue(outputQueue);
                }
            }));
        }
 public static IEnumerableAsync <TValue> SelectValues <TKey, TValue>(this IEnumerableAsync <KeyValuePair <TKey, TValue> > enumerable)
 {
     return(enumerable.Select(kvp => kvp.Value));
 }