Ejemplo n.º 1
0
        public async Task<HttpResponseMessage> Manifest(string id)
        {
            var canonicalFilename = FileHeader.Canonize(id);

            FileAndPagesInformation fileAndPages = null;
            
            Storage.Batch(accessor => fileAndPages = accessor.GetFile(canonicalFilename, 0, 0));

            long? fileLength = fileAndPages.TotalSize;

            using (var signatureRepository = new StorageSignatureRepository(Storage, canonicalFilename))
            {
                var rdcManager = new LocalRdcManager(signatureRepository, Storage, SigGenerator);
                var signatureManifest = await rdcManager.GetSignatureManifestAsync(
                                                                new DataInfo
                                                                {
                                                                    Name = canonicalFilename,
                                                                    LastModified = fileAndPages.Metadata.Value<DateTime>(Constants.RavenLastModified).ToUniversalTime()
                                                                });
                signatureManifest.FileLength = fileLength ?? 0;

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

                return GetMessageWithObject(signatureManifest)
                           .WithNoCache();
            }
        }
Ejemplo n.º 2
0
		public override async Task<SynchronizationReport> PerformAsync(ISynchronizationServerClient synchronizationServerClient)
        {
            AssertLocalFileExistsAndIsNotConflicted(FileMetadata);

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

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

            var conflict = CheckConflictWithDestination(FileMetadata, destinationMetadata, FileSystemInfo.Url);
	        if (conflict != null)
	        {
				var report = await HandleConflict(synchronizationServerClient, conflict, log);

		        if (report != null)
			        return report;
	        }

            using (var localSignatureRepository = new StorageSignatureRepository(Storage, FileName))
            using (var remoteSignatureCache = new VolatileSignatureRepository(FileName))
            {
                var localRdcManager = new LocalRdcManager(localSignatureRepository, Storage, sigGenerator);
				var destinationRdcManager = new RemoteRdcManager(synchronizationServerClient, 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.Any())
                {
                    var destinationSignatureManifest = await destinationRdcManager.SynchronizeSignaturesAsync(FileDataInfo, Cts.Token);
                    if (destinationSignatureManifest.Signatures.Any())
                    {
						return await SynchronizeTo(synchronizationServerClient, localSignatureRepository, remoteSignatureCache, localSignatureManifest, destinationSignatureManifest);
                    }
                }

				return await UploadToAsync(synchronizationServerClient);
            }
        }