Пример #1
0
        /// <summary>
        /// Create PackageDetails for a delete
        /// </summary>
        public static async Task <JObject> CreateDeleteDetailsAsync(PackageIdentity package, string reason, Uri catalogBaseURI, Guid commitId)
        {
            var now    = DateTimeOffset.UtcNow;
            var pageId = Guid.NewGuid().ToString().ToLowerInvariant();

            var rootUri = UriUtility.GetPath(catalogBaseURI, $"data/{pageId}.json");

            var json = JsonUtility.Create(rootUri, new List <string>()
            {
                "PackageDelete", "catalog:Permalink"
            });

            json.Add("commitId", commitId.ToString().ToLowerInvariant());
            json.Add("commitTimeStamp", now.GetDateString());
            json.Add("sleet:operation", "remove");

            var context = await JsonUtility.GetContextAsync("Catalog");

            json.Add("@context", context);

            json.Add("id", package.Id);
            json.Add("version", package.Version.ToFullVersionString());

            json.Add("created", DateTimeOffset.UtcNow.GetDateString());
            json.Add("sleet:removeReason", reason);

            json.Add("sleet:toolVersion", AssemblyVersionHelper.GetVersion().ToFullVersionString());

            return(JsonLDTokenComparer.Format(json));
        }
Пример #2
0
        /// <summary>
        /// Create a PackageDetails page that contains all the package information.
        /// </summary>
        public static Task <JObject> CreatePackageDetailsAsync(PackageInput packageInput, Uri catalogBaseURI, Uri nupkgUri, Guid commitId, bool writeFileList)
        {
            var pageId  = Guid.NewGuid().ToString().ToLowerInvariant();
            var rootUri = UriUtility.GetPath(catalogBaseURI, $"data/{pageId}.json");

            return(CreatePackageDetailsWithExactUriAsync(packageInput, rootUri, nupkgUri, commitId, writeFileList));
        }
Пример #3
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();
            }
        }
Пример #4
0
        public Catalog(SleetContext context, Uri catalogBaseURI)
        {
            _context = context;

            var fileSystemBase = (FileSystemBase)context.Source;

            CatalogBaseURI = fileSystemBase.FeedSubPath == null ? catalogBaseURI : UriUtility.GetPath(context.Source.BaseURI, fileSystemBase.FeedSubPath, "catalog/");
        }
Пример #5
0
        public Uri GetPath(string relativePath)
        {
            if (relativePath == null)
            {
                throw new ArgumentNullException(nameof(relativePath));
            }

            return(UriUtility.GetPath(BaseURI, relativePath));
        }
Пример #6
0
        private static void AddServiceIndexEntry(Uri baseUri, string relativeFilePath, string type, string comment, JObject json)
        {
            var id = UriUtility.GetPath(baseUri, relativeFilePath);

            RemoveServiceIndexEntry(id, json);

            var array = (JArray)json["resources"];

            array.Add(GetServiceIndexEntry(baseUri, relativeFilePath, type, comment));
        }
Пример #7
0
        public static Uri GetContainerAndSubFeedPath(CloudStorageAccount azureAccount, string container, string feedSubPath)
        {
            var uri = GetContainerPath(azureAccount, container);

            if (!string.IsNullOrEmpty(feedSubPath))
            {
                // Remove any slashes around the feed sub path and append it.
                uri = UriUtility.EnsureTrailingSlash(UriUtility.GetPath(uri, feedSubPath.Trim('/')));
            }

            return(uri);
        }
Пример #8
0
        private static JObject GetServiceIndexEntry(Uri baseUri, string relativeFilePath, string type, string comment)
        {
            var id = UriUtility.GetPath(baseUri, relativeFilePath);

            var json = new JObject
            {
                ["@id"]     = id.AbsoluteUri,
                ["@type"]   = type,
                ["comment"] = comment
            };

            return(json);
        }
Пример #9
0
        /// <summary>
        /// Uri of the latest index page.
        /// </summary>
        public Uri GetCurrentPage(JObject indexJson)
        {
            var entries = JsonUtility.GetItems(indexJson);
            var nextId  = entries.Count;

            var latest = entries.OrderByDescending(GetCommitTime).FirstOrDefault();

            if (latest != null)
            {
                if (latest["count"].ToObject <int>() < _context.SourceSettings.CatalogPageSize)
                {
                    return(JsonUtility.GetIdUri(latest));
                }
            }

            // next page
            return(UriUtility.GetPath(CatalogBaseURI, $"page.{nextId}.json"));
        }
Пример #10
0
        protected override async Task CopyFromSource(ILogger log, CancellationToken token)
        {
            Uri absoluteUri = UriUtility.GetPath(RootPath, key);

            if (!await FileExistsAsync(client, bucketName, key, token).ConfigureAwait(false))
            {
                return;
            }

            log.LogInformation($"GET {absoluteUri}");

            if (File.Exists(LocalCacheFile.FullName))
            {
                LocalCacheFile.Delete();
            }

            string contentEncoding;

            using (FileStream cache = File.OpenWrite(LocalCacheFile.FullName))
            {
                contentEncoding = await DownloadFileAsync(client, bucketName, key, cache, token).ConfigureAwait(false);
            }

            if (contentEncoding?.Equals("gzip", StringComparison.OrdinalIgnoreCase) == true)
            {
                log.LogInformation($"Decompressing {absoluteUri}");

                string gzipFile = LocalCacheFile.FullName + ".gz";
                File.Move(LocalCacheFile.FullName, gzipFile);

                using (Stream destination = File.Create(LocalCacheFile.FullName))
                    using (Stream source = File.OpenRead(gzipFile))
                        using (Stream zipStream = new GZipStream(source, CompressionMode.Decompress))
                        {
                            await zipStream.CopyToAsync(destination, DefaultCopyBufferSize, token).ConfigureAwait(false);
                        }
            }
        }
Пример #11
0
 public Catalog(SleetContext context)
     : this(context, UriUtility.GetPath(context.Source.BaseURI, "catalog/"))
 {
 }
Пример #12
0
 public Uri GetPath(string relativePath)
 {
     return(UriUtility.GetPath(BaseURI, relativePath));
 }