コード例 #1
0
        public async Task AddReceivedFile_RecipientShouldBeLinkedToFolder()
        {
            var fileRepositoryMock = new Mock <IFileRepository>();

            fileRepositoryMock.Setup(x => x.AddReceivedFile(It.IsAny <File>()))
            .ReturnsAsync(() => Result.Success());

            string addedHost               = null;
            string addedAddress            = null;
            Guid   addedFolderId           = Guid.Empty;
            var    recipientRepositoryMock = new Mock <IRecipientRepository>();

            recipientRepositoryMock.Setup(x => x.AddRecipientToFolder(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()))
            .Callback <string, string, Guid>((x, y, z) =>
            {
                addedHost     = x;
                addedAddress  = y;
                addedFolderId = z;
            })
            .ReturnsAsync(() => Result.Success());

            var newFolderGuid        = Guid.NewGuid();
            var folderRepositoryMock = new Mock <IFolderRepository>();

            folderRepositoryMock.Setup(x => x.AddFolder(It.IsAny <string>()))
            .ReturnsAsync(() => Result <Guid> .Success(newFolderGuid));
            var currentTimeStamp = DateTime.Now;

            var fileService = new FileService(fileRepositoryMock.Object, folderRepositoryMock.Object, recipientRepositoryMock.Object);
            var result      = await fileService.AddReceivedFile(Guid.NewGuid(), "TestFolder", "testFile", 1, 2, currentTimeStamp, "TestPath", "Localhost");


            Assert.AreEqual(newFolderGuid, addedFolderId);
            Assert.AreEqual("Localhost", addedHost);
            Assert.AreEqual(DummyAdress.Create("Localhost"), addedAddress);
        }
コード例 #2
0
        public async Task <IActionResult> Post(Guid fileId, int sequenceNo, string host)
        {
            WorkerLog.Instance.Information($"Filechunk received from {host}");
            using (var ms = _recyclableMemoryStreamManager.GetStream())
            {
                var outgoingQueue = _workerQueueContainer.ReceivedChunks.Writer;
                await Request.Body.CopyToAsync(ms);

                if (await outgoingQueue.WaitToWriteAsync())
                {
                    await outgoingQueue.WriteAsync(new ReceivedFileChunk(fileId, sequenceNo, ms.ToArray(), host, DummyAdress.Create(host)));

                    return(NoContent());
                }
                else
                {
                    return(StatusCode(500));
                }
            }
        }
コード例 #3
0
ファイル: FileService.cs プロジェクト: puppetSpace/Replicate
        public async Task <Result> AddReceivedFile(Guid fileId, string folderName, string name, long size, int version, DateTime lastModifiedDate, string path, string host)
        {
            var folderCreation = await AddFolder(folderName);

            if (folderCreation.WasSuccessful)
            {
                var fileResult = await _fileRepository.AddReceivedFile(new File
                                                                       (
                                                                           fileId,
                                                                           folderCreation.Data,
                                                                           name,
                                                                           path,
                                                                           lastModifiedDate,
                                                                           size,
                                                                           FileSource.Remote,
                                                                           version
                                                                       ));

                var recipientResult = await _recipientRepository.AddRecipientToFolder(host, DummyAdress.Create(host), folderCreation.Data);

                return(fileResult.WasSuccessful && recipientResult.WasSuccessful
                                        ? Result.Success()
                                        : Result.Failure());
            }

            return(Result.Failure());
        }
コード例 #4
0
            //todo check to use streaming
            // server can use while loop to keep sending as long as there are items and the client is not disconnected (u can use the context callecation token)
            public async Task <FileChunkTransmissionResponse> SendFileChunk(FileChunkTransmissionRequest request)
            {
                WorkerLog.Instance.Information($"Filechunk received from {request.Host}");
                var outgoingQueue = _workerQueueContainer.ReceivedChunks.Writer;

                if (await outgoingQueue.WaitToWriteAsync())
                {
                    await outgoingQueue.WriteAsync(new ReceivedFileChunk(Guid.Parse(request.FileId), request.SequenceNo, request.Value.ToByteArray(), request.Host, DummyAdress.Create(request.Host)));
                }
                return(_successFullFileChunkTransmissionResponse);
            }
コード例 #5
0
 public static Worker.Host.Models.Recipient GetRecipientModel(string name)
 => new Worker.Host.Models.Recipient(name, DummyAdress.Create(name), false);