void SendPayload(Payload payload) { if (!string.IsNullOrEmpty(TrackingId)) { if (!IsSampledOut()) { if (!ThrottlingEnabled || hitTokenBucket.Consume()) { payload.IsUseSecure = IsUseSecure; analyticsEngine.SendPayload(payload); } } } }
async Task DispatchQueuedHits(IEnumerable <Hit> hits) { using (var httpClient = GetHttpClient()) { var now = DateTimeOffset.UtcNow; foreach (var hit in hits) { if (isEnabled && (!ThrottlingEnabled || hitTokenBucket.Consume())) { // clone the data var hitData = hit.Data.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); hitData.Add("qt", ((long)now.Subtract(hit.TimeStamp).TotalMilliseconds).ToString()); await DispatchHitData(hit, httpClient, hitData); } else { lock (hits) // add back to queue { this.hits.Enqueue(hit); } } } } }