Ejemplo n.º 1
0
        public IRepository GetRepository(string boundedContext)
        {
            var context = BoundedContexts.FirstOrDefault(bc => bc.Name == boundedContext);

            if (context == null)
            {
                throw new ArgumentException(string.Format("bound context {0} not found", boundedContext), "boundedContext");
            }
            return(context.EventStore.Repository);
        }
Ejemplo n.º 2
0
        internal void PublishEvent(object @event, string boundedContext, string route)
        {
            var context = BoundedContexts.FirstOrDefault(bc => bc.Name == boundedContext);

            if (context == null)
            {
                throw new ArgumentException(string.Format("bound context {0} not found", boundedContext), "boundedContext");
            }
            Endpoint endpoint = m_EndpointResolver.Resolve(context.LocalBoundedContext, boundedContext, route, @event.GetType(), RouteType.Events);

            PublishEvent(@event, endpoint, route);
        }
Ejemplo n.º 3
0
        public void SendCommand(object command, string boundedContext, CommandPriority priority = CommandPriority.Normal)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            var context = BoundedContexts.FirstOrDefault(bc => bc.Name == boundedContext);

            if (context == null)
            {
                throw new ArgumentException(string.Format("bound context {0} not found", boundedContext), "boundedContext");
            }
            string route;

            if (!context.CommandRoutes.TryGetValue(Tuple.Create(command.GetType(), priority), out route))
            {
                throw new InvalidOperationException(string.Format("bound context '{0}' does not support command '{1}' with priority {2}", boundedContext, command.GetType(), priority));
            }
            m_MessagingEngine.Send(command, m_EndpointResolver.Resolve(context.LocalBoundedContext, boundedContext, route, command.GetType(), RouteType.Commands), route);
        }
Ejemplo n.º 4
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                foreach (var boundedContext in BoundedContexts.Where(b => b != null))
                {
                    if (boundedContext.Processes != null)
                    {
                        foreach (var process in boundedContext.Processes)
                        {
                            process.Dispose();
                        }
                    }

                    boundedContext.Dispose();
                }

                if (m_Subscription != null)
                {
                    m_Subscription.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
        public void ReplayEvents(string boundedContext, params Type[] types)
        {
            var context = BoundedContexts.FirstOrDefault(bc => bc.Name == boundedContext);

            if (context == null)
            {
                throw new ArgumentException(string.Format("bound context {0} not found", boundedContext), "boundedContext");
            }
            string endpoint;

            if (!context.CommandRoutes.TryGetValue(Tuple.Create(typeof(ReplayEventsCommand), CommandPriority.Normal), out endpoint))
            {
                throw new InvalidOperationException(string.Format("bound context '{0}' does not support command '{1}' with priority {2}", boundedContext, typeof(ReplayEventsCommand), CommandPriority.Normal));
            }

            var ep = m_EndpointResolver.Resolve(context.LocalBoundedContext, boundedContext, endpoint, typeof(ReplayEventsCommand), RouteType.Commands);

            Destination tmpDestination;

            if (context.GetTempDestination(ep.TransportId, () => m_MessagingEngine.CreateTemporaryDestination(ep.TransportId, "EventReplay"), out tmpDestination))
            {
                var replayEndpoint = new Endpoint {
                    Destination = tmpDestination, SerializationFormat = ep.SerializationFormat, SharedDestination = true, TransportId = ep.TransportId
                };
                var knownEventTypes = context.EventsSubscriptions.SelectMany(e => e.Value).ToArray();
                m_Subscription.Add(m_MessagingEngine.Subscribe(
                                       replayEndpoint,
                                       (@event, acknowledge) => context.EventDispatcher.Dispacth(@event, acknowledge),
                                       (typeName, acknowledge) => { },
                                       "EventReplay",
                                       0,
                                       knownEventTypes));
            }
            SendCommand(new ReplayEventsCommand {
                Destination = tmpDestination.Publish, From = DateTime.MinValue, SerializationFormat = ep.SerializationFormat, Types = types
            }, boundedContext);
        }