Exemple #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());
            }
        }
        public override async Task <SynchronizationReport> PerformAsync(IAsyncFilesSynchronizationCommands destination)
        {
            AssertLocalFileExistsAndIsNotConflicted(FileMetadata);

            var destinationMetadata = await destination.Commands.GetMetadataForAsync(FileName);

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

            var destinationServerRdcStats = await destination.GetRdcStatsAsync();

            if (!IsRemoteRdcCompatible(destinationServerRdcStats))
            {
                throw new SynchronizationException("Incompatible RDC version detected on destination server");
            }

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

            if (conflict != null)
            {
                var report = await HandleConflict(destination, 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(destination, 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(destination, localSignatureRepository, remoteSignatureCache, localSignatureManifest, destinationSignatureManifest));
                        }
                    }

                    return(await UploadToAsync(destination));
                }
        }
        public void Should_throw_FileNotFoundException_for_unknown_file()
        {
            transactionalStorage.Batch(accessor =>
            {
                accessor.AddSignature("test", 1, stream => stream.Write(new byte[] { 3 }, 0, 1));
            });

            var tested = new StorageSignatureRepository(transactionalStorage, "test", configuration);

            Assert.Throws(typeof(FileNotFoundException), () => tested.GetContentForReading("test.0.sig"));
        }
        public void Should_read_from_storage()
        {
            transactionalStorage.Batch(accessor =>
            {
                accessor.AddSignature("test", 1, stream => stream.Write(new byte[] { 3 }, 0, 1));
            });

            var tested = new StorageSignatureRepository(transactionalStorage, "test", configuration);

            Assert.Equal(3, tested.GetContentForReading("test.1.sig").ReadByte());
        }
        public void Should_get_SignatureInfo()
        {
            transactionalStorage.Batch(accessor =>
            {
                accessor.AddSignature("test", 1, stream => stream.Write(new byte[] { 3 }, 0, 1));
            });
            var tested = new StorageSignatureRepository(transactionalStorage, "test", configuration);
            var result = tested.GetByName("test.1.sig");

            Assert.Equal("test.1.sig", result.Name);
            Assert.Equal(1, result.Length);
        }
Exemple #6
0
        public HttpResponseMessage Signatures(string id)
        {
            var canonicalFilename = FileHeader.Canonize(id);

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

            using (var signatureRepository = new StorageSignatureRepository(Storage, canonicalFilename))
            {
                var localRdcManager = new LocalRdcManager(signatureRepository, Storage, SigGenerator);
                var resultContent   = localRdcManager.GetSignatureContentForReading(canonicalFilename);
                return(StreamResult(canonicalFilename, resultContent));
            }
        }
Exemple #7
0
        public HttpResponseMessage Signatures(string id)
        {
            var filename = Uri.UnescapeDataString(id);

            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));
            }
        }
        public void Should_assign_signature_to_proper_file(string fileName)
        {
            var tested = new StorageSignatureRepository(transactionalStorage, fileName, configuration);

            using (var sigContent = tested.CreateContent(fileName + ".0.sig"))
            {
                sigContent.WriteByte(3);
            }
            tested.Flush(new[] { SignatureInfo.Parse(fileName + ".0.sig") });

            var result = tested.GetByName(fileName + ".0.sig");

            Assert.Equal(fileName + ".0.sig", result.Name);
            Assert.Equal(1, result.Length);
        }
        public void Should_get_SignaturInfos_by_file_name()
        {
            var tested = new StorageSignatureRepository(transactionalStorage, "test", configuration);

            transactionalStorage.Batch(accessor =>
            {
                accessor.AddSignature("test", 0, stream => stream.Write(new byte[] { 3 }, 0, 1));
                accessor.AddSignature("test", 1, stream => stream.Write(new byte[] { 3 }, 0, 1));
                accessor.AddSignature("test", 2, stream => stream.Write(new byte[] { 3 }, 0, 1));
            });

            var signatureInfos = tested.GetByFileName().ToList();

            Assert.Equal(3, signatureInfos.Count());
            foreach (var item in signatureInfos)
            {
                Assert.Equal(1, item.Length);
            }
        }
Exemple #10
0
        public async Task <HttpResponseMessage> Manifest(string id)
        {
            var          filename     = Uri.UnescapeDataString(id);
            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.Value <string>("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(this.GetMessageWithObject(signatureManifest, HttpStatusCode.OK)
                       .WithNoCache());
            }
        }