public RegistrationCollector( Uri index, StorageFactory legacyStorageFactory, StorageFactory semVer2StorageFactory, Uri contentBaseAddress, ITelemetryService telemetryService, Func <HttpMessageHandler> handlerFunc = null, int maxConcurrentBatches = DefaultMaxConcurrentBatches) : base(index, new Uri[] { Schema.DataTypes.PackageDetails, Schema.DataTypes.PackageDelete }, telemetryService, handlerFunc) { _legacyStorageFactory = legacyStorageFactory ?? throw new ArgumentNullException(nameof(legacyStorageFactory)); _semVer2StorageFactory = semVer2StorageFactory; _shouldIncludeSemVer2 = GetShouldIncludeRegistrationPackage(_semVer2StorageFactory); ContentBaseAddress = contentBaseAddress; if (maxConcurrentBatches < 1) { throw new ArgumentOutOfRangeException( nameof(maxConcurrentBatches), maxConcurrentBatches, string.Format(Strings.ArgumentOutOfRange, 1, int.MaxValue)); } _maxConcurrentBatches = maxConcurrentBatches; }
public static async Task ProcessAsync( RegistrationKey registrationKey, IReadOnlyDictionary <string, IGraph> newItems, ShouldIncludeRegistrationPackage shouldInclude, StorageFactory storageFactory, Uri contentBaseAddress, int partitionSize, int packageCountThreshold, ITelemetryService telemetryService, CancellationToken cancellationToken) { Trace.TraceInformation("RegistrationMaker.Process: registrationKey = {0} newItems: {1}", registrationKey, newItems.Count); IRegistrationPersistence registration = new RegistrationPersistence(storageFactory, registrationKey, partitionSize, packageCountThreshold, contentBaseAddress); IDictionary <RegistrationEntryKey, RegistrationCatalogEntry> existing = await registration.Load(cancellationToken); Trace.TraceInformation("RegistrationMaker.Process: existing = {0}", existing.Count); IDictionary <RegistrationEntryKey, RegistrationCatalogEntry> delta = PromoteRegistrationKey(newItems, shouldInclude); Trace.TraceInformation("RegistrationMaker.Process: delta = {0}", delta.Count); telemetryService.TrackMetric(TelemetryConstants.RegistrationDeltaCount, (uint)delta.Count, new Dictionary <string, string>() { { TelemetryConstants.ContentBaseAddress, contentBaseAddress.AbsoluteUri } }); IDictionary <RegistrationEntryKey, RegistrationCatalogEntry> resulting = Apply(existing, delta); Trace.TraceInformation("RegistrationMaker.Process: resulting = {0}", resulting.Count); await registration.Save(resulting, cancellationToken); }
protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken) { PrintLightning(); // Hard code against Azure storage. arguments[Arguments.StorageType] = Arguments.AzureStorageType; // Configure the package path provider. var useFlatContainerAsPackageContent = arguments.GetOrDefault <bool>(Arguments.ContentIsFlatContainer, false); if (!useFlatContainerAsPackageContent) { RegistrationMakerCatalogItem.PackagePathProvider = new PackagesFolderPackagePathProvider(); } else { var flatContainerName = arguments.GetOrThrow <string>(Arguments.FlatContainerName); RegistrationMakerCatalogItem.PackagePathProvider = new FlatContainerPackagePathProvider(flatContainerName); } _command = arguments.GetOrThrow <string>(Arguments.Command); _verbose = arguments.GetOrDefault(Arguments.Verbose, false); _log = _verbose ? Console.Out : new StringWriter(); _contentBaseAddress = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress); _galleryBaseAddress = arguments.GetOrThrow <string>(Arguments.GalleryBaseAddress); _storageFactories = CommandHelpers.CreateRegistrationStorageFactories(arguments, _verbose); _shouldIncludeSemVer2ForLegacyStorageFactory = RegistrationCollector.GetShouldIncludeRegistrationPackageForLegacyStorageFactory(_storageFactories.SemVer2StorageFactory); _postProcessGraphForLegacyStorageFactory = RegistrationCollector.GetPostProcessGraphForLegacyStorageFactory(_storageFactories.SemVer2StorageFactory); _forceIconsFromFlatContainer = arguments.GetOrDefault <bool>(Arguments.AllIconsInFlatContainer); _driver = arguments.GetOrDefault(Arguments.Driver, GraphDriver).ToLowerInvariant(); // We save the arguments because the "prepare" command generates "strike" commands. Some of the arguments // used by "prepare" should be used when executing "strike". _arguments = arguments; if (_driver != GraphDriver && _driver != JsonDriver) { throw new NotSupportedException($"The lightning driver '{_driver}' is not supported."); } switch (_command.ToLowerInvariant()) { case "charge": case "prepare": InitPrepare(arguments); break; case "strike": InitStrike(arguments); break; default: throw new NotSupportedException($"The lightning command '{_command}' is not supported."); } }
private static IDictionary <RegistrationEntryKey, RegistrationCatalogEntry> PromoteRegistrationKey( IReadOnlyDictionary <string, IGraph> newItems, ShouldIncludeRegistrationPackage shouldInclude) { IDictionary <RegistrationEntryKey, RegistrationCatalogEntry> promoted = new Dictionary <RegistrationEntryKey, RegistrationCatalogEntry>(); foreach (var newItem in newItems) { var promotedEntry = RegistrationCatalogEntry.Promote( newItem.Key, newItem.Value, shouldInclude, isExistingItem: false); promoted[promotedEntry.Key] = promotedEntry.Value; } return(promoted); }
public static KeyValuePair <RegistrationEntryKey, RegistrationCatalogEntry> Promote( string resourceUri, IGraph graph, ShouldIncludeRegistrationPackage shouldInclude, bool isExistingItem) { INode subject = graph.CreateUriNode(new Uri(resourceUri)); var triples = graph.GetTriplesWithSubjectPredicate(subject, graph.CreateUriNode(Schema.Predicates.Version)); string version = triples.First().Object.ToString(); var registrationEntryKey = new RegistrationEntryKey(RegistrationKey.Promote(resourceUri, graph), version); RegistrationCatalogEntry registrationCatalogEntry = null; if (!IsDelete(subject, graph) && shouldInclude(registrationEntryKey, resourceUri, graph)) { registrationCatalogEntry = new RegistrationCatalogEntry(resourceUri, graph, isExistingItem); } return(new KeyValuePair <RegistrationEntryKey, RegistrationCatalogEntry>(registrationEntryKey, registrationCatalogEntry)); }
public RegistrationCollector( Uri index, StorageFactory legacyStorageFactory, StorageFactory semVer2StorageFactory, Uri contentBaseAddress, Uri galleryBaseAddress, bool forcePackagePathProviderForIcons, ITelemetryService telemetryService, ILogger logger, Func <HttpMessageHandler> handlerFunc = null, IHttpRetryStrategy httpRetryStrategy = null, int maxConcurrentBatches = DefaultMaxConcurrentBatches) : base( index, new Uri[] { Schema.DataTypes.PackageDetails, Schema.DataTypes.PackageDelete }, telemetryService, handlerFunc, httpRetryStrategy) { _legacyStorageFactory = legacyStorageFactory ?? throw new ArgumentNullException(nameof(legacyStorageFactory)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _semVer2StorageFactory = semVer2StorageFactory; _shouldIncludeSemVer2ForLegacyStorageFactory = GetShouldIncludeRegistrationPackageForLegacyStorageFactory(_semVer2StorageFactory); _postProcessGraphForLegacyStorageFactory = GetPostProcessGraphForLegacyStorageFactory(_semVer2StorageFactory); ContentBaseAddress = contentBaseAddress; GalleryBaseAddress = galleryBaseAddress; _forcePackagePathProviderForIcons = forcePackagePathProviderForIcons; if (maxConcurrentBatches < 1) { throw new ArgumentOutOfRangeException( nameof(maxConcurrentBatches), maxConcurrentBatches, string.Format(Strings.ArgumentOutOfRange, 1, int.MaxValue)); } _maxConcurrentBatches = maxConcurrentBatches; }