Esempio n. 1
0
        public async Task <string[]> GetOwnersOrEmptyAsync(string id)
        {
            var stopwatch = Stopwatch.StartNew();

            using (var entitiesContext = await _entitiesContextFactory.CreateAsync(readOnly: true))
            {
                _logger.LogInformation("Fetching owners for package registration with ID {PackageId}.", id);
                var owners = await entitiesContext
                             .PackageRegistrations
                             .Where(pr => pr.Id == id)
                             .Select(pr => pr.Owners.Select(u => u.Username).ToList())
                             .FirstOrDefaultAsync();

                if (owners == null)
                {
                    _logger.LogWarning("No package registration with ID {PackageId} was found. Assuming no owners.", id);
                    return(EmptyStringArray);
                }

                if (owners.Count == 0)
                {
                    _logger.LogInformation("The package registration with ID {PackageId} has no owners.", id);
                    return(EmptyStringArray);
                }

                // Sort the usernames in a consistent manner.
                var sortedOwners = owners
                                   .OrderBy(o => o, StringComparer.OrdinalIgnoreCase)
                                   .ToArray();

                stopwatch.Stop();
                _telemetryService.TrackGetOwnersForPackageId(sortedOwners.Length, stopwatch.Elapsed);
                _logger.LogInformation("The package registration with ID {PackageId} has {Count} owners.", id, sortedOwners.Length);
                return(sortedOwners);
            }
        }