public TriggerService(ITriggerDiscoveryService triggerDiscoveryService, ICascadeStrategy cascadingStrategy, ILoggerFactory loggerFactory, IOptions <TriggerOptions> triggerOptions) { _triggerDiscoveryService = triggerDiscoveryService ?? throw new ArgumentNullException(nameof(triggerDiscoveryService)); _cascadingStrategy = cascadingStrategy ?? throw new ArgumentNullException(nameof(cascadingStrategy)); _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); _defaultConfiguration = new TriggerSessionConfiguration(false, triggerOptions.Value.MaxCascadeCycles); Configuration = _defaultConfiguration; }
public IEnumerable <IEnumerable <TriggerContextDescriptor> > Discover(TriggerSessionConfiguration configuration, TriggerContextTracker tracker, ILogger logger) { var changes = tracker.DiscoveredChanges ?? throw new InvalidOperationException("Trigger discovery process has not yet started. Please ensure that TriggerSession.DiscoverChanges() or TriggerSession.RaiseBeforeSaveTriggers() has been called"); if (logger.IsEnabled(LogLevel.Debug)) { _changesDetected(logger, changes.Count(), _name, null); } return(Enumerable.Repeat(changes, 1)); }
public IEnumerable <IEnumerable <TriggerContextDescriptor> > Discover(TriggerSessionConfiguration configuration, TriggerContextTracker tracker, ILogger logger) { var maxCascadingCycles = configuration.MaxCascadeCycles; _discoveryStarted(logger, _name, maxCascadingCycles, null); var iteration = 0; while (true) { if (iteration > maxCascadingCycles) { throw new InvalidOperationException("MaxCascadingCycle was reached"); } var changes = tracker.DiscoverChanges(); // In case someone made a call to TriggerSession.DetectChanges, prior to calling RaiseBeforeSaveTriggers, we want to make sure that we include that discovery result in the first iteration if (iteration == 0 && !_skipDetectedChanges) { changes = tracker.DiscoveredChanges !; } if (changes.Any()) { if (logger.IsEnabled(LogLevel.Debug)) { changes = changes.ToList(); _changesDetected(logger, changes.Count(), _name, iteration, maxCascadingCycles, null); } yield return(changes); } else { break; } iteration++; } }
public ITriggerSession CreateSession(DbContext context, TriggerSessionConfiguration configuration, IServiceProvider serviceProvider = null) => throw new NotImplementedException();