public async Task LoadBuffer(IChannel channel, UploadPartCommand command) { if (!_uploadPool.ContainsKey(channel)) { throw new InvalidOperationException("尚未准备完毕"); } if (string.IsNullOrEmpty(command.Base64Buffer)) { throw new InvalidOperationException("数据为空"); } byte[] buffy = Convert.FromBase64String(command.Base64Buffer); IFileModel uploadVideoModel = _uploadPool[channel]; if (uploadVideoModel == null) { throw new InvalidOperationException("不存在该文件"); } uploadVideoModel.LoadBuffer(buffy, command.Index); if (uploadVideoModel.CanComplete) { (string _, string path, long _) = await new UploadAccessory().SaveAccessoryAsync(uploadVideoModel.FileContent, $"{AppDomain.CurrentDomain.BaseDirectory}//Backup", uploadVideoModel.FileName, false); await UpdateWebFileAsync(path, channel); new HttpHandler().ClearCache(); var @event = new UploadEndEvent(); await channel.SendJsonEventAsync(@event); _uploadPool.Remove(channel); } else { var @event = new UploadReadyEvent(); await channel.SendJsonEventAsync(@event); } }
/// <inheritdoc/> public IAsyncResult BeginUploadPart(UploadPartRequest uploadPartRequest, AsyncCallback callback, object state) { var cmd = UploadPartCommand.Create(GetServiceClient(), _endpoint, CreateContext(HttpMethod.Put, uploadPartRequest.BucketName, uploadPartRequest.Key), uploadPartRequest); return(OssUtils.BeginOperationHelper(cmd, callback, state)); }
/// <inheritdoc/> public UploadPartResult UploadPart(UploadPartRequest uploadPartRequest) { ThrowIfNullRequest(uploadPartRequest); var cmd = UploadPartCommand.Create(GetServiceClient(), _endpoint, CreateContext(HttpMethod.Put, uploadPartRequest.BucketName, uploadPartRequest.Key), uploadPartRequest); return(cmd.Execute()); }
public async Task ShouldReturnFalseIfSessionIsNotFound() { // Arrange var fixture = new TestFixture <UploadPartCommandHandler>(); var command = new UploadPartCommand(new MemoryStream(), "1", "1"); // Act var result = await fixture.Sut.Handle(command, CancellationToken.None); // Assert result.Should().BeFalse(); }
public async Task <IActionResult> UploadPartAsync([FromRoute] string uploadId, [FromRoute] string partId, CancellationToken cancellationToken) { Request.EnableBuffering(); var command = new UploadPartCommand(Request.Body, partId, uploadId); var success = await _mediator.Send(command, cancellationToken); if (success) { return(Ok()); } return(BadRequest()); }
public async Task ShouldReturnTrueIfSessionWasUploaded() { // Arrange var fixture = new TestFixture <UploadPartCommandHandler>(); var data = new MemoryStream(); var command = new UploadPartCommand(data, "1", "1"); fixture.Freeze <ISessionsRepository>().FindNotCompletedSessionAsync(command.UploadId, CancellationToken.None) .Returns(fixture.Create <UploadSession>()); fixture.Freeze <IBlobStorage>().UploadBlockBlob(data, "1", "1", CancellationToken.None).Returns(true); // Act var result = await fixture.Sut.Handle(command, CancellationToken.None); // Assert result.Should().BeTrue(); }