/// <summary> /// Construct a HttpParallelDownloader. /// </summary> /// <param name="task">Download task, must with HttpRangedTarget.</param> /// <param name="folderProvider">Folder provider must not be null.</param> /// <param name="cacheProvider">Cache provider must not be null.</param> /// <param name="bufferProvider">Buffer provider must not be null.</param> /// <param name="checkPoint">Set the downloader to start at given checkPoint.</param> /// <param name="threadNum">Number of threads used.</param> /// <param name="threadSegmentSize">Downloading task is divided as segments /// before assigned to each thread. Segment size defines the approximate /// size of each segment.</param> public HttpParallelDownloader( DownloadTask task, IFolderProvider folderProvider, ICacheStorageProvider cacheProvider, IBufferProvider bufferProvider, byte[] checkPoint = null, int threadNum = 8, long threadSegmentSize = 8 * 1024 * 1024 ) : base(task) { Ensure.That(task.Target is HttpRangableTarget, null, opts => opts.WithMessage( $"type of {nameof(task.Target)} must be {nameof(HttpRangableTarget)}") ).IsTrue(); Ensure.That(folderProvider, nameof(folderProvider)).IsNotNull(); Ensure.That(cacheProvider, nameof(cacheProvider)).IsNotNull(); Ensure.That(bufferProvider, nameof(bufferProvider)).IsNotNull(); Ensure.That(threadNum, nameof(threadNum)).IsGte(1); Ensure.That(threadSegmentSize, nameof(threadSegmentSize)).IsGt(1024 * 1024); this.folderProvider = folderProvider; this.cacheProvider = cacheProvider; this.bufferProvider = bufferProvider; this.threadNum = threadNum; this.threadSegmentSize = threadSegmentSize; Progress = new CompositeProgress((task.Target as HttpRangableTarget).DataLength); Speed = SharedSpeedCalculatorFactory.NewSpeedCalculator(); Progress.ProgressChanged += (sender, arg) => Speed.CurrentValue = Progress.DownloadedSize; if (checkPoint != null) { ApplyCheckPoint(checkPoint); } }
public DefaultCacheService( ShellSettings shellSettings, ICacheStorageProvider cacheStorageProvider) { _cacheStorageProvider = cacheStorageProvider; _prefix = shellSettings.Name; }
public ApiKeyService(ShellSettings shellSettings, IOrchardServices orchardServices, ICacheStorageProvider cacheManager, IApiKeySettingService apiKeySettingService) { _apiKeySettingService = apiKeySettingService; _shellSettings = shellSettings; _orchardServices = orchardServices; Logger = NullLogger.Instance; _cacheStorage = cacheManager; _defaultApplication = new Lazy <ExternalApplication>(() => { var name = ""; while (name.Length < 22) { name += _shellSettings.Name; } var apikey = Convert.ToBase64String( EncryptStringToBytes_Aes( name, _shellSettings.EncryptionKey.ToByteArray(), Encoding.UTF8.GetBytes(string.Format("{0}{0}", DateTime.UtcNow.ToString("ddMMyyyy").Substring(0, 8)))), Base64FormattingOptions.None); return(new ExternalApplication { Name = "DefaultApplication", ApiKey = apikey, EnableTimeStampVerification = true, Validity = 5 }); }); }
/// <summary> /// Create a caching service using a specified <seealso cref="ICacheStorageProvider"/> /// </summary> /// <param name="cache"></param> public CachingService(ICacheStorageProvider cache) : this(() => cache) { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } }
public static UpdaterCache InitializeCache(ICacheStorageProvider cacheStorageProvider) { IInstalledPackageMetadataCollection installedPackages; using (XmlReader xmlReader = cacheStorageProvider.OpenInstalledPackageRepository()) { installedPackages = InstalledPackageMetadataCollection.LoadFromXml(xmlReader); } return(new UpdaterCache(cacheStorageProvider, installedPackages)); }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> /// <param name="storageProvider">缓存储存提供程序</param> public StandardCachePolicy( HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache, ICacheStorageProvider storageProvider ) : base(context, token, provider) { if ( context == null ) throw new ArgumentNullException( "context" ); if ( provider == null ) throw new ArgumentNullException( "provider" ); Duration = duration; EnableClientCache = enableClientCache; CacheStorageProvider = storageProvider; }
/// <summary> /// Construct a TorrentDownloader. /// </summary> /// <param name="task">Download task, must with HttpRangedTarget.</param> /// <param name="engine">Client engine of MonoTorrent which provides torrent and magnet downloading.</param> /// <param name="folderProvider">Folder provider must not be null.</param> /// <param name="cacheProvider">Cache provider must not be null.</param> /// <param name="checkPoint">Set the downloader to start at given checkPoint.</param> /// <param name="maximumConnections"> /// The maximum number of concurrent open connections for this torrent. /// Defaults to 60.</param> /// <param name="maximumDownloadSpeed"> /// The maximum download speed, in bytes per second, for this torrent. /// A value of 0 means unlimited. Defaults to 0.</param> /// <param name="maximumUploadSpeed"> /// The maximum upload speed, in bytes per second, for this torrent. /// A value of 0 means unlimited. defaults to 0.</param> /// <param name="uploadSlots"> /// The number of peers which can be uploaded to concurrently for this torrent. /// A value of 0 means unlimited. defaults to 8.</param> /// <param name="customAnnounceUrls">Custom announce URLs.</param> public TorrentDownloader( DownloadTask task, ClientEngine engine, IFolderProvider folderProvider, ICacheStorageProvider cacheProvider, byte[] checkPoint = null, int maximumConnections = 60, int maximumDownloadSpeed = 0, int maximumUploadSpeed = 0, int uploadSlots = 8, IEnumerable <string> announceUrls = null ) : base(task) { Ensure.That(task.Target is TorrentTarget).IsTrue(); Ensure.That(cacheProvider, nameof(cacheFolder)).IsNotNull(); Ensure.That(folderProvider, nameof(folderProvider)).IsNotNull(); Ensure.That(engine, nameof(engine)).IsNotNull(); Ensure.That(maximumConnections).IsGt(0); Ensure.That(maximumDownloadSpeed).IsGte(0); Ensure.That(maximumUploadSpeed).IsGte(0); Ensure.That(uploadSlots).IsGt(0); this.engine = engine; this.cacheProvider = cacheProvider; this.folderProvider = folderProvider; this.maximumConnections = maximumConnections; this.maximumDownloadSpeed = maximumDownloadSpeed; this.maximumUploadSpeed = maximumUploadSpeed; this.uploadSlots = uploadSlots; this.announceUrls = announceUrls?.ToList(); TorrentTarget realTarget = (TorrentTarget)task.Target; Progress = new BaseMeasurableProgress( realTarget.Torrent.Files.Sum( file => realTarget.IsFileSelected(file) ? file.Length : 0)); Speed = SharedSpeedCalculatorFactory.NewSpeedCalculator(); Progress.ProgressChanged += (sender, arg) => Speed.CurrentValue = Progress.DownloadedSize; if (checkPoint != null) { ApplyCheckPoint(checkPoint); } }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> /// <param name="storageProvider">缓存储存提供程序</param> public StandardCachePolicy(HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache, ICacheStorageProvider storageProvider) : base(context, token, provider) { if (context == null) { throw new ArgumentNullException("context"); } if (provider == null) { throw new ArgumentNullException("provider"); } Duration = duration; EnableClientCache = enableClientCache; CacheStorageProvider = storageProvider; }
/// <summary> /// Construct a HttpDownloader with given task and configurations. /// </summary> /// <param name="task">Download task, must with HttpTarget.</param> /// <param name="folderProvider">Folder provider must not be null.</param> /// <param name="cacheProvider">Cache provider must not be null.</param> /// <param name="bufferProvider">Buffer provider must not be null.</param> public HttpDownloader( DownloadTask task, IFolderProvider folderProvider, ICacheStorageProvider cacheProvider, IBufferProvider bufferProvider ) : base(task) { Ensure.That(task.Target is HttpTarget, null, opts => opts.WithMessage($"type of {nameof(task.Target)} must be {nameof(HttpTarget)}") ).IsTrue(); Ensure.That(folderProvider, nameof(folderProvider)).IsNotNull(); Ensure.That(cacheProvider, nameof(cacheProvider)).IsNotNull(); Ensure.That(bufferProvider, nameof(bufferProvider)).IsNotNull(); this.folderProvider = folderProvider; this.cacheProvider = cacheProvider; this.bufferProvider = bufferProvider; Progress = new BaseProgress(); Speed = SharedSpeedCalculatorFactory.NewSpeedCalculator(); Progress.ProgressChanged += (sender, arg) => Speed.CurrentValue = Progress.DownloadedSize; }
public IPackageAcquisition BuildPackageAcquisition(Uri remotePackageStorageDirectory, ICacheStorageProvider storageProvider) { return(new PackageAcquisition(remotePackageStorageDirectory, storageProvider)); }
private UpdaterCache(ICacheStorageProvider storageProvider, IInstalledPackageMetadataCollection installedMetadataCollection) { this.StorageProvider = storageProvider; this.InstalledPackages = installedMetadataCollection; }
public PackageAcquisition(Uri remotePackageStorageDirectory, ICacheStorageProvider storageProvider) { this.remotePackageStorageDirectory = remotePackageStorageDirectory; this.storageProvider = storageProvider; }
public static T Get <T>(this ICacheStorageProvider provider, string key) { return((T)provider.Get <T>(key)); }
public DefaultCacheService( ShellSettings shellSettings, ICacheStorageProvider cacheStorageProvider) { _cacheStorageProvider = cacheStorageProvider; _prefix = shellSettings.Name; }