public Save ( |
||
resourceUri | ||
content | NuGet.Services.Metadata.Catalog.Persistence.StorageContent | |
cancellationToken | CancellationToken | |
return | System.Threading.Tasks.Task |
private async Task<Uri> SaveNuspec(Storage storage, string id, string version, string nuspec, CancellationToken cancellationToken) { var relativeAddress = string.Format("{1}/{0}.nuspec", id, version); var nuspecUri = new Uri(storage.BaseAddress, relativeAddress); await storage.Save(nuspecUri, new StringStorageContent(nuspec, "text/xml", "max-age=120"), cancellationToken); return nuspecUri; }
async Task UpdateMetadata(Storage storage, string version, CancellationToken cancellationToken) { Uri resourceUri = new Uri(storage.BaseAddress, "index.json"); HashSet<NuGetVersion> versions = GetVersions(await storage.LoadString(resourceUri, cancellationToken)); versions.Add(NuGetVersion.Parse(version)); List<NuGetVersion> result = new List<NuGetVersion>(versions); result.Sort(); await storage.Save(resourceUri, CreateContent(result.Select((v) => v.ToString())), cancellationToken); }
private async Task StoreCursor(NuGet.Services.Metadata.Catalog.Persistence.Storage storage, Uri cursorUri, CollectorCursor value) { if (!Equals(value, CollectorCursor.None)) { Log.StoringCursor(value.Value); var cursorContent = new JObject { { "http://schema.nuget.org/collectors/resolver#cursor", new JObject { { "@value", value.Value }, { "@type", "http://www.w3.org/2001/XMLSchema#dateTime" } } }, { "http://schema.nuget.org/collectors/resolver#source", CatalogIndexUrl } }.ToString(); await storage.Save(cursorUri, new StringStorageContent( cursorContent, contentType : "application/json", cacheControl : "no-store")); Log.StoredCursor(); } }
async Task UpdateMetadata(Storage storage, Action<HashSet<NuGetVersion>> updateAction, CancellationToken cancellationToken) { string relativeAddress = "index.json"; var resourceUri = new Uri(storage.BaseAddress, relativeAddress); HashSet<NuGetVersion> versions = GetVersions(await storage.LoadString(resourceUri, cancellationToken)); updateAction(versions); List<NuGetVersion> result = new List<NuGetVersion>(versions); if (result.Any()) { // Store versions (sorted) result.Sort(); await storage.Save(resourceUri, CreateContent(result.Select((v) => v.ToString())), cancellationToken); } else { // Remove versions file if no versions are present if (storage.Exists(relativeAddress)) { await storage.Delete(resourceUri, cancellationToken); } } }
static async Task SaveSmallRegistration(Storage storage, Uri registrationBaseAddress, IDictionary<string, IGraph> items, Uri contentBaseAddress, int partitionSize, CancellationToken cancellationToken) { SingleGraphPersistence graphPersistence = new SingleGraphPersistence(storage); await graphPersistence.Initialize(cancellationToken); await SaveRegistration(storage, registrationBaseAddress, items, null, graphPersistence, contentBaseAddress, partitionSize, cancellationToken); // now the commit has happened the graphPersistence.Graph should contain all the data JObject frame = (new CatalogContext()).GetJsonLdContext("context.Registration.json", graphPersistence.TypeUri); StorageContent content = new StringStorageContent(Utils.CreateJson(graphPersistence.Graph, frame), "application/json", "no-store"); await storage.Save(graphPersistence.ResourceUri, content,cancellationToken); }
static async Task Save(Storage storage, JObject catalogIndex, IEnumerable<JObject> catalogPages, CancellationToken cancellationToken) { foreach (JObject catalogPage in catalogPages) { Uri pageUri = new Uri(catalogPage["url"].ToString()); await storage.Save(pageUri, new StringStorageContent(catalogPage.ToString(), "application/json"), cancellationToken); } Uri indexUri = new Uri(catalogIndex["url"].ToString()); await storage.Save(indexUri, new StringStorageContent(catalogIndex.ToString(), "application/json"), cancellationToken); }
async Task CopyNupkg(Storage storage, string id, string version, CancellationToken cancellationToken) { using (HttpClient client = new HttpClient()) { Uri requestUri = new Uri(ContentBaseAddress, string.Format("{0}.{1}.nupkg", id, version)); using (Stream stream = await client.GetStreamAsync(requestUri)) { string relativeAddress = string.Format("{1}/{0}.{1}.nupkg", id, version); Uri nupkgUri = new Uri(storage.BaseAddress, string.Format("{1}/{0}.{1}.nupkg", id, version)); await storage.Save(nupkgUri, new StreamStorageContent(stream, "application/octet-stream", "max-age=120"), cancellationToken); } } }
private async Task<Uri> SaveNupkg(Stream nupkgStream, Storage storage, string id, string version, CancellationToken cancellationToken) { Uri nupkgUri = new Uri(storage.BaseAddress, string.Format("{1}/{0}.{1}.nupkg", id, version)); await storage.Save(nupkgUri, new StreamStorageContent(nupkgStream, "application/octet-stream", "max-age=120"), cancellationToken); return nupkgUri; }