示例#1
0
        public IconCopyResultCacheFacts()
        {
            StorageMock = new Mock <IStorage>();

            StorageMock
            .Setup(s => s.ResolveUri("c2i_cache.json"))
            .Returns(new Uri("https://cache.test/blob"))
            .Verifiable();

            IconCacheStorageMock = new Mock <IStorage>();
            IconCacheStorageMock
            .Setup(ics => ics.ResolveUri(It.IsAny <string>()))
            .Returns(new Uri(DefaultResolvedUrlString));

            var responseStreamContentMock = new Mock <StorageContent>();

            responseStreamContentMock
            .Setup(rsc => rsc.GetContentStream())
            .Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(Data)))
            .Verifiable();

            StorageMock
            .Setup(s => s.LoadAsync(new Uri("https://cache.test/blob"), It.IsAny <CancellationToken>()))
            .ReturnsAsync(responseStreamContentMock.Object);

            Target = new IconCopyResultCache(
                StorageMock.Object,
                TimeSpan.FromMilliseconds(750),
                Mock.Of <ILogger <IconCopyResultCache> >());
        }
示例#2
0
        protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken)
        {
            ServicePointManager.DefaultConnectionLimit = DegreeOfParallelism;

            var verbose              = arguments.GetOrDefault(Arguments.Verbose, false);
            var packageStorageBase   = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress);
            var failCacheTime        = arguments.GetOrDefault(FailCacheTime, TimeSpan.FromHours(1));
            var auxStorageFactory    = CreateAuxStorageFactory(arguments, verbose);
            var targetStorageFactory = CreateTargetStorageFactory(arguments, verbose);
            var packageStorage       = new AzureStorage(
                storageBaseUri: new Uri(packageStorageBase),
                maxExecutionTime: TimeSpan.FromMinutes(15),
                serverTimeout: TimeSpan.FromMinutes(10),
                useServerSideCopy: true,
                compressContent: false,
                verbose: true,
                throttle: null);
            var source               = arguments.GetOrThrow <string>(Arguments.Source);
            var iconProcessor        = new IconProcessor(TelemetryService, LoggerFactory.CreateLogger <IconProcessor>());
            var httpHandlerFactory   = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose);
            var httpMessageHandler   = httpHandlerFactory();
            var httpClient           = new HttpClient(httpMessageHandler);
            var simpleHttpClient     = new SimpleHttpClient(httpClient, LoggerFactory.CreateLogger <SimpleHttpClient>());
            var catalogClient        = new CatalogClient(simpleHttpClient, LoggerFactory.CreateLogger <CatalogClient>());
            var httpResponseProvider = new HttpClientWrapper(httpClient);
            var externalIconProvider = new ExternalIconContentProvider(httpResponseProvider, LoggerFactory.CreateLogger <ExternalIconContentProvider>());
            var iconCopyResultCache  = new IconCopyResultCache(auxStorageFactory.Create(), failCacheTime, LoggerFactory.CreateLogger <IconCopyResultCache>());

            var leafProcessor = new CatalogLeafDataProcessor(
                packageStorage,
                iconProcessor,
                externalIconProvider,
                iconCopyResultCache,
                TelemetryService,
                LoggerFactory.CreateLogger <CatalogLeafDataProcessor>());

            _collector = new IconsCollector(
                new Uri(source),
                TelemetryService,
                targetStorageFactory,
                catalogClient,
                leafProcessor,
                iconCopyResultCache,
                auxStorageFactory,
                CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose),
                LoggerFactory.CreateLogger <IconsCollector>());
            var cursorStorage = auxStorageFactory.Create();

            _front = new DurableCursor(cursorStorage.ResolveUri("c2icursor.json"), cursorStorage, DateTime.MinValue.ToUniversalTime());
        }