示例#1
0
        public PackageStatistics FromCdnLogEntry(CdnLogEntry cdnLogEntry)
        {
            var packageDefinition = PackageDefinition.FromRequestUrl(cdnLogEntry.RequestUrl);

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

            if (_packageTranslator != null)
            {
                packageDefinition = _packageTranslator.TranslatePackageDefinition(packageDefinition);
            }

            var statistic = new PackageStatistics();

            statistic.EdgeServerTimeDelivered = cdnLogEntry.EdgeServerTimeDelivered;
            statistic.PackageId      = packageDefinition.PackageId;
            statistic.PackageVersion = NormalizeSemanticVersion(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);
            statistic.EdgeServerIpAddress = cdnLogEntry.EdgeServerIpAddress;

            // ignore blacklisted user agents
            if (!IsBlackListed(statistic.UserAgent))
            {
                return(statistic);
            }
            return(null);
        }
示例#2
0
 private static string GetUserAgentValue(CdnLogEntry cdnLogEntry)
 {
     if (cdnLogEntry.UserAgent.StartsWith("\"") && cdnLogEntry.UserAgent.EndsWith("\""))
     {
         return(cdnLogEntry.UserAgent.Substring(1, cdnLogEntry.UserAgent.Length - 2));
     }
     else
     {
         return(cdnLogEntry.UserAgent);
     }
 }
示例#3
0
        public static DnxStatistics FromCdnLogEntry(CdnLogEntry logEntry)
        {
            var statistics = GetDnxStatisticsFromRequestUrl(logEntry.RequestUrl, logEntry.EdgeServerTimeDelivered);

            if (statistics != null)
            {
                statistics.EdgeServerIpAddress = logEntry.EdgeServerIpAddress;
                statistics.UserAgent           = GetUserAgentValue(logEntry);
            }
            return(statistics);
        }
        public PackageStatistics FromCdnLogEntry(CdnLogEntry cdnLogEntry)
        {
            var packageDefinitions = PackageDefinition.FromRequestUrl(cdnLogEntry.RequestUrl);

            if (packageDefinitions == null || !packageDefinitions.Any())
            {
                return(null);
            }

            if (packageDefinitions.Count > 1)
            {
                _logger.LogWarning(LogEvents.MultiplePackageIDVersionParseOptions,
                                   "Found multiple parse options for URL {RequestUrl}: {PackageDefinitions}",
                                   cdnLogEntry.RequestUrl,
                                   string.Join(", ", packageDefinitions));
            }

            var packageDefinition = packageDefinitions.First();

            if (_packageTranslator != null)
            {
                bool translateOccured = _packageTranslator.TryTranslatePackageDefinition(packageDefinition);

                if (translateOccured)
                {
                    _logger.LogInformation(LogEvents.TranslatedPackageIdVersion,
                                           "Translated package. Url: {RequestUrl}, New definition: {PackageDefinition}",
                                           cdnLogEntry.RequestUrl,
                                           packageDefinition);
                }
            }

            var statistic = new PackageStatistics();

            statistic.EdgeServerTimeDelivered = cdnLogEntry.EdgeServerTimeDelivered;
            statistic.PackageId      = packageDefinition.PackageId;
            statistic.PackageVersion = NormalizeSemanticVersion(packageDefinition.PackageVersion);

            var customFieldDictionary = CdnLogCustomFieldParser.Parse(cdnLogEntry.CustomField);

            statistic.Operation           = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetOperation);
            statistic.DependentPackage    = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetDependentPackage);
            statistic.UserAgent           = GetUserAgentValue(cdnLogEntry);
            statistic.EdgeServerIpAddress = cdnLogEntry.EdgeServerIpAddress;

            // Ignore blacklisted user agents
            if (!IsBlackListed(statistic.UserAgent))
            {
                return(statistic);
            }
            return(null);
        }