internal CatalogBlob(Uri uri, StorageContent content)
 {
     Uri     = uri;
     Content = content;
 }
Example #2
0
 protected override Task OnSaveAsync(Uri resourceUri, StorageContent content, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
Example #3
0
 private static bool SameDataAndContentType(byte[] expectedData, string expectedContentType, StorageContent content)
 {
     return(SameData(expectedData, content) && content.ContentType == expectedContentType);
 }
 async Task Save(Uri resourceUri, IGraph graph)
 {
     SetTimestamp(resourceUri, graph);
     StorageContent content = CreateContent(graph, Schema.DataTypes.Record);
     await _storage.Save(resourceUri, content);
 }
Example #5
0
 protected override Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken)
 {
     return(_factory.OnSave(resourceUri, content, cancellationToken));
 }
Example #6
0
 public StorageComparerTestData()
 {
     EmptyContent     = new StorageContent(Array.Empty <File>());
     TwoFilesContent  = CreateTwoFilesContent();
     FourFilesContent = CreateFourFilesContent();
 }
        protected void AssertContentDoesNotContain(StorageContent content, string value)
        {
            var contentValue = content.GetContentString();

            Assert.DoesNotContain(contentValue, value, StringComparison.OrdinalIgnoreCase);
        }
Example #8
0
        protected internal override async Task Execute()
        {
            await Extend(TimeSpan.FromMinutes(10));

            // Set defaults
            TargetStorageAccount = TargetStorageAccount ?? Config.Storage.Primary;

            // Check required payload
            ArgCheck.Require(TargetBaseAddress, "TargetBaseAddress");
            ArgCheck.Require(CatalogIndexUrl, "CatalogIndexUrl");
            ArgCheck.Require(CdnBaseAddress, "CdnBaseAddress");
            ArgCheck.Require(GalleryBaseAddress, "GalleryBaseAddress");

            // Clean input data
            if (!TargetBaseAddress.EndsWith("/"))
            {
                TargetBaseAddress += "/";
            }
            var resolverBaseUri = new Uri(TargetBaseAddress);

            CdnBaseAddress     = CdnBaseAddress.TrimEnd('/');
            GalleryBaseAddress = GalleryBaseAddress.TrimEnd('/');

            // Load Storage
            NuGet.Services.Metadata.Catalog.Persistence.Storage storage;
            string storageDesc;

            if (String.IsNullOrEmpty(TargetLocalDirectory))
            {
                ArgCheck.Require(TargetStorageAccount, "ResolverStorage");
                ArgCheck.Require(TargetPath, "ResolverPath");
                var dir = StorageHelpers.GetBlobDirectory(TargetStorageAccount, TargetPath);
                storage     = new AzureStorage(dir, resolverBaseUri);
                storageDesc = dir.Uri.ToString();
            }
            else
            {
                storage     = new FileStorage(TargetBaseAddress, TargetLocalDirectory);
                storageDesc = TargetLocalDirectory;
            }


            Uri cursorUri = new Uri(resolverBaseUri, "meta/cursor.json");

            Log.LoadingCursor(cursorUri.ToString());
            StorageContent content = await storage.Load(cursorUri);

            CollectorCursor lastCursor;

            if (content == null)
            {
                lastCursor = CollectorCursor.None;
            }
            else
            {
                JToken cursorDoc = JsonLD.Util.JSONUtils.FromInputStream(content.GetContentStream());
                lastCursor = (CollectorCursor)(cursorDoc["http://schema.nuget.org/collectors/resolver#cursor"].Value <DateTime>("@value"));
            }
            Log.LoadedCursor(lastCursor.Value);

            ResolverCollector collector = new ResolverCollector(storage, 200)
            {
                ContentBaseAddress = CdnBaseAddress,
                GalleryBaseAddress = GalleryBaseAddress
            };

            collector.ProcessedCommit += cursor =>
            {
                ExtendIfNeeded(TimeSpan.FromMinutes(10)).Wait();

                if (!Equals(cursor, lastCursor))
                {
                    StoreCursor(storage, cursorUri, cursor).Wait();
                    lastCursor = cursor;
                }
            };

            Log.EmittingResolverBlobs(
                CatalogIndexUrl.ToString(),
                storageDesc,
                CdnBaseAddress,
                GalleryBaseAddress);
            lastCursor = (DateTime)await collector.Run(
                new Uri(CatalogIndexUrl),
                lastCursor);

            Log.EmittedResolverBlobs();

            await this.Enqueue(this.Invocation.Job, this.Invocation.Payload, TimeSpan.FromSeconds(3), this.Invocation.JobInstanceName);
        }
        private Task SaveToStorage(MemoryStorageFactory storageFactory, PackageState state, FeedPackageIdentity package, StorageContent content)
        {
            var stateName       = Enum.GetName(typeof(PackageState), state);
            var storage         = storageFactory.Create(stateName.ToLowerInvariant());
            var packageFileName = GetPackageFileName(package.Id, package.Version);

            return(storage.SaveAsync(storage.ResolveUri(packageFileName), content, CancellationToken.None));
        }