Пример #1
0
		private Task<SynchronizationReport> PushByUsingMultipartRequest(ISynchronizationServerClient synchronizationServerClient, Stream sourceFileStream,
																		IList<RdcNeed> needList)
		{
			Cts.Token.ThrowIfCancellationRequested();

			multipartRequest = new SynchronizationMultipartRequest(synchronizationServerClient, FileSystemInfo, FileName, FileMetadata, sourceFileStream, needList);

			var bytesToTransferCount = needList.Where(x => x.BlockType == RdcNeedType.Source).Sum(x => (double)x.BlockLength);

			log.Debug(
				"Synchronizing a file '{0}' (ETag {1}) to {2} by using multipart request. Need list length is {3}. Number of bytes that needs to be transfered is {4}",
				FileName, FileETag, synchronizationServerClient, needList.Count, bytesToTransferCount);

			return multipartRequest.PushChangesAsync(Cts.Token);
		}
		private static async Task<string> ExecuteRawSynchronizationRequest(IAsyncFilesCommands sourceClient, IAsyncFilesCommands destinationClient, Action action = null)
		{
			await destinationClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("destination")));

			if (action != null)
				action();

			await sourceClient.UploadAsync("test", new MemoryStream(Encoding.UTF8.GetBytes("source")));

			var sourceStream = new MemoryStream();

			(await sourceClient.DownloadAsync("test")).CopyTo(sourceStream);

			var metadata = await sourceClient.GetMetadataForAsync("test");

			var request = new SynchronizationMultipartRequest(destinationClient.Synchronization, new ServerInfo()
			{
				FileSystemUrl = sourceClient.UrlFor(),
				Id = sourceClient.GetServerIdAsync().Result
			}, "test", metadata, sourceStream, new[]
			{
				new RdcNeed()
				{
					BlockLength = 6,
					BlockType = RdcNeedType.Source,
					FileOffset = 0
				}
			});

			var synchronizationReport = await request.PushChangesAsync(CancellationToken.None);

			Assert.Null(synchronizationReport.Exception);

			var stream = await destinationClient.DownloadAsync("test");

			return StreamToString(stream);
		}