/// <inheritdoc /> protected override Task <PutResult> PutStreamCoreAsync( OperationContext operationContext, ContentHash contentHash, Stream stream, UrgencyHint urgencyHint, Counter retryCounter) { // We need a seekable stream, that can give its length. If the input stream is seekable, we can use it directly. // Otherwise, we need to create a temp file for this purpose. Stream putStream; long position; Stream disposableStream; if (stream.CanSeek) { putStream = stream; position = stream.Position; disposableStream = null; } else { putStream = TempFileStreamFactory.Create(operationContext, stream); position = 0; disposableStream = putStream; } using (disposableStream) { return(PerformRetries( operationContext, () => RpcClient.PutStreamAsync(operationContext, contentHash, stream), retryCounter: retryCounter)); } }
/// <summary> /// Returns a file system implementation, which is assigned /// to the <see cref="TestContext.FileSystem"/> property. /// </summary> /// <param name="localTestFolder">The temporary test folder that is /// used by the context. This is actually just the <see cref="TestContext.LocalTestRoot"/> /// reference.</param> protected override IFileSystemProvider InitFileSystem(DirectoryInfo localTestFolder) { //init empty zip file ZipFilePath = Path.Combine(localTestFolder.FullName, "TestArchive.zip"); var zip = new ZipFile(ZipFilePath); zip.Save(); zip.Dispose(); //init transfer stores var downloadTransferStore = new TestTransferStore<ZipDownloadTransfer>(); var uploadTransferStore = new TestTransferStore<ZipUploadTransfer>(); //init configuration var tempFactory = new TempFileStreamFactory(LocalTestRoot.FullName); var zipFile = new FileInfo(ZipFilePath); var configuration = new ZipFileSystemConfiguration(zipFile, tempFactory); configuration.RootName = "Test Root"; configuration.DownloadStore = downloadTransferStore; configuration.UploadStore = uploadTransferStore; configuration.DownloadTokenExpirationTime = TimeSpan.FromHours(24); configuration.UploadTokenExpirationTime = TimeSpan.FromHours(24); configuration.DefaultDownloadBlockSize = 32768; configuration.MaxDownloadBlockSize = 32768 * 2; configuration.MaxUploadBlockSize = 32768 * 4; configuration.MaxUploadFileSize = (long)1024 * 1024 * 2048; //2GB limit //create provider Provider = new ZipFileProvider(configuration); return Provider; }
public static ZipFileSystemConfiguration CreateDefaultConfig(string zipfile, string tempDir) { //init transfer stores InMemoryTransferStore <ZipDownloadTransfer> downloadTransferStore = new InMemoryTransferStore <ZipDownloadTransfer>(); InMemoryTransferStore <ZipUploadTransfer> uploadTransferStore = new InMemoryTransferStore <ZipUploadTransfer>(); //init configuration var tempFactory = new TempFileStreamFactory(tempDir); var configuration = new ZipFileSystemConfiguration(new FileInfo(zipfile), tempFactory); configuration.DownloadStore = downloadTransferStore; configuration.UploadStore = uploadTransferStore; configuration.DownloadTokenExpirationTime = TimeSpan.FromHours(24); configuration.UploadTokenExpirationTime = TimeSpan.FromHours(24); configuration.DefaultDownloadBlockSize = 32768; configuration.MaxDownloadBlockSize = 32768 * 2; configuration.MaxUploadBlockSize = 32768 * 4; configuration.MaxUploadFileSize = (long)1024 * 1024 * 2048; //2GB limit // return(configuration); }
/// <inheritdoc /> protected override async Task <PutResult> PutStreamCoreAsync( OperationContext operationContext, HashType hashType, Stream stream, UrgencyHint urgencyHint, Counter retryCounter) { // We need a seekable stream, that can give its length. If the input stream is seekable, we can use it directly. // Otherwise, we need to create a temp file for this purpose. var putStream = stream; Stream disposableStream = null; if (!stream.CanSeek) { putStream = TempFileStreamFactory.Create(operationContext, stream); disposableStream = putStream; } using (disposableStream) { return(await PerformRetries( operationContext, () => RpcClient.PutStreamAsync(operationContext, hashType, putStream), retryCounter : retryCounter)); } }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyServiceClientContentSession"/> class. /// </summary> public ReadOnlyServiceClientContentSession( string name, ImplicitPin implicitPin, ILogger logger, IAbsFileSystem fileSystem, ServiceClientContentSessionTracer sessionTracer, ServiceClientContentStoreConfiguration configuration, Func <IRpcClient>?rpcClientFactory = null) : base(name) { Contract.Requires(name != null); Contract.Requires(logger != null); Contract.Requires(fileSystem != null); _implicitPin = implicitPin; SessionTracer = sessionTracer; Logger = logger; FileSystem = fileSystem; Configuration = configuration; TempFileStreamFactory = new TempFileStreamFactory(FileSystem); RpcClient = (rpcClientFactory ?? GetRpcClient)(); RetryPolicy = configuration.RetryPolicy; }
public void Init() { //init temp folder TempDirectory = TestUtil.CreateTestDirectory(); //create copy of test ZIP file within temp folder string path = Path.Combine(TempDirectory.FullName, "TestFile.zip"); File.WriteAllBytes(path, Resources.TestFile); TestZipFile = new FileInfo(path); //init transfer stores InMemoryTransferStore <ZipDownloadTransfer> DownloadTransferStore = new InMemoryTransferStore <ZipDownloadTransfer>(); InMemoryTransferStore <ZipUploadTransfer> UploadTransferStore = new InMemoryTransferStore <ZipUploadTransfer>(); //init configuration var tempFactory = new TempFileStreamFactory(TempDirectory.FullName); var configuration = new ZipFileSystemConfiguration(TestZipFile, tempFactory); configuration.RootName = "Test Root"; configuration.DownloadStore = DownloadTransferStore; configuration.UploadStore = UploadTransferStore; configuration.DownloadTokenExpirationTime = TimeSpan.FromHours(24); configuration.UploadTokenExpirationTime = TimeSpan.FromHours(24); configuration.DefaultDownloadBlockSize = 32768; configuration.MaxDownloadBlockSize = 32768 * 2; configuration.MaxUploadBlockSize = 32768 * 4; AdjustFileSystemConfiguration(configuration); FileSystemConfiguration = configuration; //create provider Provider = new ZipFileProvider(FileSystemConfiguration); InitInternal(); }
/// <summary> /// Returns a file system implementation, which is assigned /// to the <see cref="TestContext.FileSystem"/> property. /// </summary> /// <param name="localTestFolder">The temporary test folder that is /// used by the context. This is actually just the <see cref="TestContext.LocalTestRoot"/> /// reference.</param> protected override IFileSystemProvider InitFileSystem(DirectoryInfo localTestFolder) { //init empty zip file ZipFilePath = Path.Combine(localTestFolder.FullName, "TestArchive.zip"); var zip = new ZipFile(ZipFilePath); zip.Save(); zip.Dispose(); //init transfer stores var downloadTransferStore = new TestTransferStore <ZipDownloadTransfer>(); var uploadTransferStore = new TestTransferStore <ZipUploadTransfer>(); //init configuration var tempFactory = new TempFileStreamFactory(LocalTestRoot.FullName); var zipFile = new FileInfo(ZipFilePath); var configuration = new ZipFileSystemConfiguration(zipFile, tempFactory); configuration.RootName = "Test Root"; configuration.DownloadStore = downloadTransferStore; configuration.UploadStore = uploadTransferStore; configuration.DownloadTokenExpirationTime = TimeSpan.FromHours(24); configuration.UploadTokenExpirationTime = TimeSpan.FromHours(24); configuration.DefaultDownloadBlockSize = 32768; configuration.MaxDownloadBlockSize = 32768 * 2; configuration.MaxUploadBlockSize = 32768 * 4; configuration.MaxUploadFileSize = (long)1024 * 1024 * 2048; //2GB limit //create provider Provider = new ZipFileProvider(configuration); return(Provider); }