Пример #1
0
        public static ClientDimension FromPackageStatistic(PackageStatistics packageStatistics)
        {
            if (string.IsNullOrEmpty(packageStatistics.UserAgent))
            {
                return Unknown;
            }

            ClientDimension result;
            var parsed = _parser.ParseUserAgent(packageStatistics.UserAgent);
            if (parsed != null)
            {
                if (string.Equals(_other, parsed.Family, StringComparison.OrdinalIgnoreCase))
                {
                    return Unknown;
                }
                result = new ClientDimension();
                result.ClientName = parsed.Family;
                result.Major = string.IsNullOrWhiteSpace(parsed.Major) ? _zeroString : parsed.Major;
                result.Minor = string.IsNullOrWhiteSpace(parsed.Minor) ? _zeroString : parsed.Minor;
                result.Patch = string.IsNullOrWhiteSpace(parsed.Patch) ? _zeroString : parsed.Patch;
            }
            else result = Unknown;

            return result;
        }
Пример #2
0
        public static PackageStatistics FromCdnLogEntry(CdnLogEntry cdnLogEntry)
        {
            var packageDefinition = PackageDefinition.FromRequestUrl(cdnLogEntry.RequestUrl);

            if (packageDefinition == null)
            {
                return null;
            }

            var statistic = new PackageStatistics();
            statistic.EdgeServerTimeDelivered = cdnLogEntry.EdgeServerTimeDelivered;
            statistic.PackageId = packageDefinition.PackageId;
            statistic.PackageVersion = packageDefinition.PackageVersion;

            var customFieldDictionary = CdnLogCustomFieldParser.Parse(cdnLogEntry.CustomField);
            statistic.Operation = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetOperation);
            statistic.DependentPackage = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetDependentPackage);
            statistic.ProjectGuids = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetProjectGuids);
            statistic.UserAgent = GetUserAgentValue(cdnLogEntry);

            // ignore blacklisted user agents
            if (!IsBlackListed(statistic.UserAgent))
            {
                return statistic;
            }
            return null;
        }
        public static IReadOnlyCollection <string> GetDistinctProjectGuids(this PackageStatistics current)
        {
            if (string.IsNullOrEmpty(current.ProjectGuids) || current.ProjectGuids.Length == 1)
            {
                return(new List <string>());
            }

            return(current.ProjectGuids.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Distinct(StringComparer.OrdinalIgnoreCase).ToList());
        }
Пример #4
0
        public static PlatformDimension FromPackageStatistic(PackageStatistics packageStatistics)
        {
            if (string.IsNullOrEmpty(packageStatistics.UserAgent))
            {
                return Unknown;
            }

            var dimension = Parse(packageStatistics.UserAgent);
            return dimension;
        }