예제 #1
0
		private IList<LocalRemotePair> PrepareSigPairs(SignatureManifest signatureManifest)
		{
			var remoteSignatures = signatureManifest.Signatures;
			var localSignatures = localSignatureRepository.GetByFileName().ToList();

			var length = Math.Min(remoteSignatures.Count, localSignatures.Count);
			var remoteSignatureNames =
				remoteSignatures.Skip(remoteSignatures.Count - length).Take(length).Select(item => item.Name).ToList();
			var localSignatureNames =
				localSignatures.Skip(localSignatures.Count - length).Take(length).Select(item => item.Name).ToList();
			return
				localSignatureNames.Zip(remoteSignatureNames,
										(local, remote) => new LocalRemotePair { Local = local, Remote = remote }).ToList();
		}
예제 #2
0
		public Task<SignatureManifest> GetSignatureManifestAsync(DataInfo dataInfo)
		{
			return Task.Factory.StartNew(() =>
			{
				signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim())
									   .EnterUpgradeableReadLock();
				IEnumerable<SignatureInfo> signatureInfos = null;

				try
				{
					var lastUpdate = _signatureRepository.GetLastUpdate();

					if (lastUpdate == null || lastUpdate < dataInfo.CreatedAt)
					{
						signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim())
											   .EnterWriteLock();
						try
						{
							signatureInfos = PrepareSignatures(dataInfo.Name);
						}
						finally
						{
							signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim())
												   .ExitWriteLock();
						}
					}
					else
					{
						signatureInfos = _signatureRepository.GetByFileName();
					}
				}
				finally
				{
					signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim())
										   .ExitUpgradeableReadLock();
				}

				var result = new SignatureManifest
				{
					FileLength = dataInfo.Length,
					FileName = dataInfo.Name,
					Signatures = SignatureInfosToSignatures(signatureInfos)
				};
				return result;
			});
		}
예제 #3
0
        private async Task<SynchronizationReport> SynchronizeTo(RavenFileSystemClient.SynchronizationClient destination,
																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(destination, localFile, needList);
			}
		}