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 Post Get /// <summary> /// Get posts in categroy /// </summary> /// <param name="archiveId"></param> /// <param name="offset"></param> /// <returns></returns> public PostWithoutContent[] GetPostsInArchive(ArchiveId id, Int32 offset) { Func <Post, Boolean> predicate; if (id.Month.HasValue) { predicate = c => c.Published && c.DateCreatedGmt <= DateTime.UtcNow && c.DateCreatedGmt.Year == id.Year && c.DateCreatedGmt.Month == id.Month; } else { predicate = c => c.Published && c.DateCreatedGmt <= DateTime.UtcNow && c.DateCreatedGmt.Year == id.Year; } return(_context.Posts .Include(CategoriesPropertyName) .Where(predicate) .OrderByDescending(c => c.DateCreatedGmt) .Skip(offset) .Take(Settings.Current.PostQuantityPerSearch) .Select(c => new PostWithoutContent { Id = c.Id, Title = c.Title, Categories = c.Categories, DateCreatedGmt = c.DateCreatedGmt } ).ToArray()); }
/// <summary> /// Get more items when filter posts by category /// </summary> /// <param name="model"></param> /// <returns></returns> public PartialViewResult ArchiveGetMore(PostsFilter model) { ArchiveId id = new ArchiveId(model.Id); InitializeArchiveModel(model, id); return(PartialView(FilterGetMoreView, model)); }
public void ChangeBasedOnArchive(ArchiveId archiveId, Reason reason, OperatorName @operator, Organization.DutchTranslation organization, RequestedChanges requestedChanges) { //TODO: Verify there are no duplicate identifiers (will fail anyway) and report as rejection requestedChanges .VerifyWith(_view.With(requestedChanges)) .RecordUsing(archiveId, reason, @operator, organization, Apply); }
/// <summary> /// Get more items when filter posts by category /// </summary> /// <param name="model"></param> /// <returns></returns> public PartialViewResult ArchiveGetMore(PostsFilter model) { ArchiveId id = new ArchiveId(model.Id); using (var db = new DataService()) { InitializeArchiveModel(db, model, id); } return(PartialView(FilterGetMoreView, model)); }
public static RoadNetworkChangesArchive Upload(ArchiveId id) { var instance = new RoadNetworkChangesArchive(); instance.Apply(new RoadNetworkChangesArchiveUploaded { ArchiveId = id }); return(instance); }
public static Command ChangesTheRoadNetworkBasedOnAnArchive(ArchiveId archive, Reason reason, OperatorName @operator, OrganizationId organization, params RequestedChange[] changes) { return(new Command(new ChangeRoadNetworkBasedOnArchive { ArchiveId = archive, Reason = reason, Operator = @operator, OrganizationId = organization, Changes = changes })); }
public async Task <RoadNetworkChangesArchive> Get(ArchiveId id, CancellationToken ct = default) { var stream = new StreamName(id); if (_map.TryGet(stream, out var entry)) { return((RoadNetworkChangesArchive)entry.Entity); } var page = await _store.ReadStreamForwards(stream, StreamVersion.Start, 1024, ct); if (page.Status == PageReadStatus.StreamNotFound) { var network = RoadNetworkChangesArchive.Factory(); _map.Attach(new EventSourcedEntityMapEntry(network, stream, ExpectedVersion.NoStream)); return(network); } IEventSourcedEntity entity = RoadNetworkChangesArchive.Factory(); var messages = new List <object>(page.Messages.Length); foreach (var message in page.Messages) { messages.Add( JsonConvert.DeserializeObject( await message.GetJsonData(ct), _mapping.GetEventType(message.Type), _settings)); } entity.RestoreFromEvents(messages.ToArray()); while (!page.IsEnd) { messages.Clear(); page = await page.ReadNext(ct); if (page.Status == PageReadStatus.StreamNotFound) { var network = RoadNetworkChangesArchive.Factory(); _map.Attach(new EventSourcedEntityMapEntry(network, stream, ExpectedVersion.NoStream)); return(network); } foreach (var message in page.Messages) { messages.Add( JsonConvert.DeserializeObject( await message.GetJsonData(ct), _mapping.GetEventType(message.Type), _settings)); } entity.RestoreFromEvents(messages.ToArray()); } _map.Attach(new EventSourcedEntityMapEntry(entity, stream, page.LastStreamVersion)); return((RoadNetworkChangesArchive)entity); }
public void RecordUsing( ArchiveId archiveId, Reason reason, OperatorName @operator, Organization.DutchTranslation organization, Action <object> applier) { if (organization == null) { throw new ArgumentNullException(nameof(organization)); } if (applier == null) { throw new ArgumentNullException(nameof(applier)); } if (_changes.Count == 0) { return; } if (_changes.OfType <RejectedChange>().Any()) { applier(new Messages.RoadNetworkChangesBasedOnArchiveRejected { ArchiveId = archiveId, Reason = reason, Operator = @operator, OrganizationId = organization.Identifier, Organization = organization.Name, Changes = _changes .OfType <RejectedChange>() .Select(change => change.Translate()) .ToArray() }); } else { applier(new Messages.RoadNetworkChangesBasedOnArchiveAccepted { ArchiveId = archiveId, Reason = reason, Operator = @operator, OrganizationId = organization.Identifier, Organization = organization.Name, Changes = _changes .OfType <AcceptedChange>() .Select(change => change.Translate()) .ToArray() }); } }
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); } }
public RoadNetworkChangesArchiveEventModule( IBlobClient client, IZipArchiveTranslator translator, IStreamStore store) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (translator == null) { throw new ArgumentNullException(nameof(translator)); } if (store == null) { throw new ArgumentNullException(nameof(store)); } For <Messages.RoadNetworkChangesArchiveAccepted>() .UseRoadNetworkCommandQueue(store) .Handle(async(queue, message, ct) => { var archiveId = new ArchiveId(message.Body.ArchiveId); var archiveBlob = await client.GetBlobAsync(new BlobName(archiveId), ct); using (var archiveBlobStream = await archiveBlob.OpenAsync(ct)) using (var archive = new ZipArchive(archiveBlobStream, ZipArchiveMode.Read, false)) { var requestedChanges = new List <Messages.RequestedChange>(); var translatedChanges = translator.Translate(archive); foreach (var change in translatedChanges) { var requestedChange = new Messages.RequestedChange(); change.TranslateTo(requestedChange); requestedChanges.Add(requestedChange); } var command = new Command(new Messages.ChangeRoadNetworkBasedOnArchive { ArchiveId = archiveId, Changes = requestedChanges.ToArray(), Reason = translatedChanges.Reason, Operator = translatedChanges.Operator, OrganizationId = translatedChanges.Organization }) .WithMessageId(message.MessageId); await queue.Write(command, ct); } }); }
public override int GetHashCode() { unchecked { const int randomPrime = 397; int hashCode = Id.GetHashCode(); hashCode = (hashCode * randomPrime) ^ ArchiveId.GetHashCode(); hashCode = (hashCode * randomPrime) ^ (FondNumber != null ? FondNumber.GetHashCode() : 0); hashCode = (hashCode * randomPrime) ^ (FondName != null ? FondName.GetHashCode() : 0); hashCode = (hashCode * randomPrime) ^ (InventoryNumber != null ? InventoryNumber.GetHashCode() : 0); hashCode = (hashCode * randomPrime) ^ DocumentNumber.GetHashCode(); hashCode = (hashCode * randomPrime) ^ (TimeInterval != null ? TimeInterval.GetHashCode() : 0); hashCode = (hashCode * randomPrime) ^ (Language != null ? Language.GetHashCode() : 0); return(hashCode); } }
private void InitializeArchiveModel(PostsFilter model, ArchiveId id) { // Archive model.Action = "Archive"; // Gets posts model.Items = _dataService.GetPostsInArchive(id, model.Page * _options.Value.PostQuantityPerSearch); // Have more Int32 count = _dataService.CounPostsInArchive(id); model.Available = count; model.HaveMoreResults = count > (model.Page + 1) * _options.Value.PostQuantityPerSearch; // Update page index model.NextPage = model.Page + 1; }
/// <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)); }
public RoadNetworkCommandModule(IStreamStore store, IRoadNetworkSnapshotReader snapshotReader, IClock clock) { if (store == null) { throw new ArgumentNullException(nameof(store)); } if (snapshotReader == null) { throw new ArgumentNullException(nameof(snapshotReader)); } if (clock == null) { throw new ArgumentNullException(nameof(clock)); } For <ChangeRoadNetworkBasedOnArchive>() .UseValidator(new ChangeRoadNetworkBasedOnArchiveValidator()) .UseRoadRegistryContext(store, snapshotReader, EnrichEvent.WithTime(clock)) .Handle(async(context, message, ct) => { var archive = new ArchiveId(message.Body.ArchiveId); var @operator = new OperatorName(message.Body.Operator); var reason = new Reason(message.Body.Reason); var organizationId = new OrganizationId(message.Body.OrganizationId); var organization = await context.Organizations.TryGet(organizationId, ct); var translation = organization == null ? Organization.PredefinedTranslations.Unknown : organization.Translation; var network = await context.RoadNetworks.Get(ct); var translator = new RequestedChangeTranslator( network.ProvidesNextRoadNodeId(), network.ProvidesNextRoadSegmentId(), network.ProvidesNextGradeSeparatedJunctionId(), network.ProvidesNextEuropeanRoadAttributeId(), network.ProvidesNextNationalRoadAttributeId(), network.ProvidesNextNumberedRoadAttributeId(), network.ProvidesNextRoadSegmentLaneAttributeId(), network.ProvidesNextRoadSegmentWidthAttributeId(), network.ProvidesNextRoadSegmentSurfaceAttributeId() ); var requestedChanges = translator.Translate(message.Body.Changes); network.ChangeBasedOnArchive(archive, reason, @operator, translation, requestedChanges); }); }
/// <summary> /// Count posts in category /// </summary> /// <param name="archiveId"></param> /// <returns></returns> public Int32 CounPostsInArchive(ArchiveId id) { Func <Post, Boolean> predicate; if (id.Month.HasValue) { predicate = c => c.Published && c.DateCreatedGmt <= DateTime.UtcNow && c.DateCreatedGmt.Year == id.Year && c.DateCreatedGmt.Month == id.Month; } else { predicate = c => c.Published && c.DateCreatedGmt <= DateTime.UtcNow && c.DateCreatedGmt.Year == id.Year; } return(_context.Posts .Count(predicate)); }
/// <summary> /// Gets the core filter from this model. /// </summary> /// <returns>Filter.</returns> public ActFilter GetFilter(ITextFilter filter) { return(new ActFilter { PageNumber = PageNumber, PageSize = PageSize, ArchiveId = ArchiveId.GetValueOrDefault(), BookId = BookId.GetValueOrDefault(), BookYearMin = BookYearMin.GetValueOrDefault(), BookYearMax = BookYearMax.GetValueOrDefault(), Description = filter.Apply(Description), ActTypeId = ActTypeId.GetValueOrDefault(), FamilyId = FamilyId.GetValueOrDefault(), CompanyId = CompanyId.GetValueOrDefault(), PlaceId = PlaceId.GetValueOrDefault(), Label = filter.Apply(Label), CategoryIds = ParseIds(CategoryIds), ProfessionIds = ParseIds(ProfessionIds), PartnerIds = ParseIds(PartnerIds) }); }
public RoadNetworkChangesArchiveCommandModule( IBlobClient client, IStreamStore store, IRoadNetworkSnapshotReader snapshotReader, IZipArchiveValidator validator, IClock clock) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (store == null) { throw new ArgumentNullException(nameof(store)); } if (validator == null) { throw new ArgumentNullException(nameof(validator)); } if (clock == null) { throw new ArgumentNullException(nameof(clock)); } For <Messages.UploadRoadNetworkChangesArchive>() .UseRoadRegistryContext(store, snapshotReader, EnrichEvent.WithTime(clock)) .Handle(async(context, message, ct) => { var archiveId = new ArchiveId(message.Body.ArchiveId); var upload = RoadNetworkChangesArchive.Upload(archiveId); var archiveBlob = await client.GetBlobAsync(new BlobName(archiveId), ct); using (var archiveBlobStream = await archiveBlob.OpenAsync(ct)) using (var archive = new ZipArchive(archiveBlobStream, ZipArchiveMode.Read, false)) { upload.ValidateArchiveUsing(archive, validator); } context.RoadNetworkChangesArchives.Add(upload); }); }
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()); }
private static void InitializeArchiveModel(DataService db, PostsFilter model, ArchiveId id) { // Archive model.Action = "Archive"; // Gets posts model.Items = db.GetPostsInArchive(id, model.Page * Settings.Current.PostQuantityPerSearch); // Have more Int32 count = db.CounPostsInArchive(id); model.Available = count; model.HaveMoreResults = count > (model.Page + 1) * Settings.Current.PostQuantityPerSearch; // Update page index model.NextPage = model.Page + 1; }
private RoadNetworkChangesArchive() { On <RoadNetworkChangesArchiveUploaded>(e => Id = new ArchiveId(e.ArchiveId)); }