public async Task <IActionResult> Get(string identifier) { if (!ArchiveId.Accepts(identifier)) { return(BadRequest()); } var archiveId = new ArchiveId(identifier); var blobName = new BlobName(archiveId.ToString()); if (!await _client.BlobExistsAsync(blobName, HttpContext.RequestAborted)) { return(NotFound()); } var blob = await _client.GetBlobAsync(blobName, HttpContext.RequestAborted); var filename = blob.Metadata .Single(pair => pair.Key == new MetadataKey("filename")); return(new FileCallbackResult( new MediaTypeHeaderValue("application/zip"), async(stream, actionContext) => { using (var blobStream = await blob.OpenAsync(actionContext.HttpContext.RequestAborted)) { await blobStream.CopyToAsync(stream, actionContext.HttpContext.RequestAborted); } }) { FileDownloadName = filename.Value }); }
public async Task <IActionResult> Post(IFormFile archive) { if (archive == null) { throw new ArgumentNullException(nameof(archive)); } if (!ContentType.TryParse(archive.ContentType, out var parsed) || parsed != ContentType.Parse("application/zip")) { return(new UnsupportedMediaTypeResult()); } using (var readStream = archive.OpenReadStream()) { var archiveId = new ArchiveId(Guid.NewGuid().ToString("N")); var metadata = Metadata.None.Add(new KeyValuePair <MetadataKey, string>(new MetadataKey("filename"), string.IsNullOrEmpty(archive.FileName) ? archiveId + ".zip" : archive.FileName)); await _client.CreateBlobAsync( new BlobName(archiveId.ToString()), metadata, ContentType.Parse("application/zip"), readStream, HttpContext.RequestAborted ); var message = new Command( new UploadRoadNetworkChangesArchive { ArchiveId = archiveId.ToString() }); await _dispatcher(message, HttpContext.RequestAborted); } return(Ok()); }
public async Task When_downloading_activities_of_filled_registry() { var controller = new ChangeFeedController(new FakeClock(NodaConstants.UnixEpoch)) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; var database = await _fixture.CreateDatabaseAsync(); var archiveId = new ArchiveId(Guid.NewGuid().ToString("N")); using (var context = await _fixture.CreateEmptyBackOfficeContextAsync(database)) { context.RoadNetworkChanges.Add(new RoadNetworkChange { Title = "De oplading werd ontvangen.", Type = nameof(RoadNetworkChangesArchiveUploaded), Content = JsonConvert.SerializeObject(new RoadNetworkChangesArchiveUploadedEntry { Archive = new RoadNetworkChangesArchiveInfo { Id = archiveId, Available = true, Filename = "file.zip" } }), When = InstantPattern.ExtendedIso.Format(NodaConstants.UnixEpoch) }); await context.SaveChangesAsync(); } using (var context = await _fixture.CreateBackOfficeContextAsync(database)) { var result = await controller.Get(context); var jsonResult = Assert.IsType <JsonResult>(result); Assert.Equal(StatusCodes.Status200OK, jsonResult.StatusCode); var response = Assert.IsType <ChangeFeedResponse>(jsonResult.Value); var item = Assert.Single(response.Entries); Assert.NotNull(item); Assert.Equal(0, item.Id); Assert.Equal("De oplading werd ontvangen.", item.Title); Assert.Equal(nameof(RoadNetworkChangesArchiveUploaded), item.Type); var content = Assert.IsType <RoadNetworkChangesArchiveUploadedEntry>(item.Content); Assert.Equal(archiveId.ToString(), content.Archive.Id); Assert.True(content.Archive.Available); Assert.Equal("file.zip", content.Archive.Filename); Assert.Equal("01", item.Day); // YR: Different versions of libicu use different casing Assert.Equal("jan.", item.Month.ToLowerInvariant()); Assert.Equal("01:00", item.TimeOfDay); } }
/// <summary> /// Filter post by category /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult Archive(PostsFilter model) { ArchiveId id = new ArchiveId(model.Id); // Title model.Title = Resources.Archives; // Get name model.SubTitle = id.ToString(); model.Description = String.Format( Resources.ArchivesDescription, model.SubTitle); // Initialize the data InitializeArchiveModel(model, id); return(View(FilterView, model)); }