Ejemplo n.º 1
0
        public async Task CloseAsync()
        {
            await Task.Delay(1).ConfigureAwait(false);

            lock (EventDataSent)
                EventDataSent.Clear();
        }
        public string PeekLastSent(string partitionKey)
        {
            lock (EventDataSent)
            {
                if (EventDataSent.TryGetValue(partitionKey, out var eventData))
                {
                    if (eventData.Count > 0)
                    {
                        return(Encoding.UTF8.GetString(eventData[eventData.Count - 1].Body));
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public Task SendAsync(IList <EventData> eventDataList, string partitionKey)
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                throw new InvalidOperationException("EventHubService not connected");
            }

            return(Task.Delay(_random.Next(5, 10)).ContinueWith(t =>
            {
                lock (EventDataSent)
                {
                    if (EventDataSent.TryGetValue(partitionKey, out var existingBatch))
                    {
                        existingBatch.AddRange(eventDataList);
                    }
                    else
                    {
                        EventDataSent[partitionKey] = new List <EventData>(eventDataList);
                    }
                }
            }));
        }
 public void Close()
 {
     lock (EventDataSent)
         EventDataSent.Clear();
 }