public NEventStoreServer(IPersistStreams persistStreams)
        {
            var bootstrapper = new NEventStoreBootstrapper(persistStreams);

            _owinEmbeddedHost =
                OwinEmbeddedHost.Create(app => app.UseNancy(options => options.Bootstrapper = bootstrapper));
        }
Пример #2
0
 private static IDispatchCommits BuildDispatcher(IPersistStreams persistence)
 {
     return new AsynchronousDispatcher(
         new DelegateMessagePublisher(DispatchCommit),
         persistence,
         OnDispatchError);
 }
Пример #3
0
        public PollingClientRx(IPersistStreams persistStreams, int pollingInterval = 1000, CancellationToken cancellationToken = default)
        {
            if (persistStreams == null)
            {
                throw new ArgumentNullException(nameof(persistStreams));
            }
            if (pollingInterval <= 0)
            {
                throw new ArgumentException("Must be greater than 0", nameof(pollingInterval));
            }

            _subject        = new Subject <ICommit>();
            _pollingClient2 = new PollingClient2(persistStreams, c =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    _subject.OnCompleted();
                    return(PollingClient2.HandlingResult.Stop);
                }

                _subject.OnNext(c);
                return(PollingClient2.HandlingResult.MoveToNext);
            },
                                                 waitInterval: pollingInterval);
        }
Пример #4
0
        public static Commit CommitSingle(this IPersistStreams persistence, string streamId = null)
        {
            Commit commit = (streamId ?? Guid.NewGuid().ToString()).BuildAttempt();

            persistence.Commit(commit);
            return(commit);
        }
Пример #5
0
 public PollingObserveCommits(IPersistStreams persistStreams, int interval, string bucketId, string checkpointToken = null)
 {
     _persistStreams = persistStreams;
     _checkpointToken = checkpointToken;
     _interval = interval;
     _bucketId = bucketId;
 }
        public AsynchronousDispatcher(IPublishMessages bus, IPersistStreams persistence)
        {
            this.bus = bus;
            this.persistence = persistence;

            this.Start();
        }
        public static Task <ICommit> CommitSingleAsync(
            this IPersistStreams persistence, string streamId, CancellationToken cancellationToken)
        {
            var commitAttempt = (streamId ?? Guid.NewGuid().ToString()).BuildAttempt();

            return(persistence.CommitAsync(commitAttempt, cancellationToken));
        }
Пример #8
0
        public static Commit CommitNext(this IPersistStreams persistence, Commit previous)
        {
            Commit commit = previous.BuildNextAttempt();

            persistence.Commit(commit);
            return(commit);
        }
Пример #9
0
        public ActivityProjector(
            IDbService dbService,
            IPersistStreams persistStreams,
            IEntryService entryService,
            IUserService userService,
            ILogger <ActivityProjector> logger,
            IOptions <Configuration> applicationConfiguration) : base(persistStreams, dbService)
        {
            var conventionalDispatcher = new ConventionBasedEventDispatcher(c => Checkpoint = c.ToSome(), commit => {
                logger.LogWarning($"Commit contains null events. CommitId:{commit.CommitId}, CommitSequence:{commit.CommitSequence}, StreamId:{commit.StreamId}, StreamRevision:{commit.StreamRevision}, EventCount:{commit.Events.Count}, AggregateId {commit.AggregateId()}");
            })
                                         .FirstProject <EntryCreated>(OnEntryCreated)
                                         .ThenProject <EntryUpdated>(OnEntryUpdated)
                                         .ThenProject <EntryRemoved>(OnEntryRemoved)
                                         .ThenProject <PlacementCreated>(OnPlacementCreated)
                                         .ThenProject <PlacementUpdated>(OnPlacementUpdated)
                                         .ThenProject <PlacementRemoved>(OnPlacementRemoved)
                                         .ThenProject <SkillSelfAssessmentCreated>(OnSelfAssessmentCreated)
                                         .ThenProject <SkillSelfAssessmentUpdated>(OnSelfAssessmentUpdated)
                                         .ThenProject <SkillSelfAssessmentRemoved>(OnSelfAssessmentRemoved)
                                         .ThenProject <EntryShared>(OnEntryShared)
                                         .ThenProject <EntryCollaboratorRemoved>(OnEntryCollaboratorRemoved)
                                         .ThenProject <EntryCommentCreated>(OnEntryCommentCreated);

            _conventionProjector      = new ConventionBasedCommitProjecter(this, dbService, conventionalDispatcher);
            _entryService             = entryService;
            _userService              = userService;
            _applicationConfiguration = applicationConfiguration;
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="persistStreams"></param>
        /// <param name="callback"></param>
        /// <param name="waitInterval">Interval in Milliseconds to wait when the provider
        /// return no more commit and the next request</param>
        public PollingClient2(IPersistStreams persistStreams, Func <ICommit, HandlingResult> callback, Int32 waitInterval = 100)
        {
            if (persistStreams == null)
            {
                throw new ArgumentNullException("PersistStreams cannot be null", "persistStreams");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("Cannot use polling client without callback", "callback");
            }

            _logger                      = LogFactory.BuildLogger(GetType());
            _waitInterval                = waitInterval;
            _pollingWakeUpTimer          = new System.Timers.Timer();
            _pollingWakeUpTimer.Elapsed += (sender, e) => WakeUpPoller();
            _pollingWakeUpTimer.Interval = _waitInterval;

            //Create polling thread
            _pollingThread = new Thread(InnerPollingLoop);
            _pollingThread.Start();

            _commitCallback        = callback;
            _persistStreams        = persistStreams;
            _lastActivityTimestamp = DateTime.UtcNow;
        }
Пример #11
0
        public SynchronousDispatcher(IPublishMessages bus, IPersistStreams persistence)
        {
            this.bus         = bus;
            this.persistence = persistence;

            this.Start();
        }
        public SynchronousDispatchScheduler(IDispatchCommits dispatcher, IPersistStreams persistence)
        {
            _dispatcher  = dispatcher;
            _persistence = persistence;

            Logger.Info(Resources.StartingDispatchScheduler);
        }
        public SynchronousDispatchScheduler(IDispatchCommits dispatcher, IPersistStreams persistence)
        {
            _dispatcher = dispatcher;
            _persistence = persistence;

            Logger.Info(Resources.StartingDispatchScheduler);
        }
 private static IDispatchCommits BuildDispatcher(IPersistStreams persistence, ILifetimeScope container)
 {
     return new AsynchronousDispatcher(
         new DelegateMessagePublisher(c => DispatchCommit(container, c)),
         persistence,
         OnDispatchError);
 }
        public static Task <ICommit> CommitNextAsync(
            this IPersistStreams persistence, CommitAttempt previous, CancellationToken cancellationToken)
        {
            var nextAttempt = previous.BuildNextAttempt();

            return(persistence.CommitAsync(nextAttempt, cancellationToken));
        }
Пример #16
0
        public static Task <ICommit> CommitSingle(this IPersistStreams persistence, string streamId = null, DateTime?now = null)
        {
            CommitAttempt commitAttempt = (streamId ?? Guid.NewGuid().ToString())
                                          .BuildAttempt(now: now);

            return(persistence.Commit(commitAttempt));
        }
Пример #17
0
        public EventUnwinder(
            ProjectionEngineConfig config,
            ILogger logger)
        {
            _config     = config;
            _logger     = logger;
            _eventStore = Wireup
                          .Init()
                          .LogTo(t => new NEventStoreLog4NetLogger(_logger))
                          .UsingMongoPersistence(() => _config.EventStoreConnectionString, new DocumentObjectSerializer())
                          .InitializeStorageEngine()
                          .Build();

            var url    = new MongoUrl(_config.EventStoreConnectionString);
            var client = new MongoClient(url);

            _mongoDatabase = client.GetDatabase(url.DatabaseName);

            _persistStream = _eventStore.Advanced;

            _unwindedEventCollection = _mongoDatabase.GetCollection <UnwindedDomainEvent>("UnwindedEvents");
            _unwindedEventCollection.Indexes.CreateOne(
                Builders <UnwindedDomainEvent> .IndexKeys
                .Ascending(ude => ude.CheckpointToken)
                .Ascending(ude => ude.EventSequence)
                .Ascending(ude => ude.EventType),
                new CreateIndexOptions()
            {
                Name = "ScanPrimary"
            }
                );
        }
Пример #18
0
 public PollingObserveCommits(IPersistStreams persistStreams, int interval, string bucketId, string checkpointToken = null)
 {
     _persistStreams  = persistStreams;
     _checkpointToken = checkpointToken;
     _interval        = interval;
     _bucketId        = bucketId;
 }
 public PipelineHooksAwarePersistanceDecorator(IPersistStreams original, IEnumerable<IPipelineHook> pipelineHooks)
 {
     if (original == null) throw new ArgumentNullException("original");
     if (pipelineHooks == null) throw new ArgumentNullException("pipelineHooks");
     this.original = original;
     this.pipelineHooks = pipelineHooks;
 }
 protected override void Context()
 {
     snapshot     = new Snapshot(streamId, 1, "Snapshot");
     persistence1 = Partitions.NewEventStoreWithPartition();
     persistence2 = Partitions.NewEventStoreWithPartition();
     persistence1.Commit(streamId.BuildAttempt());
 }
Пример #21
0
 /// <summary>
 /// Deletes a stream from the default bucket.
 /// </summary>
 /// <param name="persistStreams">The IPersistStreams instance.</param>
 /// <param name="streamId">The stream id to be deleted.</param>
 public static Task DeleteStream(this IPersistStreams persistStreams, string streamId)
 {
     if (persistStreams == null)
     {
         throw new ArgumentException("persistStreams is null");
     }
     return(persistStreams.DeleteStream(Bucket.Default, streamId));
 }
Пример #22
0
 /// <summary>
 ///     Gets all commits after from start checkpoint.
 /// </summary>
 /// <param name="persistStreams">The IPersistStreams instance.</param>
 public static IEnumerable <ICommit> GetFromStart(this IPersistStreams persistStreams)
 {
     if (persistStreams == null)
     {
         throw new ArgumentException("persistStreams is null");
     }
     return(persistStreams.GetFrom(null));
 }
Пример #23
0
 /// <summary>
 ///     Gets all commits on or after from the specified starting time from the default bucket.
 /// </summary>
 /// <param name="persistStreams">The IPersistStreams instance.</param>
 /// <param name="start">The point in time at which to start.</param>
 /// <returns>All commits that have occurred on or after the specified starting time.</returns>
 /// <exception cref="StorageException" />
 /// <exception cref="StorageUnavailableException" />
 public static IEnumerable <ICommit> GetFrom(this IPersistStreams persistStreams, DateTime start)
 {
     if (persistStreams == null)
     {
         throw new ArgumentException("persistStreams is null");
     }
     return(persistStreams.GetFrom(Bucket.Default, start));
 }
 public JoesBrowsableEventStore(IPersistStreams streamStore)
 {
     if (!(streamStore is IPersistStreamsWithAbsoluteOrdering))
     {
         throw new ArgumentException("The stream store must impement IPersistStreamsWithAbsoluteOrdering in order to be used with JoesBrowsableEventStore", "streamStore");
     }
     _streamStore = (IPersistStreamsWithAbsoluteOrdering)streamStore;
 }        
Пример #25
0
 /// <summary>
 ///     Gets all commits after from start checkpoint.
 /// </summary>
 /// <param name="persistStreams">The IPersistStreams instance.</param>
 public static IEnumerable <ICommit> GetFromStart(this IPersistStreams persistStreams)
 {
     if (persistStreams == null)
     {
         throw new ArgumentNullException(nameof(persistStreams));
     }
     return(persistStreams.GetFrom(0));
 }
        protected override void Context()
        {
            persistence1 = Partitions.NewEventStoreWithPartition();
            persistence2 = Partitions.NewEventStoreWithPartition();

            persistence1.Commit(streamId.BuildAttempt());
            persistence2.Commit(streamId.BuildAttempt());
        }
Пример #27
0
        public OptimisticEventStore(IPersistStreams persistence, IEnumerable<IPipelineHook> pipelineHooks)
        {
            if (persistence == null)
                throw new ArgumentNullException("persistence");

            this.persistence = persistence;
            this.pipelineHooks = pipelineHooks ?? new IPipelineHook[0];
        }
Пример #28
0
 public static IEnumerable <ICommit> GetFromTo(this IPersistStreams persistStreams, DateTime start, DateTime end)
 {
     if (persistStreams == null)
     {
         throw new ArgumentNullException(nameof(persistStreams));
     }
     return(persistStreams.GetFromTo(Bucket.Default, start, end));
 }
Пример #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="persistStreams">IPersistStreams Required for when the projector falls behind the head commit and needs to catchup</param>
 /// <param name="dbService"></param>
 public ProjectorBase(IPersistStreams persistStreams, IDbService dbService)
 {
     _persistStreams = persistStreams;
     _dbService      = dbService;
     ProjectorId     = this.GetProjectorId();
     Receive <CatchUpMessage>(msg => Received(msg));
     Receive <OrderedCommitNotification>(msg => Received(msg));
 }
Пример #30
0
 public JoesBrowsableEventStore(IPersistStreams streamStore)
 {
     if (!(streamStore is IPersistStreamsWithAbsoluteOrdering))
     {
         throw new ArgumentException("The stream store must impement IPersistStreamsWithAbsoluteOrdering in order to be used with JoesBrowsableEventStore", "streamStore");
     }
     _streamStore = (IPersistStreamsWithAbsoluteOrdering)streamStore;
 }
Пример #31
0
        public void Run(int maxEventsThreshold = 500)
        {
            log.Info("Rebuild snapshots. MaxEventsThreshold: " + maxEventsThreshold);
            IPersistStreams advanced = events.Advanced;
            var             ids      = advanced.GetStreamsToSnapshot(maxEventsThreshold).Select(e => new Guid(e.StreamId)).ToArray();

            ids.AsParallel().ForAll(MakeSnapshot);
        }
Пример #32
0
 /// <summary>
 /// Deletes a stream from the default bucket.
 /// </summary>
 /// <param name="persistStreams">The IPersistStreams instance.</param>
 /// <param name="streamId">The stream id to be deleted.</param>
 public static void DeleteStream(this IPersistStreams persistStreams, string streamId)
 {
     if (persistStreams == null)
     {
         throw new ArgumentNullException(nameof(persistStreams));
     }
     persistStreams.DeleteStream(Bucket.Default, streamId);
 }
Пример #33
0
        public AsynchronousDispatcher(
			IPublishMessages bus, IPersistStreams persistence, Action<Commit, Exception> handleException)
        {
            this.bus = bus;
            this.persistence = persistence;
            this.handleException = handleException ?? ((c, e) => { });

            this.Start();
        }
Пример #34
0
        public CommitFilterPersistence(
			IPersistStreams inner,
			IEnumerable<IFilterCommitReads> readFilter,
			IEnumerable<IFilterCommitWrites> writeFilter)
        {
            this.inner = inner;
            this.readFilters = readFilter ?? new IFilterCommitReads[0];
            this.writeFilters = writeFilter ?? new IFilterCommitWrites[0];
        }
Пример #35
0
        public BoundedContextModule(IPersistStreams persistStreams) : base("boundedcontexts")
        {
            Get["/", true] = async(_, __) =>
            {
                string[] strings = await persistStreams.GetBoundedContexts();

                return(Negotiate.WithModel(strings));
            };
        }
Пример #36
0
 public EventStoreClient(
     IPersistStreams persistStreams,
     int pollingIntervalMilliseconds = DefaultPollingInterval)
 {
     _persistStreams = persistStreams;
     _retrieveTimer = Observable
         .Interval(TimeSpan.FromMilliseconds(pollingIntervalMilliseconds))
         .Subscribe(_ => RetrieveNow());
 }
        /// <summary>
        /// Gets all commits after from start checkpoint.
        /// </summary>
        /// <param name="persistStreams">The IPersistStreams instance.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static Task <IEnumerable <ICommit> > GetFromStartAsync(this IPersistStreams persistStreams, CancellationToken cancellationToken)
        {
            if (persistStreams == null)
            {
                throw new ArgumentNullException(nameof(persistStreams));
            }

            return(persistStreams.GetFromAsync(0, cancellationToken));
        }
Пример #38
0
 public virtual PersistenceWireup WithPersistence(IPersistStreams instance)
 {
     if (Logger.IsInfoEnabled)
     {
         Logger.Info(Messages.RegisteringPersistenceEngine, instance.GetType());
     }
     With(instance);
     return(this);
 }
 public NEventStoreAdapter(IPersistStreams eventStore, int cacheSize, TimeSpan pollInterval, int maxPageSize,
                           Func <DateTime> getUtcNow)
 {
     this.eventStore   = eventStore;
     this.pollInterval = pollInterval;
     this.maxPageSize  = maxPageSize;
     this.getUtcNow    = getUtcNow;
     transactionCacheByPreviousCheckpoint = new LruCache <long, Transaction>(cacheSize);
 }
        protected override async Task Context()
        {
            _process1 = new AcceptanceTestMongoPersistenceFactory().Build();
            await _process1.Initialize();
            _commit1 = await _process1.Commit(Guid.NewGuid().ToString().BuildAttempt());

            _process2 = new AcceptanceTestMongoPersistenceFactory().Build();
            await _process2.Initialize();
        }
Пример #41
0
 public PollingObserveCommits(IPersistStreams persistStreams, int interval, string checkpointToken, ICommitEnhancer enhancer, bool boost, IConcurrentCheckpointTracker tracker)
 {
     _persistStreams  = persistStreams;
     _checkpointToken = checkpointToken;
     _enhancer        = enhancer;
     _interval        = interval;
     _boost           = boost;
     _tracker         = tracker;
 }
Пример #42
0
 public EventStoreClient(
     IPersistStreams persistStreams,
     int pollingIntervalMilliseconds = DefaultPollingInterval)
 {
     _persistStreams = persistStreams;
     _retrieveTimer  = Observable
                       .Interval(TimeSpan.FromMilliseconds(pollingIntervalMilliseconds))
                       .Subscribe(_ => RetrieveNow());
 }
        public OptimisticEventStore(IPersistStreams persistence, IEnumerable<IPipelineHook> pipelineHooks)
        {
            if (persistence == null)
            {
                throw new ArgumentNullException("persistence");
            }

            _pipelineHooks = pipelineHooks ?? new IPipelineHook[0];
            _persistence = new PipelineHooksAwarePersistanceDecorator(persistence, pipelineHooks);
        }
Пример #44
0
 public PollingClient(IPersistStreams persistStreams, int interval = 5000) : base(persistStreams)
 {
     if (persistStreams == null)
     {
         throw new ArgumentNullException("persistStreams");
     }
     if (interval <= 0)
     {
         throw new ArgumentException(Messages.MustBeGreaterThanZero.FormatWith("interval"));
     }
     _interval = interval;
 }
 public PerformanceCounterPersistenceEngine(IPersistStreams persistence, string instanceName)
 {
     _persistence = persistence;
     _counters = new PerformanceCounters(instanceName);
 }
Пример #46
0
 public EventStore(IPersistStreams persistence)
 {
     Guard.NotNull(() => persistence);
     this._persistence = persistence;
 }
 public InMemoryPersistenceEngineWithSerialization(ISerialize serializer)
 {
     this.underlying = new InMemoryPersistenceEngine();
     this.serializer = serializer;
 }
 public AsynchronousDispatchScheduler(IDispatchCommits dispatcher, IPersistStreams persistence)
     : base(dispatcher, persistence)
 {
     _queue = new BlockingCollection<ICommit>(new ConcurrentQueue<ICommit>(), BoundedCapacity);
 }
 public virtual PersistenceWireup WithPersistence(IPersistStreams instance)
 {
     Logger.Debug(Messages.RegisteringPersistenceEngine, instance.GetType());
     this.With(instance);
     return this;
 }
Пример #50
0
 public StoreEventsMock MockAdvanced(IPersistStreams advanced)
 {
     Advanced = advanced;
     return this;
 }
 public AsynchronousDispatchScheduler(IDispatchCommits dispatcher, IPersistStreams persistence)
     : base(dispatcher, persistence)
 {}
Пример #52
0
 public OptimisticEventStore(IPersistStreams persistence, IDispatchCommits dispatcher)
 {
     this.persistence = persistence;
     this.dispatcher = dispatcher;
 }
Пример #53
0
 protected ClientBase(IPersistStreams persistStreams)
 {
     _persistStreams = persistStreams;
 }
Пример #54
0
 public virtual PersistenceWireup WithPersistence(IPersistStreams instance)
 {
     this.With(instance);
     return this;
 }
Пример #55
0
 public OptimisticEventStore(IPersistStreams persistence, IEnumerable<IPipelineHook> pipelineHooks)
 {
     this.persistence = persistence;
     this.pipelineHooks = pipelineHooks ?? new IPipelineHook[0];
 }