예제 #1
0
        private async Task <UserPackageDeleteEvent> GetUserPackageDeleteEvent(
            Package package,
            ReportPackageReason?reportPackageReason,
            PackageDeleteDecision?packageDeleteDecision)
        {
            var sinceCreated = DateTime.UtcNow - package.Created;

            var report = await _statisticsService.GetPackageDownloadsByVersion(package.PackageRegistration.Id);

            var idReportDownloads = report?
                                    .Facts
                                    .Sum(x => x.Amount) ?? 0;

            var versionReportDownloads = report?
                                         .Facts
                                         .Where(x => HasVersion(x, package.NormalizedVersion))
                                         .Sum(x => x.Amount) ?? 0;

            var details = new UserPackageDeleteEvent(
                sinceCreated,
                package.Key,
                package.PackageRegistration.Id,
                package.NormalizedVersion,
                package.PackageRegistration.DownloadCount,
                idReportDownloads,
                package.DownloadCount,
                versionReportDownloads,
                reportPackageReason,
                packageDeleteDecision);

            return(details);
        }
예제 #2
0
        private bool IsAccepted(UserPackageDeleteEvent details, UserPackageDeleteOutcome outcome)
        {
            // Only report telemetry if a reason has been specified.
            if (details.ReportPackageReason.HasValue)
            {
                _telemetryService.TrackUserPackageDeleteChecked(details, outcome);
            }

            return(outcome == UserPackageDeleteOutcome.Accepted);
        }
예제 #3
0
        public void TrackUserPackageDeleteChecked(UserPackageDeleteEvent details, UserPackageDeleteOutcome outcome)
        {
            if (details == null)
            {
                throw new ArgumentNullException(nameof(details));
            }

            var hours = details.SinceCreated.TotalHours;

            TrackMetric(Events.UserPackageDeleteCheckedAfterHours, hours, properties => {
                properties.Add(Outcome, outcome.ToString());
                properties.Add(PackageKey, details.PackageKey.ToString());
                properties.Add(PackageId, details.PackageId);
                properties.Add(PackageVersion, details.PackageVersion);
                properties.Add(IdDatabaseDownloads, details.IdDatabaseDownloads.ToString());
                properties.Add(IdReportDownloads, details.IdReportDownloads.ToString());
                properties.Add(VersionDatabaseDownloads, details.VersionDatabaseDownloads.ToString());
                properties.Add(VersionReportDownloads, details.VersionReportDownloads.ToString());
                properties.Add(ReportPackageReason, details.ReportPackageReason?.ToString());
                properties.Add(PackageDeleteDecision, details.PackageDeleteDecision?.ToString());
            });
        }