Exemplo n.º 1
0
		public async Task<HttpResponseMessage> Manifest(string filename)
		{
			filename = Uri.UnescapeDataString(filename);
			FileAndPages fileAndPages = null;
			try
			{
				Storage.Batch(accessor => fileAndPages = accessor.GetFile(filename, 0, 0));
			}
			catch (FileNotFoundException)
			{
				Log.Debug("Signature manifest for a file '{0}' was not found", filename);
				return Request.CreateResponse(HttpStatusCode.NotFound);
			}

			long? fileLength = fileAndPages.TotalSize;

			using (var signatureRepository = new StorageSignatureRepository(Storage, filename))
			{
				var rdcManager = new LocalRdcManager(signatureRepository, Storage, SigGenerator);
				var signatureManifest =
					await rdcManager.GetSignatureManifestAsync(new DataInfo
						                                           {
							                                           Name = filename,
							                                           CreatedAt =
								                                           Convert.ToDateTime(fileAndPages.Metadata["Last-Modified"])
								                                                  .ToUniversalTime()
						                                           });
				signatureManifest.FileLength = fileLength ?? 0;

				Log.Debug("Signature manifest for a file '{0}' was downloaded. Signatures count was {1}", filename,
				          signatureManifest.Signatures.Count);

				return Request.CreateResponse(HttpStatusCode.OK, signatureManifest);
			}
		}
		public override async Task<SynchronizationReport> PerformAsync(string destination)
		{
			AssertLocalFileExistsAndIsNotConflicted(FileMetadata);

			var destinationRavenFileSystemClient = new RavenFileSystemClient(destination);

			var destinationMetadata = await destinationRavenFileSystemClient.GetMetadataForAsync(FileName);

			if (destinationMetadata == null)
			{
				// if file doesn't exist on destination server - upload it there
				return await UploadToAsync(destination);
			}

			var destinationServerRdcStats = await destinationRavenFileSystemClient.Synchronization.GetRdcStatsAsync();
			if (!IsRemoteRdcCompatible(destinationServerRdcStats))
				throw new SynchronizationException("Incompatible RDC version detected on destination server");

			var conflict = CheckConflictWithDestination(FileMetadata, destinationMetadata, ServerInfo.Url);

			if (conflict != null)
				return await ApplyConflictOnDestinationAsync(conflict, destination, ServerInfo.Url, log);

			using (var localSignatureRepository = new StorageSignatureRepository(Storage, FileName))
			using (var remoteSignatureCache = new VolatileSignatureRepository(FileName))
			{
				var localRdcManager = new LocalRdcManager(localSignatureRepository, Storage, sigGenerator);
				var destinationRdcManager = new RemoteRdcManager(destinationRavenFileSystemClient, localSignatureRepository,
				                                                 remoteSignatureCache);

				log.Debug("Starting to retrieve signatures of a local file '{0}'.", FileName);

				Cts.Token.ThrowIfCancellationRequested();

				// first we need to create a local file signatures before we synchronize with remote ones
				var localSignatureManifest = await localRdcManager.GetSignatureManifestAsync(FileDataInfo);

				log.Debug("Number of a local file '{0}' signatures was {1}.", FileName, localSignatureManifest.Signatures.Count);

				if (localSignatureManifest.Signatures.Count > 0)
				{
					var destinationSignatureManifest = await destinationRdcManager.SynchronizeSignaturesAsync(FileDataInfo, Cts.Token);

					if (destinationSignatureManifest.Signatures.Count > 0)
					{
						return
							await
							SynchronizeTo(destination, localSignatureRepository, remoteSignatureCache, localSignatureManifest,
							              destinationSignatureManifest);
					}
				}

				return await UploadToAsync(destination);
			}
		}
Exemplo n.º 3
0
		public HttpResponseMessage Signatures(string filename)
		{
			filename = Uri.UnescapeDataString(filename);

			Log.Debug("Got signatures of a file '{0}' request", filename);

			using (var signatureRepository = new StorageSignatureRepository(Storage, filename))
			{
				var localRdcManager = new LocalRdcManager(signatureRepository, Storage, SigGenerator);
				var resultContent = localRdcManager.GetSignatureContentForReading(filename);
				return StreamResult(filename, resultContent);
			}
		}