コード例 #1
0
    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);
        }
    }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public IStatusGeneric Handle(EntityEvents callingEntity, OrderCreatedEvent domainEvent)
        {
            var tax = _rateFinder.GetTaxRateInEffect(domainEvent.ExpectedDispatchDate);

            domainEvent.SetTaxRatePercent(tax);

            return(null);
        }
コード例 #5
0
        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());
        }
コード例 #6
0
    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);
    }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: BaseGameEvents.cs プロジェクト: wildrabbit/7drl-lib
 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();
 }
コード例 #9
0
    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));
    }
コード例 #10
0
    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)));
    }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
    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);
    }
コード例 #14
0
        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);
        }
コード例 #15
0
    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);
    }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: Map.cs プロジェクト: eldan-dex/randio
 //Updates all events linked to entities (damage animations, attack timers)
 protected void UpdateEvents()
 {
     EntityEvents.Update();
 }
コード例 #18
0
 /// <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);
 }
コード例 #19
0
 public EntityAndEvent(EntityEvents callingEntity, IDomainEvent domainEvent)
 {
     CallingEntity = callingEntity;
     DomainEvent   = domainEvent;
 }
コード例 #20
0
 public abstract void Handle(EntityEvents callingEntity, IDomainEvent domainEvent);
コード例 #21
0
 public void Handle(EntityEvents callingEntity, EventTestAfterExceptionHandler domainEvent)
 {
     throw new ApplicationException(nameof(AfterHandlerThrowsException));
 }
コード例 #22
0
 public void Handle(EntityEvents callingEntity, OrderReadyToDispatchEvent domainEvent)
 {
     //Send message to dispatch that order has been checked and is ready to go
 }
コード例 #23
0
 public IStatusGeneric Handle(EntityEvents callingEntity, EventCircularEvent domainEvent)
 {
     callingEntity.AddEvent(domainEvent);
     return(null);
 }
コード例 #24
0
 public override void Handle(EntityEvents callingEntity, IDomainEvent domainEvent)
 {
     _handler.Handle(callingEntity, (T)domainEvent);
 }
コード例 #25
0
 public IStatusGeneric Handle(EntityEvents callingEntity, EventTestBeforeReturnError domainEvent)
 {
     callingEntity.AddEvent(new EventDoNothing());
     return(new StatusGenericHandler().AddError("This is a test"));
 }
コード例 #26
0
 public IStatusGeneric Handle(EntityEvents callingEntity, EventTestExceptionHandlerWithAttribute domainEvent)
 {
     throw new ApplicationException(nameof(BeforeHandlerThrowsExceptionWithAttribute));
 }
コード例 #27
0
 public IStatusGeneric Handle(EntityEvents callingEntity, EventDoNothing domainEvent)
 {
     return(null);
 }
コード例 #28
0
 public abstract IStatusGeneric Handle(EntityEvents callingEntity, IDomainEvent domainEvent);
コード例 #29
0
 public IStatusGeneric Handle(EntityEvents callingEntity, EventTestBeforeExceptionHandler domainEvent)
 {
     throw new ApplicationException(nameof(BeforeHandlerThrowsException));
 }
コード例 #30
0
 public override IStatusGeneric Handle(EntityEvents callingEntity, IDomainEvent domainEvent)
 {
     return(_handler.Handle(callingEntity, (T)domainEvent));
 }