private Task <PackageMonitoringStatus> GetPackageAsync(CatalogStorage storage, string fileName, CancellationToken token) { if (!storage.Exists(fileName)) { return(Task.FromResult <PackageMonitoringStatus>(null)); } return(GetPackageAsync(storage, storage.ResolveUri(fileName), token)); }
public static async Task<DateTime?> GetCatalogProperty(Storage storage, string propertyName, CancellationToken cancellationToken) { var json = await storage.LoadString(storage.ResolveUri("index.json"), cancellationToken); if (json != null) { var obj = JObject.Parse(json); JToken token; if (obj.TryGetValue(propertyName, out token)) { return token.ToObject<DateTime>().ToUniversalTime(); } } return null; }
static async Task SaveLargeRegistration(Storage storage, Uri registrationBaseAddress, IDictionary<string, IGraph> items, string existingRoot, Uri contentBaseAddress, int partitionSize, CancellationToken cancellationToken) { if (existingRoot != null) { JToken compacted = JToken.Parse(existingRoot); AddExistingItems(Utils.CreateGraph(compacted), items); } IList<Uri> cleanUpList = new List<Uri>(); await SaveRegistration(storage, registrationBaseAddress, items, cleanUpList, null, contentBaseAddress, partitionSize, cancellationToken); // because there were multiple files some might now be irrelevant foreach (Uri uri in cleanUpList) { if (uri != storage.ResolveUri("index.json")) { Console.WriteLine("DELETE: {0}", uri); await storage.Delete(uri, cancellationToken); } } }
static JObject MakeCatalogIndex(Storage storage, IList<JObject> pages) { JToken context; using (JsonReader jsonReader = new JsonTextReader(new StreamReader(Utils.GetResourceStream("context.Container.json")))) { JObject obj = JObject.Load(jsonReader); context = obj["@context"]; } JObject newIndex = new JObject(); newIndex["@type"] = "CatalogIndex"; Uri indexUri = storage.ResolveUri("index.json"); newIndex["url"] = indexUri.ToString(); DateTime indexTimestamp = DateTime.MaxValue; JArray items = new JArray(); int pageNumber = 0; foreach (JObject page in pages) { Uri pageUri = storage.ResolveUri(string.Format("page{0}.json", pageNumber++)); page["url"] = pageUri.ToString(); page["parent"] = newIndex["url"]; page["@context"] = context; JObject indexItem = new JObject(); indexItem["url"] = page["url"]; indexItem["commitTimestamp"] = page["commitTimestamp"]; indexItem["@type"] = "CatalogPage"; indexItem["count"] = page["items"].Count(); items.Add(indexItem); DateTime itemDataTime = page["commitTimestamp"].ToObject<DateTime>(); if (itemDataTime < indexTimestamp) { indexTimestamp = itemDataTime; } } newIndex["items"] = items; newIndex["commitTimestamp"] = indexTimestamp.ToString("O"); newIndex["@context"] = context; return newIndex; }
private Uri GetPackageUri(CatalogStorage storage, FeedPackageIdentity package) { return(storage.ResolveUri(GetPackageFileName(package))); }
public static async Task AddDependenciesAsync(string path, Storage storage) { Uri root = storage.ResolveUri("index.json"); Console.WriteLine(root); DistinctPackageIdCollector distinctPackageIdCollector = new DistinctPackageIdCollector(root); await distinctPackageIdCollector.Run(CancellationToken.None); DistinctDependencyPackageIdCollector distinctDependencyPackageIdCollector = new DistinctDependencyPackageIdCollector(root); await distinctDependencyPackageIdCollector.Run(CancellationToken.None); HashSet<string> missing = new HashSet<string>(); foreach (string id in distinctDependencyPackageIdCollector.Result) { if (!distinctPackageIdCollector.Result.Contains(id)) { if (!id.StartsWith("../")) { missing.Add(id); } } } if (missing.Count > 0) { Console.WriteLine("missing: {0}", missing.Count); foreach (string name in missing) { Console.WriteLine("\t{0}", name); } BuildCatalogAsync(path, storage, missing).Wait(); AddDependenciesAsync(path, storage).Wait(); } }