Пример #1
0
        /// <summary>
        /// Runs the background task to send the anonymous ID
        /// to telemetry service
        /// </summary>
        public override async Task PerformExecuteAsync(object state)
        {
            // Try & get a value stored in umbracoSettings.config on the backoffice XML element ID attribute
            var backofficeIdentifierRaw = _globalSettings.Value.Id;

            // Parse as a GUID & verify its a GUID and not some random string
            // In case of users may have messed or decided to empty the file contents or put in something random
            if (Guid.TryParse(backofficeIdentifierRaw, out var telemetrySiteIdentifier) == false)
            {
                // Some users may have decided to mess with the XML attribute and put in something else
                _logger.LogWarning("No telemetry marker found");

                return;
            }

            try
            {
                if (s_httpClient.BaseAddress is null)
                {
                    // Send data to LIVE telemetry
                    s_httpClient.BaseAddress = new Uri("https://telemetry.umbraco.com/");

                    // Set a low timeout - no need to use a larger default timeout for this POST request
                    s_httpClient.Timeout = new TimeSpan(0, 0, 1);

#if DEBUG
                    // Send data to DEBUG telemetry service
                    s_httpClient.BaseAddress = new Uri("https://telemetry.rainbowsrock.net/");
#endif
                }


                s_httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");

                using (var request = new HttpRequestMessage(HttpMethod.Post, "installs/"))
                {
                    var postData = new TelemetryReportData {
                        Id = telemetrySiteIdentifier, Version = _umbracoVersion.SemanticVersion.ToSemanticStringWithoutBuild()
                    };
                    request.Content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/json"); //CONTENT-TYPE header

                    // Make a HTTP Post to telemetry service
                    // https://telemetry.umbraco.com/installs/
                    // Fire & Forget, do not need to know if its a 200, 500 etc
                    using (HttpResponseMessage response = await s_httpClient.SendAsync(request))
                    {
                    }
                }
            }
            catch
            {
                // Silently swallow
                // The user does not need the logs being polluted if our service has fallen over or is down etc
                // Hence only logging this at a more verbose level (which users should not be using in production)
                _logger.LogDebug("There was a problem sending a request to the Umbraco telemetry service");
            }
        }
Пример #2
0
        /// <summary>
        /// Runs the background task to send the anonymous ID
        /// to telemetry service
        /// </summary>
        /// <returns>A value indicating whether to repeat the task.</returns>
        public override async Task <bool> PerformRunAsync(CancellationToken token)
        {
            // Try & get a value stored in umbracoSettings.config on the backoffice XML element ID attribute
            var backofficeIdentifierRaw = _settings.BackOffice.Id;

            // Parse as a GUID & verify its a GUID and not some random string
            // In case of users may have messed or decided to empty the file contents or put in something random
            if (Guid.TryParse(backofficeIdentifierRaw, out var telemetrySiteIdentifier) == false)
            {
                // Some users may have decided to mess with the XML attribute and put in something else
                // Stop repeating this task (no need to keep checking)
                // The only time it will recheck when the site is recycled
                return(false);
            }

            try
            {
                // Send data to LIVE telemetry
                _httpClient.BaseAddress = new Uri("https://telemetry.umbraco.com/");

#if DEBUG
                // Send data to DEBUG telemetry service
                _httpClient.BaseAddress = new Uri("https://telemetry.rainbowsrock.net/");
#endif

                _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");

                using (var request = new HttpRequestMessage(HttpMethod.Post, "installs/"))
                {
                    var postData = new TelemetryReportData {
                        Id = telemetrySiteIdentifier, Version = UmbracoVersion.SemanticVersion.ToSemanticString()
                    };
                    request.Content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/json"); //CONTENT-TYPE header

                    // Set a low timeout - no need to use a larger default timeout for this POST request
                    _httpClient.Timeout = new TimeSpan(0, 0, 1);

                    // Make a HTTP Post to telemetry service
                    // https://telemetry.umbraco.com/installs/
                    // Fire & Forget, do not need to know if its a 200, 500 etc
                    var result = await _httpClient.SendAsync(request, token);
                }
            }
            catch
            {
                // Silently swallow
                // The user does not need the logs being polluted if our service has fallen over or is down etc
                // Hence only logging this at a more verbose level (which users should not be using in production)
                _logger.Debug <ReportSiteTask>("There was a problem sending a request to the Umbraco telemetry service");
            }

            // Keep recurring this task & pinging the telemetry service
            return(true);
        }
Пример #3
0
        /// <inheritdoc/>
        public bool TryGetTelemetryReportData(out TelemetryReportData telemetryReportData)
        {
            if (_siteIdentifierService.TryGetOrCreateSiteIdentifier(out Guid telemetryId) is false)
            {
                telemetryReportData = null;
                return(false);
            }

            telemetryReportData = new TelemetryReportData
            {
                Id       = telemetryId,
                Version  = _umbracoVersion.SemanticVersion.ToSemanticStringWithoutBuild(),
                Packages = GetPackageTelemetry(),
            };
            return(true);
        }
Пример #4
0
        /// <inheritdoc/>
        public bool TryGetTelemetryReportData(out TelemetryReportData telemetryReportData)
        {
            if (TryGetTelemetryId(out Guid telemetryId) is false)
            {
                telemetryReportData = null;
                return(false);
            }

            telemetryReportData = new TelemetryReportData
            {
                Id       = telemetryId,
                Version  = _umbracoVersion.SemanticVersion.ToSemanticStringWithoutBuild(),
                Packages = GetPackageTelemetry()
            };
            return(true);
        }
        /// <inheritdoc/>
        public bool TryGetTelemetryReportData(out TelemetryReportData?telemetryReportData)
        {
            if (_siteIdentifierService.TryGetOrCreateSiteIdentifier(out Guid telemetryId) is false)
            {
                telemetryReportData = null;
                return(false);
            }

            telemetryReportData = new TelemetryReportData
            {
                Id       = telemetryId,
                Version  = GetVersion(),
                Packages = GetPackageTelemetry(),
                Detailed = _usageInformationService.GetDetailed(),
            };
            return(true);
        }
Пример #6
0
        private ListResponse <TelemetryReportData> ToTelemetryData(ListResponse <LogRecord> logRecords, ListRequest listRequest, string recordType)
        {
            var lr = new ListResponse <TelemetryReportData>
            {
                NextPartitionKey = logRecords.NextPartitionKey,
                NextRowKey       = logRecords.NextRowKey,
                PageIndex        = listRequest.PageIndex,
                HasMoreRecords   = !String.IsNullOrEmpty(logRecords.NextPartitionKey),
                PageSize         = logRecords.Model.Count()
            };


            var trdList = new List <TelemetryReportData>();

            foreach (var logRecord in logRecords.Model)
            {
                trdList.Add(TelemetryReportData.FromLogRecord(logRecord, recordType));
            }

            lr.Model = trdList;

            return(lr);
        }