Exemple #1
0
        protected override async Task CopyToSource(ILogger log, CancellationToken token)
        {
            var absoluteUri = UriUtility.GetPath(RootPath, key);

            if (!File.Exists(LocalCacheFile.FullName))
            {
                if (await FileExistsAsync(client, bucketName, key, token).ConfigureAwait(false))
                {
                    log.LogVerbose($"Removing {absoluteUri}");
                    await RemoveFileAsync(client, bucketName, key, token).ConfigureAwait(false);
                }
                else
                {
                    log.LogVerbose($"Skipping {absoluteUri}");
                }

                return;
            }

            log.LogVerbose($"Pushing {absoluteUri}");

            using (var cache = LocalCacheFile.OpenRead())
            {
                Stream writeStream = cache;
                string contentType = null, contentEncoding = null;
                if (key.EndsWith(".nupkg", StringComparison.Ordinal))
                {
                    contentType = "application/zip";
                }
                else if (key.EndsWith(".xml", StringComparison.Ordinal) ||
                         key.EndsWith(".nuspec", StringComparison.Ordinal))
                {
                    contentType = "application/xml";
                }
                else if (key.EndsWith(".json", StringComparison.Ordinal) ||
                         await JsonUtility.IsJsonAsync(LocalCacheFile.FullName))
                {
                    contentType     = "application/json";
                    contentEncoding = "gzip";

                    // Compress content before uploading
                    log.LogVerbose($"Compressing {absoluteUri}");
                    writeStream = await JsonUtility.GZipAndMinifyAsync(cache);
                }
                else if (key.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                         key.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase))
                {
                    contentType = "application/octet-stream";
                }
                else
                {
                    log.LogWarning($"Unknown file type: {absoluteUri}");
                }

                await UploadFileAsync(client, bucketName, key, contentType, contentEncoding, writeStream, token)
                .ConfigureAwait(false);

                writeStream.Dispose();
            }
        }
Exemple #2
0
        protected override async Task CopyToSource(ILogger log, CancellationToken token)
        {
            if (File.Exists(LocalCacheFile.FullName))
            {
                log.LogInformation($"Pushing {_blob.Uri.AbsoluteUri}");

                using (var cache = LocalCacheFile.OpenRead())
                {
                    Stream writeStream = cache;

                    if (_blob.Uri.AbsoluteUri.EndsWith(".nupkg", StringComparison.Ordinal))
                    {
                        _blob.Properties.ContentType = "application/zip";
                    }
                    else if (_blob.Uri.AbsoluteUri.EndsWith(".xml", StringComparison.Ordinal) ||
                             _blob.Uri.AbsoluteUri.EndsWith(".nuspec", StringComparison.Ordinal))
                    {
                        _blob.Properties.ContentType = "application/xml";
                    }
                    else if (_blob.Uri.AbsoluteUri.EndsWith(".json", StringComparison.Ordinal) ||
                             JsonUtility.IsJson(LocalCacheFile.FullName))
                    {
                        _blob.Properties.ContentType     = "application/json";
                        _blob.Properties.ContentEncoding = "gzip";

                        // Compress content before uploading
                        log.LogInformation($"Compressing {_blob.Uri.AbsoluteUri}");
                        writeStream = GZipAndMinify(cache);
                    }
                    else
                    {
                        log.LogWarning($"Unknown file type: {_blob.Uri.AbsoluteUri}");
                    }

                    await _blob.UploadFromStreamAsync(writeStream);

                    writeStream.Dispose();
                }

                _blob.Properties.CacheControl = "no-store";

                // TODO: re-enable this once it works again.
                _blob.Properties.ContentMD5 = null;

                await _blob.SetPropertiesAsync();
            }
            else if (await _blob.ExistsAsync())
            {
                log.LogInformation($"Removing {_blob.Uri.AbsoluteUri}");
                await _blob.DeleteAsync();
            }
            else
            {
                log.LogInformation($"Skipping {_blob.Uri.AbsoluteUri}");
            }
        }
Exemple #3
0
        public async Task <Stream> GetStream(ILogger log, CancellationToken token)
        {
            await EnsureFile(log, token);

            if (LocalCacheFile.Exists)
            {
                return(LocalCacheFile.OpenRead());
            }
            else
            {
                return(null);
            }
        }