コード例 #1
0
        private async Task BreakLeasIfExpiredAsync()
        {
            await m_blob.FetchAttributesAsync();

            if (m_blob.Metadata.ContainsKey(Constants.MetadataProperties.SESSION_EXPIRES_ON))
            {
                var expiresOn = DateTimeOffset.Parse(m_blob.Metadata[Constants.MetadataProperties.SESSION_EXPIRES_ON]);
                if (expiresOn <= DateTimeOffset.UtcNow)
                {
                    await m_blob.BreakLeaseAsync();

                    s_logger.Warning("Acquired session's ({StreamName}, {ConsumerId}) lease has been broken.", m_streamName, m_acquiredLease);
                }
            }
        }
コード例 #2
0
        public async Task ProcessPackageAsync(CatalogIndexEntry packageEntry, ICloudBlockBlob blob)
        {
            await blob.FetchAttributesAsync(CancellationToken.None);

            // Skip the package if it has a Content MD5 hash
            if (blob.ContentMD5 != null)
            {
                _telemetryService.TrackPackageAlreadyHasHash(packageEntry.Id, packageEntry.Version);
                return;
            }

            // Download the blob and calculate its hash. We use HttpClient to download blobs as Azure Blob Sotrage SDK
            // occassionally hangs. See: https://github.com/Azure/azure-storage-net/issues/470
            string hash;

            using (var hashAlgorithm = MD5.Create())
                using (var packageStream = await _httpClient.GetStreamAsync(blob.Uri))
                {
                    var hashBytes = hashAlgorithm.ComputeHash(packageStream);

                    hash = Convert.ToBase64String(hashBytes);
                }

            blob.ContentMD5 = hash;

            var condition = AccessCondition.GenerateIfMatchCondition(blob.ETag);
            await blob.SetPropertiesAsync(
                condition,
                options : null,
                operationContext : null);

            _telemetryService.TrackPackageHashFixed(packageEntry.Id, packageEntry.Version);

            _logger.LogWarning(
                "Updated package {PackageId} {PackageVersion}, set hash to '{Hash}' using ETag {ETag}",
                packageEntry.Id,
                packageEntry.Version,
                hash,
                blob.ETag);
        }
コード例 #3
0
        public async Task ProcessPackageAsync(CatalogIndexEntry packageEntry, ICloudBlockBlob blob)
        {
            await blob.FetchAttributesAsync(CancellationToken.None);

            if (blob.ContentMD5 == null)
            {
                _telemetryService.TrackPackageMissingHash(packageEntry.Id, packageEntry.Version);

                _logger.LogError(
                    "Package {PackageId} {PackageVersion} has a null Content MD5 hash!",
                    packageEntry.Id,
                    packageEntry.Version);
                return;
            }

            // Download the blob and calculate its hash. We use HttpClient to download blobs as Azure Blob Sotrage SDK
            // occassionally hangs. See: https://github.com/Azure/azure-storage-net/issues/470
            string hash;

            using (var hashAlgorithm = MD5.Create())
                using (var packageStream = await _httpClient.GetStreamAsync(blob.Uri))
                {
                    var hashBytes = hashAlgorithm.ComputeHash(packageStream);

                    hash = Convert.ToBase64String(hashBytes);
                }

            if (blob.ContentMD5 != hash)
            {
                _telemetryService.TrackPackageHasIncorrectHash(packageEntry.Id, packageEntry.Version);

                _logger.LogError(
                    "Package {PackageId} {PackageVersion} has an incorrect Content MD5 hash! Expected: '{ExpectedHash}', actual: '{ActualHash}'",
                    packageEntry.Id,
                    packageEntry.Version,
                    hash,
                    blob.ContentMD5);
            }
        }
コード例 #4
0
        public async Task <CreateThumbnailSetResult> CreateThumbnailSetAsync(
            CreateThumbnailsMessage message,
            ICloudBlockBlob input,
            ICloudStorageAccount cloudStorageAccount,
            ILogger logger,
            CancellationToken cancellationToken)
        {
            CreateThumbnailSetResult result = null;
            var sw = new Stopwatch();

            sw.Start();
            logger.Info("StartFileProcessor: " + sw.ElapsedMilliseconds);

            if (message.Items == null || message.Items.Count == 0)
            {
                return(null);
            }

            var cache = this.GetItemsCache(message, cloudStorageAccount);

            logger.Info("GetBlockBlobs: " + sw.ElapsedMilliseconds);
            await this.PopulateExists(message, cancellationToken, cache);

            logger.Info("CheckExists: " + sw.ElapsedMilliseconds);

            if (message.Overwrite == false && cache.Values.All(v => v.Exists))
            {
                return(null);
            }

            await input.FetchAttributesAsync(cancellationToken);

            var cacheControl = input.Properties.CacheControl;

            this.PopulateCacheControl(cacheControl, cache);

            using (var image = await this.OpenImageAsync(input, cancellationToken, logger, sw))
            {
                logger.Info("OpenImage: " + sw.ElapsedMilliseconds);
                var outputMimeType = image.FormatInfo.MimeType;
                if (!SupportedOutputMimeTypes.Contains(outputMimeType))
                {
                    outputMimeType = DefaultOutputMimeType;
                    image.Format   = DefaultOutputFormat;
                    logger.Info("ConvertToJpeg: " + sw.ElapsedMilliseconds);
                }

                if (image.Format == MagickFormat.Jpg || image.Format == MagickFormat.Jpeg)
                {
                    var colorProfile = image.GetColorProfile();
                    if (colorProfile == null)
                    {
                        image.AddProfile(ColorProfile.SRGB);
                        logger.Info("AddColorProfile: " + sw.ElapsedMilliseconds);
                    }

                    if (image.Quality > 85)
                    {
                        image.Quality = 85;
                    }

                    await this.OrientAndSetMetadataAsync(image, input, cancellationToken, logger, sw);
                }
                else
                {
                    await SetAndSaveMetadata(input, image);
                }

                var jobData = new JobData(outputMimeType);

                logger.Info("Processing: " + sw.ElapsedMilliseconds);
                result = new CreateThumbnailSetResult(image.Width, image.Height);
                await this.ProcessThumbnailItems(message.Items, cache, image, jobData, logger, cancellationToken);

                logger.Info("ProcessingComplete: " + sw.ElapsedMilliseconds);
            }

            logger.Info("Disposed: " + sw.ElapsedMilliseconds);
            return(result);
        }