Example #1
0
 protected virtual IReaderStrategy CreateReaderStrategy(ITimeProvider timeProvider)
 {
     return(ReaderStrategy.Create(
                _name,
                0,
                _sourceDefinition,
                timeProvider,
                _projectionConfig.StopOnEof,
                _projectionConfig.RunAs));
 }
Example #2
0
 public IReaderStrategy Build(ITimeProvider timeProvider, IPrincipal runAs)
 {
     base.Validate();
     HashSet<string> categories = ToSet(_categories);
     HashSet<string> streams = ToSet(_streams);
     bool includeLinks = _options.IncludeLinks;
     HashSet<string> events = ToSet(_events);
     bool reorderEvents = _options.ReorderEvents;
     int processingLag = _options.ProcessingLag;
     var readerStrategy = new ReaderStrategy(
         _allStreams, categories, streams, _allEvents, includeLinks, events, processingLag, reorderEvents,
         runAs, timeProvider);
     return readerStrategy;
 }
Example #3
0
            public IReaderStrategy Build(ITimeProvider timeProvider, IPrincipal runAs)
            {
                base.Validate();
                HashSet <string> categories    = ToSet(_categories);
                HashSet <string> streams       = ToSet(_streams);
                bool             includeLinks  = _options.IncludeLinks;
                HashSet <string> events        = ToSet(_events);
                bool             reorderEvents = _options.ReorderEvents;
                int processingLag  = _options.ProcessingLag;
                var readerStrategy = new ReaderStrategy(
                    _allStreams, categories, streams, _allEvents, includeLinks, events, processingLag, reorderEvents,
                    runAs, timeProvider);

                return(readerStrategy);
            }
        public static IReaderStrategy Create(int phase, IQuerySources sources, ITimeProvider timeProvider, bool stopOnEof, IPrincipal runAs)
        {
            if (!sources.AllStreams && !sources.HasCategories() && !sources.HasStreams()
                && string.IsNullOrEmpty(sources.CatalogStream))
                throw new InvalidOperationException("None of streams and categories are included");
            if (!sources.AllEvents && !sources.HasEvents())
                throw new InvalidOperationException("None of events are included");
            if (sources.HasStreams() && sources.HasCategories())
                throw new InvalidOperationException(
                    "Streams and categories cannot be included in a filter at the same time");
            if (sources.AllStreams && (sources.HasCategories() || sources.HasStreams()))
                throw new InvalidOperationException("Both FromAll and specific categories/streams cannot be set");
            if (sources.AllEvents && sources.HasEvents())
                throw new InvalidOperationException("Both AllEvents and specific event filters cannot be set");

            if (sources.ByStreams && sources.HasStreams())
                throw new InvalidOperationException("foreachStream projections are not supported on stream based sources");

            if ((sources.HasStreams() || sources.AllStreams) && !string.IsNullOrEmpty(sources.CatalogStream))
                throw new InvalidOperationException("catalogStream cannot be used with streams or allStreams");

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !sources.ByStreams)
                throw new InvalidOperationException("catalogStream is only supported in the byStream mode");

            if (sources.ReorderEventsOption)
            {
                if (!string.IsNullOrEmpty(sources.CatalogStream))
                    throw new InvalidOperationException("Event reordering cannot be used with stream catalogs");
                if (sources.AllStreams)
                    throw new InvalidOperationException("Event reordering cannot be used with fromAll()");
                if (!(sources.HasStreams() && sources.Streams.Length > 1))
                {
                    throw new InvalidOperationException(
                        "Event reordering is only available in fromStreams([]) projections");
                }
                if (sources.ProcessingLagOption < 50)
                    throw new InvalidOperationException("Event reordering requires processing lag at least of 50ms");
            }

            var readerStrategy = new ReaderStrategy(
                phase, sources.AllStreams, sources.Categories, sources.Streams, sources.AllEvents,
                sources.IncludeLinksOption, sources.Events, sources.CatalogStream, sources.ProcessingLagOption,
                sources.ReorderEventsOption, runAs, timeProvider);
            return readerStrategy;
        }
Example #5
0
        public static IReaderStrategy Create(
            string tag,
            int phase,
            IQuerySources sources,
            ITimeProvider timeProvider,
            bool stopOnEof,
            IPrincipal runAs)
        {
            if (!sources.AllStreams && !sources.HasCategories() && !sources.HasStreams() &&
                string.IsNullOrEmpty(sources.CatalogStream))
            {
                throw new InvalidOperationException("None of streams and categories are included");
            }
            if (!sources.AllEvents && !sources.HasEvents())
            {
                throw new InvalidOperationException("None of events are included");
            }
            if (sources.HasStreams() && sources.HasCategories())
            {
                throw new InvalidOperationException(
                          "Streams and categories cannot be included in a filter at the same time");
            }
            if (sources.AllStreams && (sources.HasCategories() || sources.HasStreams()))
            {
                throw new InvalidOperationException("Both FromAll and specific categories/streams cannot be set");
            }
            if (sources.AllEvents && sources.HasEvents())
            {
                throw new InvalidOperationException("Both AllEvents and specific event filters cannot be set");
            }

            if (sources.ByStreams && sources.HasStreams())
            {
                throw new InvalidOperationException(
                          "foreachStream projections are not supported on stream based sources");
            }

            if ((sources.HasStreams() || sources.AllStreams) && !string.IsNullOrEmpty(sources.CatalogStream))
            {
                throw new InvalidOperationException("catalogStream cannot be used with streams or allStreams");
            }

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !sources.ByStreams)
            {
                throw new InvalidOperationException("catalogStream is only supported in the byStream mode");
            }

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !stopOnEof)
            {
                throw new InvalidOperationException("catalogStream is not supported in the projections mode");
            }

            if (sources.ReorderEventsOption)
            {
                if (!string.IsNullOrEmpty(sources.CatalogStream))
                {
                    throw new InvalidOperationException("Event reordering cannot be used with stream catalogs");
                }
                if (sources.AllStreams)
                {
                    throw new InvalidOperationException("Event reordering cannot be used with fromAll()");
                }
                if (!(sources.HasStreams() && sources.Streams.Length > 1))
                {
                    throw new InvalidOperationException(
                              "Event reordering is only available in fromStreams([]) projections");
                }
                if (sources.ProcessingLagOption < 50)
                {
                    throw new InvalidOperationException("Event reordering requires processing lag at least of 50ms");
                }
            }

            if (sources.HandlesDeletedNotifications && !sources.ByStreams)
            {
                throw new InvalidOperationException(
                          "Deleted stream notifications are only supported with foreachStream()");
            }

            var readerStrategy = new ReaderStrategy(
                tag,
                phase,
                sources.AllStreams,
                sources.Categories,
                sources.Streams,
                sources.AllEvents,
                sources.IncludeLinksOption,
                sources.Events,
                sources.HandlesDeletedNotifications,
                sources.CatalogStream,
                sources.ProcessingLagOption,
                sources.ReorderEventsOption,
                runAs,
                timeProvider);

            return(readerStrategy);
        }