예제 #1
0
		public void Generate_check()
		{
			IList<SignatureInfo> sourceSignatureInfos;
			IList<SignatureInfo> seedSignatureInfos;
			using (var sourceSignatureRepository = CreateSignatureRepositoryFor("test"))
			using (var seedSignatureRepository = CreateSignatureRepositoryFor("test"))
			{
				using (var generator = new SigGenerator())
				{
					seedSignatureInfos = generator.GenerateSignatures(GetSeedStream(), "test", seedSignatureRepository);
				}
				var sourceStream = GetSourceStream();
				using (var generator = new SigGenerator())
				{
					sourceSignatureInfos = generator.GenerateSignatures(sourceStream, "test", sourceSignatureRepository);
				}
				var sourceSize = sourceStream.Length;
				using (var tested = new NeedListGenerator(sourceSignatureRepository, seedSignatureRepository))
				{
					var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last());
					Assert.NotNull(result);

					Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength)));
				}
			}
		}
예제 #2
0
		public void ctor_and_dispose()
		{
			using (var signatureRepository = CreateSignatureRepositoryFor("test"))
			using (var tested = new NeedListGenerator(signatureRepository, signatureRepository))
			{
				Assert.NotNull(tested);
			}
		}
예제 #3
0
		private async Task SynchronizeAsync(string localSigName, string localSigSigName, string remoteSigName,
											string remoteSigSigName, CancellationToken token)
		{
			using (var needListGenerator = new NeedListGenerator(localSignatureRepository, remoteCacheSignatureRepository))
			{
				var source = new RemoteSignaturePartialAccess(synchronizationServerClient, remoteSigName);
				var seed = new SignaturePartialAccess(localSigName, localSignatureRepository);
				var needList = needListGenerator.CreateNeedsList(SignatureInfo.Parse(localSigSigName),
																 SignatureInfo.Parse(remoteSigSigName), token);

				using (var output = remoteCacheSignatureRepository.CreateContent(remoteSigName))
				{
					await NeedListParser.ParseAsync(source, seed, output, needList, token);
				}
			}
		}
예제 #4
0
		public void Synchronize_file_with_different_beginning()
		{
			const int size = 5000;
			var differenceChunk = new MemoryStream();
			var sw = new StreamWriter(differenceChunk);

			sw.Write("Coconut is Stupid");
			sw.Flush();

			var sourceContent = PrepareSourceStream(size);
			sourceContent.Position = 0;
			var seedContent = new CombinedStream(differenceChunk, sourceContent);

			using (var sourceSignatureRepository = CreateSignatureRepositoryFor("test2"))
			using (var seedSignatureRepository = CreateSignatureRepositoryFor("test1"))
			{
				IList<SignatureInfo> seedSignatureInfos;
				using (var generator = new SigGenerator())
				{
					seedContent.Seek(0, SeekOrigin.Begin);
					seedSignatureInfos = generator.GenerateSignatures(seedContent, "test1", seedSignatureRepository);
				}
				IList<SignatureInfo> sourceSignatureInfos;
				using (var generator = new SigGenerator())
				{
					sourceContent.Seek(0, SeekOrigin.Begin);
					sourceSignatureInfos = generator.GenerateSignatures(sourceContent, "test2", sourceSignatureRepository);
				}
				var sourceSize = sourceContent.Length;

				using (var tested = new NeedListGenerator(seedSignatureRepository, sourceSignatureRepository))
				{
					var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last());
					Assert.NotNull(result);
					Assert.Equal(2, result.Count);
					Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength)));
				}
			}
		}
예제 #5
0
        public void Synchronize_file_with_different_sizes_and_completely_different_content()
        {
            var seedBuffer = new byte[1024 * 1024 * 2]; // 2 MB     
            new Random().NextBytes(seedBuffer);
            var seedContent = new MemoryStream(seedBuffer);

            var smallerBuffer = new byte[1024 * 1024];
            new Random().NextBytes(smallerBuffer);
            var changedContent = new MemoryStream(smallerBuffer);

            using (var seedSignatureRepository = CreateSignatureRepositoryFor("seed"))
            using (var sourceSignatureRepository = CreateSignatureRepositoryFor("source"))
            {
                IList<SignatureInfo> seedSignatureInfos;
                using (var generator = new SigGenerator())
                {
                    seedContent.Seek(0, SeekOrigin.Begin);
                    seedSignatureInfos = generator.GenerateSignatures(seedContent, "seed", seedSignatureRepository);
                }
                IList<SignatureInfo> sourceSignatureInfos;
                using (var generator = new SigGenerator())
                {
                    changedContent.Seek(0, SeekOrigin.Begin);
                    sourceSignatureInfos = generator.GenerateSignatures(changedContent, "source", sourceSignatureRepository);
                }

                var sourceSize = changedContent.Length;

                using (var tested = new NeedListGenerator(seedSignatureRepository, sourceSignatureRepository))
                {
                    var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last());
                    Assert.NotNull(result);
                    Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength)));
                }
            }
        }
예제 #6
0
		private async Task<SynchronizationReport> SynchronizeTo(ISynchronizationServerClient synchronizationServerClient,
																ISignatureRepository localSignatureRepository,
																ISignatureRepository remoteSignatureRepository,
																SignatureManifest sourceSignatureManifest,
																SignatureManifest destinationSignatureManifest)
		{
			var seedSignatureInfo = SignatureInfo.Parse(destinationSignatureManifest.Signatures.Last().Name);
			var sourceSignatureInfo = SignatureInfo.Parse(sourceSignatureManifest.Signatures.Last().Name);

			using (var localFile = StorageStream.Reading(Storage, FileName))
			{
				IList<RdcNeed> needList;
				using (var needListGenerator = new NeedListGenerator(remoteSignatureRepository, localSignatureRepository))
				{
					needList = needListGenerator.CreateNeedsList(seedSignatureInfo, sourceSignatureInfo, Cts.Token);
				}

				return await PushByUsingMultipartRequest(synchronizationServerClient, localFile, needList);
			}
		}