private Dictionary <string, int> GetScores(ServiceWorkerDetectionResult result)
 {
     return(new Dictionary <string, int>
     {
         { "hasSW", result.HasSW ? 20 : 0 },
         { "scope", result.Scope != null ? 5 : 0 },
         { "hasPeriodicBackgroundSync", result.HasPeriodicBackgroundSync ? 2 : 0 },
         { "hasPushRegistration", result.HasPushRegistration ? 1 : 0 }
     });
 }
예제 #2
0
        public void LogUrlResult(Uri url, ServiceWorkerDetectionResult result, TimeSpan elapsed)
        {
            if (this.settings.Value.Url == null)
            {
                this.logger.LogWarning("Skipping URL recording due to no url log service API");
                return;
            }

            var args = System.Text.Json.JsonSerializer.Serialize(new
            {
                Url = url,
                ServiceWorkerDetected              = result.HasSW,
                ServiceWorkerDetectionError        = result.ServiceWorkerDetectionTimedOut,
                ServiceWorkerDetectionTimedOut     = result.ServiceWorkerDetectionTimedOut,
                ServiceWorkerScoreExcludingOffline = result.ServiceWorkerScore.Select(a => a.Value).Sum(),
                ServiceWorkerDetectionTimeInMs     = elapsed.TotalMilliseconds
            });

            this.http.PostAsync(this.settings.Value.Url, new StringContent(args))
            .ContinueWith(_ => logger.LogInformation("Successfully sent {url} to URL logging service. Success = {success}, Error = {error}, Elapsed = {elapsed}", url, result.HasSW, result.NoServiceWorkerFoundDetails, elapsed), TaskContinuationOptions.OnlyOnRanToCompletion)
            .ContinueWith(task => logger.LogError(task.Exception ?? new Exception("Unable to send URL to logging service"), "Unable to send {url} to logging service due to an error", url), TaskContinuationOptions.OnlyOnFaulted);
        }