/// <summary> /// Registers the given profiler with the event dispatcher, allowing you to aggregate timing information from the view subsystem /// </summary> public DependentViewManagerEventDispatcherSettings WithProfiler(IViewManagerProfiler profiler) { if (ViewManagerProfiler != null) { throw new InvalidOperationException(string.Format("Cannot register view profiler {0} because {1} has already been registered", profiler, ViewManagerProfiler)); } ViewManagerProfiler = profiler; return(this); }
public void SetProfiler(IViewManagerProfiler viewManagerProfiler) { if (viewManagerProfiler == null) { throw new ArgumentNullException("viewManagerProfiler"); } _logger.Info("Setting profiler: {0}", viewManagerProfiler); _viewManagerProfiler = viewManagerProfiler; }
/// <summary> /// Registers the given profiler with the event dispatcher, allowing you to aggregate timing information from the view subsystem /// </summary> public DependentViewManagerEventDispatcherSettings WithProfiler(IViewManagerProfiler profiler) { if (ViewManagerProfiler != null) { throw new InvalidOperationException(string.Format("Cannot register view profiler {0} because {1} has already been registered", profiler, ViewManagerProfiler)); } ViewManagerProfiler = profiler; return this; }
public void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { foreach (var e in batch) { _position = e.GetGlobalSequenceNumber(); Console.WriteLine("TestViewManager: position = {0}", _position); } }
public override void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { if (_purging) { return; } var cachedViewInstances = new Dictionary <string, TViewInstance>(); var eventList = batch.ToList(); if (!eventList.Any()) { return; } if (BatchDispatchEnabled) { var domainEventBatch = new DomainEventBatch(eventList); eventList.Clear(); eventList.Add(domainEventBatch); } foreach (var e in eventList) { if (!ViewLocator.IsRelevant <TViewInstance>(e)) { continue; } var stopwatch = Stopwatch.StartNew(); var viewIds = _viewLocator.GetAffectedViewIds(viewContext, e); foreach (var viewId in viewIds) { var viewInstance = cachedViewInstances[viewId] = GetOrCreateViewInstance(viewId, cachedViewInstances); _dispatcherHelper.DispatchToView(viewContext, e, viewInstance); } viewManagerProfiler.RegisterTimeSpent(this, e, stopwatch.Elapsed); } FlushCacheToDatabase(cachedViewInstances); RaiseUpdatedEventFor(cachedViewInstances.Values); UpdatePersistentCache(eventList.Max(e => e.GetGlobalSequenceNumber())); }
public void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { ReceivedDomainEvents.AddRange(batch); if (!batch.Any()) { return; } _position = batch.Max(e => e.GetGlobalSequenceNumber()); }
public override void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { if (_purging) { return; } var eventList = batch.ToList(); if (!eventList.Any()) { return; } if (BatchDispatchEnabled) { var domainEventBatch = new DomainEventBatch(eventList); eventList.Clear(); eventList.Add(domainEventBatch); } using (var session = _store.OpenSession()) { foreach (var e in eventList) { if (!ViewLocator.IsRelevant <TViewInstance>(e)) { continue; } var stopwatch = Stopwatch.StartNew(); var viewIds = _viewLocator.GetAffectedViewIds(viewContext, e); foreach (var viewId in viewIds) { var viewInstance = session.Load <TViewInstance>(viewId); if (viewInstance == null) { viewInstance = _dispatcherHelper.CreateNewInstance(viewId); session.Store(viewInstance); } _dispatcherHelper.DispatchToView(viewContext, e, viewInstance); } viewManagerProfiler.RegisterTimeSpent(this, e, stopwatch.Elapsed); } var position = session.Load <ViewPosition>(_viewPositionKey); if (position == null) { position = new ViewPosition { Id = _viewPositionKey }; session.Store(position); } position.Position = eventList.Max(e => e.GetGlobalSequenceNumber()); RaiseUpdatedEventFor(session.Advanced.ManagedEntities.OfType <TViewInstance>()); session.SaveChanges(); } }
public override void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { var eventList = batch.ToList(); if (!eventList.Any()) { return; } if (BatchDispatchEnabled) { var domainEventBatch = new DomainEventBatch(eventList); eventList.Clear(); eventList.Add(domainEventBatch); } var activeViewInstances = new Dictionary <string, TViewInstance>(); using (var context = GetContext()) { foreach (var e in eventList) { if (!ViewLocator.IsRelevant <TViewInstance>(e)) { continue; } var stopwatch = Stopwatch.StartNew(); var viewIds = _viewLocator.GetAffectedViewIds(viewContext, e); foreach (var viewId in viewIds) { var viewInstance = activeViewInstances.ContainsKey(viewId) ? activeViewInstances[viewId] : (activeViewInstances[viewId] = context.ViewCollection.FirstOrDefault(v => v.Id == viewId) ?? CreateAndAddNewViewInstance(viewId, context.ViewCollection)); _dispatcherHelper.DispatchToView(viewContext, e, viewInstance); } viewManagerProfiler.RegisterTimeSpent(this, e, stopwatch.Elapsed); } UpdatePersistentCache(context, eventList.Max(e => e.GetGlobalSequenceNumber())); context.SaveChanges(); } RaiseUpdatedEventFor(activeViewInstances.Values); }
public ViewManagerEventDispatcherConfiguationBuilder WithProfiler(IViewManagerProfiler profiler) { RegisterInstance(profiler); return(this); }
public override void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { var eventList = batch.ToList(); if (!eventList.Any()) { return; } var newPosition = eventList.Max(e => e.GetGlobalSequenceNumber()); using (var connection = GetConnection()) { using (var transaction = connection.BeginTransaction()) { var activeViewsById = new Dictionary <string, ActiveViewInstance>(); if (BatchDispatchEnabled) { var domainEventBatch = new DomainEventBatch(eventList); eventList.Clear(); eventList.Add(domainEventBatch); } foreach (var e in eventList) { if (!ViewLocator.IsRelevant <TViewInstance>(e)) { continue; } var stopwatch = Stopwatch.StartNew(); var viewIds = _viewLocator.GetAffectedViewIds(viewContext, e); foreach (var viewId in viewIds) { var view = activeViewsById .GetOrAdd(viewId, id => { var existing = FindOneById(id, connection, transaction); return(existing != null ? ActiveViewInstance.Existing(existing) : ActiveViewInstance.New(_dispatcher.CreateNewInstance(id))); }); _dispatcher.DispatchToView(viewContext, e, view.ViewInstance); } viewManagerProfiler.RegisterTimeSpent(this, e, stopwatch.Elapsed); } Save(activeViewsById, connection, transaction); RaiseUpdatedEventFor(activeViewsById.Values.Select(a => a.ViewInstance)); UpdatePosition(connection, transaction, newPosition); transaction.Commit(); } } }
public override void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { var eventList = batch.ToList(); if (!eventList.Any()) { return; } var newPosition = eventList.Max(e => e.GetGlobalSequenceNumber()); using (var conn = new SqlConnection(_connectionString)) { conn.Open(); using (var tx = conn.BeginTransaction()) { var activeViewsById = new Dictionary <string, TViewInstance>(); if (BatchDispatchEnabled) { var domainEventBatch = new DomainEventBatch(eventList); eventList.Clear(); eventList.Add(domainEventBatch); } foreach (var e in eventList) { if (!ViewLocator.IsRelevant <TViewInstance>(e)) { continue; } var stopwatch = Stopwatch.StartNew(); var viewIds = _viewLocator.GetAffectedViewIds(viewContext, e); foreach (var viewId in viewIds) { var view = activeViewsById .GetOrAdd(viewId, id => FindOneById(id, tx, conn) ?? _dispatcher.CreateNewInstance(viewId)); _dispatcher.DispatchToView(viewContext, e, view); } viewManagerProfiler.RegisterTimeSpent(this, e, stopwatch.Elapsed); } Save(activeViewsById, conn, tx); RaiseUpdatedEventFor(activeViewsById.Values); UpdatePosition(conn, tx, newPosition); tx.Commit(); } } Interlocked.Exchange(ref _cachedPosition, newPosition); }
public override void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { var updatedViews = new HashSet <TViewInstance>(); foreach (var e in batch) { if (ViewLocator.IsRelevant <TViewInstance>(e)) { var stopwatch = Stopwatch.StartNew(); var affectedViewIds = _viewLocator.GetAffectedViewIds(viewContext, e); foreach (var viewId in affectedViewIds) { var viewInstance = _views.GetOrAdd(viewId, id => _dispatcher.CreateNewInstance(id)); _dispatcher.DispatchToView(viewContext, e, viewInstance); updatedViews.Add(viewInstance); } viewManagerProfiler.RegisterTimeSpent(this, e, stopwatch.Elapsed); } Interlocked.Exchange(ref _position, e.GetGlobalSequenceNumber()); } RaiseUpdatedEventFor(updatedViews); }
public abstract void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler);
public void Dispatch(IViewContext viewContext, IEnumerable <DomainEvent> batch, IViewManagerProfiler viewManagerProfiler) { foreach (var e in batch) { _position = e.GetGlobalSequenceNumber(); } }