Beispiel #1
0
        public Task Invoke(HttpContext context, IEventTypeFinder eventTypeFinder)
        {
            if (js == null)
            {
                RenderScript(eventTypeFinder.ListEventsTypes());
            }

            var response = context.Response;

            response.ContentType = "application/javascript";
            response.StatusCode  = 200;

            if (ClientCached(context.Request, scriptBuildDate))
            {
                response.StatusCode = 304;
                response.Headers["Content-Length"] = "0";
                response.Body.Close();
                response.Body = Stream.Null;

                return(Task.CompletedTask);
            }

            response.Headers["Last-Modified"] = scriptBuildDate.ToString("r");
            response.Headers["Cache-Control"] = "must-revalidate";
            return(response.WriteAsync(js));
        }
Beispiel #2
0
        public TypeFinder(IAssemblyLocator assemblyLocator, IEventTypeFinder eventTypeFinder)
        {
            this.assemblyLocator = assemblyLocator;
            types = new Dictionary <string, Type>();

            var eventTypes = eventTypeFinder
                             .ListEventsTypes();

            eventTypeLookup = eventTypes
                              .ToDictionary(t => t.GetFullNameWihoutGenerics(), t => t);

            var lookupType = typeof(IEventConstraintHandler <>);
            var predicate  = new Func <Type, bool>(t => t.IsGenericType && t.GetGenericTypeDefinition() == lookupType);

            var lookup = assemblyLocator
                         .GetAssemblies()
                         .SelectMany(GetTypesSafely)
                         .Where(t => t.GetInterfaces().Any(predicate))
                         .Select(t => new { Handler = t, Type = t.GetInterfaces().First(predicate).GetGenericArguments()[0] })
                         .GroupBy(t => t.Type)
                         .ToDictionary(g => g.Key, g => g.Select(t => t.Handler));

            constraintHandlerTypes = eventTypes
                                     .SelectMany(ListInheritanceChange)
                                     .Distinct()
                                     .ToDictionary(type => type, type => lookup
                                                   .Where(kvp => kvp.Key.IsAssignableFrom(type))
                                                   .SelectMany(kvp => kvp.Value)
                                                   .ToList() as IEnumerable <Type>);
        }
Beispiel #3
0
 public ObserverUnit(IServiceProvider serviceProvider, Type eventHandlerType)
 {
     this.serviceProvider = serviceProvider;
     serializer           = serviceProvider.GetService <ISerializer>();
     typeFinder           = serviceProvider.GetService <IEventTypeFinder>();
     Logger           = serviceProvider.GetService <ILogger <ObserverUnit <PrimaryKey> > >();
     EventHandlerType = eventHandlerType;
 }
Beispiel #4
0
 public Bus(IServiceProvider serviceProvider, IEventTypeFinder eventTypeFinder, ISerializer serializer, ISnowflakeIdGenerator snowflakeIdGenerator, IEventStorage eventStorage)
 {
     ServiceProvider           = serviceProvider;
     this.eventTypeFinder      = eventTypeFinder;
     this.serializer           = serializer;
     this.snowflakeIdGenerator = snowflakeIdGenerator;
     this.eventStorage         = eventStorage;
 }
        public TypeFinder(IEventTypeFinder eventTypeFinder)
        {
            eventTypes      = eventTypeFinder.ListEventsTypes().ToList();
            eventTypeLookup = eventTypes
                              .ToDictionary(t => t.GetFullNameWihoutGenerics(), t => t);

            types            = new Dictionary <string, Type>();
            subscriberLookup = new Dictionary <Type, IEnumerable <Type> >();
        }
Beispiel #6
0
 public UnitOfWork(IProducerInfoContainer producerContainer, IEventTypeFinder eventTypeFinder,
                   ISerializer serializer, IEventBuffer eventBuffer, IServiceProvider serviceProvider)
 {
     this.producerContainer = producerContainer;
     this.eventTypeFinder   = eventTypeFinder;
     this.serializer        = serializer;
     this.eventBuffer       = eventBuffer;
     this.ServiceProvider   = serviceProvider;
 }
        public TypeFinder(IAssemblyLocator assemblyLocator, IEventTypeFinder eventTypeFinder)
        {
            this.assemblyLocator = assemblyLocator;
            types = new Dictionary <string, Type>();

            eventTypes = eventTypeFinder
                         .ListEventsTypes()
                         .ToDictionary(t => t.GetFullNameWihoutGenerics(), t => t);
            InitConstraintHandlerTypes();
        }
Beispiel #8
0
 public BacketController(IClusterClient clusterClient, ILogger <BacketController> logger, IProducerInfoContainer producerContainer,
                         IEventTypeFinder eventTypeFinder, ISerializer serializer, ISnowflakeIdGenerator snowflakeIdGenerator, IEventBuffer eventBuffer, IServiceProvider serviceProvider)
 {
     this.clusterClient        = clusterClient;
     this.logger               = logger;
     this.producerContainer    = producerContainer;
     this.eventTypeFinder      = eventTypeFinder;
     this.serializer           = serializer;
     this.snowflakeIdGenerator = snowflakeIdGenerator;
     this.eventBuffer          = eventBuffer;
     this.serviceProvider      = serviceProvider;
 }
Beispiel #9
0
        public async Task Invoke(EventBytesTransport transport, ISerializer serializer, IEventTypeFinder eventTypeFinder, ILogger logger, Type eventHandlerType)
        {
            var eventType = eventTypeFinder.FindType(transport.EventTypeCode);
            var @event    = (TEvent)serializer.Deserialize(transport.EventBytes, eventType);

            if (this is IPoleEventHandler <TEvent> handler)
            {
                var   handleTasks = handler.EventHandle(@event);
                await handleTasks;
                logger.LogTrace("Invoke completed: {0}->{1}->{2}", eventHandlerType.FullName, nameof(handler.EventHandle), serializer.Serialize(@event));
                return;
            }
            else
            {
                throw new EventHandlerImplementedNotRightException(nameof(handler.EventHandle), eventType.Name, this.GetType().FullName);
            }
        }