public Func <T, bool> GetInMemoryFilter <T>(bool userInterface) where T : Entity { using (userInterface ? ExecutionMode.UserInterface() : null) { EntityEvents <T>?ee = (EntityEvents <T>?)entityEvents.TryGetC(typeof(T)); if (ee == null) { return(a => true); } Func <T, bool>?result = null; foreach (var item in ee.OnFilterQuery().NotNull()) { if (item.InMemoryFunction == null) { throw new InvalidOperationException("FilterQueryResult with InDatabaseExpresson '{0}' has no equivalent InMemoryFunction" .FormatWith(item.InDatabaseExpresson.ToString())); } result = CombineFunc(result, item.InMemoryFunction); } if (result == null) { return(a => true); } return(result); } }
internal void RemapEntityKeys(KeyMapping keyMapping) { if (keyMapping.Map.Count == 0) { return; } using (Activate()) { if (!LazyKeyGenerationIsEnabled) { Persist(PersistReason.RemapEntityKeys); Invalidate(); } OrmLog.Debug(Strings.LogSessionXRemappingEntityKeys, this); foreach (var entityState in EntityChangeRegistry.GetItems(PersistenceState.New)) { var key = entityState.Key; var remappedKey = keyMapping.TryRemapKey(key); if (remappedKey != key) { entityState.RemapKey(remappedKey); } EntityStateCache.Add(entityState); } ProcessChangesOfEntitySets(entitySetState => entitySetState.RemapKeys(keyMapping)); EntityEvents.RemapKeys(keyMapping); } }
private async ValueTask RemapEntityKeys(KeyMapping keyMapping, bool isAsync, CancellationToken token = default) { if (keyMapping.Map.Count == 0) { return; } using (Activate()) { if (!LazyKeyGenerationIsEnabled) { await Persist(PersistReason.RemapEntityKeys, isAsync, token).ConfigureAwait(false); Invalidate(); } if (IsDebugEventLoggingEnabled) { OrmLog.Debug(Strings.LogSessionXRemappingEntityKeys, this); } foreach (var entityState in EntityChangeRegistry.GetItems(PersistenceState.New)) { var key = entityState.Key; var remappedKey = keyMapping.TryRemapKey(key); if (remappedKey != key) { entityState.RemapKey(remappedKey); } EntityStateCache.Add(entityState); } ProcessChangesOfEntitySets(entitySetState => entitySetState.RemapKeys(keyMapping)); EntityEvents.RemapKeys(keyMapping); } }
public IStatusGeneric Handle(EntityEvents callingEntity, OrderCreatedEvent domainEvent) { var tax = _rateFinder.GetTaxRateInEffect(domainEvent.ExpectedDispatchDate); domainEvent.SetTaxRatePercent(tax); return(null); }
public IStatusGeneric Handle(EntityEvents callingEntity, TaxRateChangedEvent domainEvent) { //do something with the new tax rate domainEvent.RefreshGrandTotalPrice(); //example of using Action/Func to set something inside the calling class return(new StatusGenericHandler()); }
internal CacheControllerBase <T>?CacheController <T>() where T : Entity { EntityEvents <T>?ee = (EntityEvents <T>?)entityEvents.TryGetC(typeof(T)); if (ee == null) { return(null); } return(ee.CacheController); }
public IStatusGeneric Handle(EntityEvents callingEntity, BookReviewRemovedEvent domainEvent) { //Here is the fast (delta) version of the update. Doesn't need access to the database var numReviews = domainEvent.Book.ReviewsCount - 1; var totalStars = Math.Round(domainEvent.Book.ReviewsAverageVotes * domainEvent.Book.ReviewsCount) - domainEvent.ReviewRemoved.NumStars; domainEvent.UpdateReviewCachedValues(numReviews, totalStars / numReviews); return(null); }
public BaseGameEvents() { Player = new PlayerEvents(); Time = new TimeEvents(); Monsters = new MonsterEvents(); Entities = new EntityEvents(); Flow = new FlowEvents(); Health = new HPEvents(); Battle = new BattleEvents(); Traps = new TrapEvents(); Blocks = new BlockingEvents(); }
internal IDisposable?OnPreUnsafeMListDelete <T>(IQueryable mlistQuery, IQueryable <T> entityQuery) where T : Entity { AssertAllowed(typeof(T), inUserInterface: false); EntityEvents <T>?ee = (EntityEvents <T>?)entityEvents.TryGetC(typeof(T)); if (ee == null) { return(null); } return(ee.OnPreUnsafeMListDelete(mlistQuery, entityQuery)); }
internal IDisposable?OnPreUnsafeDelete <T>(IQueryable <T> entityQuery) where T : Entity { AssertAllowed(typeof(T), inUserInterface: false); EntityEvents <T>?ee = (EntityEvents <T>?)entityEvents.TryGetC(typeof(T)); if (ee == null) { return(null); } return(Disposable.Combine(ee?.OnPreUnsafeDelete(entityQuery), entityEventsGlobal.OnPreUnsafeDelete(entityQuery))); }
/// <summary> /// Register entity events /// </summary> /// <param name="services"></param> /// <returns></returns> public static IServiceCollection AddEntityModuleEvents(this IServiceCollection services) { //Register entity events EntityEvents.RegisterEvents(); SystemEvents.Application.OnApplicationStarted += delegate(object sender, ApplicationStartedEventArgs args) { var scopeContextFactory = (DbContext)args.Services.GetRequiredService <IEntityContext>(); DbConnectionFactory.Connection.SetConnection(scopeContextFactory.Database.GetDbConnection()); }; SystemEvents.Application.OnApplicationStopped += delegate { DbConnectionFactory.CloseAll(); }; return(services); }
public IStatusGeneric Handle(EntityEvents callingEntity, AllocateProductEvent domainEvent) { var status = new StatusGenericHandler(); var stock = _context.Find <ProductStock>(domainEvent.ProductName); if (stock == null) { throw new ApplicationException($"could not find the stock for product called {domainEvent.ProductName} "); } if (stock.NumInStock < domainEvent.NumOrdered) { return(status.AddError( $"I could not accept this order because there wasn't enough {domainEvent.ProductName} in stock.")); } stock.NumAllocated += domainEvent.NumOrdered; return(status); }
internal FilterQueryResult <T>?OnFilterQuery <T>() where T : Entity { AssertAllowed(typeof(T), inUserInterface: false); EntityEvents <T>?ee = (EntityEvents <T>?)entityEvents.TryGetC(typeof(T)); if (ee == null) { return(null); } FilterQueryResult <T>?result = null; foreach (var item in ee.OnFilterQuery()) { result = CombineFilterResult(result, item); } return(result); }
public IStatusGeneric Handle(EntityEvents callingEntity, OrderReadyToDispatchEvent domainEvent) { var status = new StatusGenericHandler(); //Update the rate as the date may have changed domainEvent.SetTaxRatePercent(_rateFinder.GetTaxRateInEffect(domainEvent.ActualDispatchDate)); var orderId = ((Order)callingEntity).OrderId; foreach (var lineItem in _context.LineItems.Where(x => x.OrderId == orderId)) { var stock = _context.Find <ProductStock>(lineItem.ProductName); if (stock.NumInStock < lineItem.NumOrdered) { return(status.AddError( $"I could not dispatch this order because there wasn't enough {lineItem.ProductName} in stock.")); } stock.NumAllocated -= lineItem.NumOrdered; stock.NumInStock -= lineItem.NumOrdered; } return(status); }
public Expression <Func <T, bool> >?GetInDatabaseFilter <T>() where T : Entity { EntityEvents <T>?ee = (EntityEvents <T>?)entityEvents.TryGetC(typeof(T)); if (ee == null) { return(null); } Expression <Func <T, bool> >?result = null; foreach (var item in ee.OnFilterQuery().NotNull()) { result = CombineExpr(result, item.InDatabaseExpresson); } if (result == null) { return(null); } return(result); }
public IStatusGeneric Handle(EntityEvents callingEntity, AuthorNameUpdatedEvent domainEvent) { //We go through all the books that have this author as one of its authors foreach (var bookWithEvents in _context.BookAuthors .Where(x => x.AuthorId == domainEvent.ChangedAuthor.AuthorId) .Select(x => x.Book)) { //For each book that has this author has its AuthorsOrdered string recomputed. var allAuthorsInOrder = _context.Set <BookWithEvents>() .Where(x => x.BookId == bookWithEvents.BookId) .Select(x => x.AuthorsLink.OrderBy(y => y.Order).Select(y => y.Author).ToList()) .Single(); //The database hasn't been updated yet, so we have to manually insert the new name into the correct point in the authorsOrdered var newAuthorsOrdered = string.Join(", ", allAuthorsInOrder.Select(x => x.AuthorId == domainEvent.ChangedAuthor.AuthorId ? domainEvent.ChangedAuthor.Name : x.Name)); bookWithEvents.AuthorsOrdered = newAuthorsOrdered; } return(null); }
//Updates all events linked to entities (damage animations, attack timers) protected void UpdateEvents() { EntityEvents.Update(); }
/// <summary> /// This allows you to create an exception with the callingEntity and domainEvent type names /// </summary> /// <param name="message"></param> /// <param name="callingEntity"></param> /// <param name="domainEvent"></param> public GenericEventRunnerException(string message, EntityEvents callingEntity, IDomainEvent domainEvent) : base(message) { Data.Add("CallingEntityType", callingEntity.GetType().FullName); Data.Add("DomainEventType", domainEvent.GetType().FullName); }
public EntityAndEvent(EntityEvents callingEntity, IDomainEvent domainEvent) { CallingEntity = callingEntity; DomainEvent = domainEvent; }
public abstract void Handle(EntityEvents callingEntity, IDomainEvent domainEvent);
public void Handle(EntityEvents callingEntity, EventTestAfterExceptionHandler domainEvent) { throw new ApplicationException(nameof(AfterHandlerThrowsException)); }
public void Handle(EntityEvents callingEntity, OrderReadyToDispatchEvent domainEvent) { //Send message to dispatch that order has been checked and is ready to go }
public IStatusGeneric Handle(EntityEvents callingEntity, EventCircularEvent domainEvent) { callingEntity.AddEvent(domainEvent); return(null); }
public override void Handle(EntityEvents callingEntity, IDomainEvent domainEvent) { _handler.Handle(callingEntity, (T)domainEvent); }
public IStatusGeneric Handle(EntityEvents callingEntity, EventTestBeforeReturnError domainEvent) { callingEntity.AddEvent(new EventDoNothing()); return(new StatusGenericHandler().AddError("This is a test")); }
public IStatusGeneric Handle(EntityEvents callingEntity, EventTestExceptionHandlerWithAttribute domainEvent) { throw new ApplicationException(nameof(BeforeHandlerThrowsExceptionWithAttribute)); }
public IStatusGeneric Handle(EntityEvents callingEntity, EventDoNothing domainEvent) { return(null); }
public abstract IStatusGeneric Handle(EntityEvents callingEntity, IDomainEvent domainEvent);
public IStatusGeneric Handle(EntityEvents callingEntity, EventTestBeforeExceptionHandler domainEvent) { throw new ApplicationException(nameof(BeforeHandlerThrowsException)); }
public override IStatusGeneric Handle(EntityEvents callingEntity, IDomainEvent domainEvent) { return(_handler.Handle(callingEntity, (T)domainEvent)); }