public SqlStreamStoreSubscriptionSource(IStreamStore streamStore, StreamId streamId, ISerializer serializer) { _serializer = serializer; _streamId = streamId; _streamStore = streamStore; _log = LogProvider.For <SqlStreamStoreSubscriptionSource>(); }
public StreamCrawler(IStreamStore streamStore) { this.streamStore = streamStore; crawledStreams = new Dictionary <byte[], long>(ByteArrayEqualityComparer.Default); streamsToLoad = new Dictionary <byte[], long>(ByteArrayEqualityComparer.Default); stupidityCounter = 0; }
public static IApplicationBuilder UseSqlStreamStoreHal( this IApplicationBuilder builder, IStreamStore streamStore, SqlStreamStoreMiddlewareOptions options = default) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (streamStore == null) { throw new ArgumentNullException(nameof(streamStore)); } options = options ?? new SqlStreamStoreMiddlewareOptions(); return(builder .UseExceptionHandling() .Use(CaseSensitiveQueryStrings) .Use(AcceptHalJson) .Use(HeadRequests) .UseIndex() .Map("/stream", UseAllStream(streamStore, options)) .Map("/streams", UseStream(streamStore, options))); }
public async Task <IActionResult> Delete( [FromServices] AddressCrabEditClient editClient, [FromServices] IStreamStore streamStore, [FromServices] LegacyContext context, [FromRoute] string lokaleIdentificator, CancellationToken cancellationToken) { // TODO: Turn this into proper VBR API Validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var persistentLocalId = int.Parse(lokaleIdentificator); // todo: should become position from bus.Dispatch var position = await streamStore.ReadHeadPosition(cancellationToken); var addressId = context .CrabIdToPersistentLocalIds .SingleOrDefault(item => item.PersistentLocalId == persistentLocalId); CrabEditResponse deleteResponse = addressId != null ? await editClient.Delete(addressId, cancellationToken) : CrabEditResponse.NothingExecuted; return(AcceptedWithPosition( position, deleteResponse.ExecutionTime)); }
private static void DisplayMenu(IStreamStore streamStore, string url = null) { while (true) { Console.WriteLine("Press w to write 10 messages each to 100 streams"); Console.WriteLine("Press t to write 100 messages each to 10 streams"); Console.WriteLine("Press ESC to exit"); var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.Escape: return; case ConsoleKey.W: Write(streamStore, url, 10, 100); break; case ConsoleKey.T: Write(streamStore, url, 100, 10); break; default: Console.WriteLine("Computer says no"); break; } } }
private static Action <IApplicationBuilder> UseAllStream( IStreamStore streamStore, SqlStreamStoreMiddlewareOptions options) => builder => builder .MapWhen(IsOptions, inner => inner.UseAllStreamOptions(streamStore)) .UseReadAllStream(streamStore, options) .Use(MethodsNotAllowed("POST", "PUT", "DELETE", "TRACE", "PATCH"));
public CheckpointAwareProjector(IStreamStore streamStore, IMessageTypeMapper messageTypeMapper, CheckpointedProjector[] projections) { _streamStore = streamStore; _messageTypeMapper = messageTypeMapper; _projectors = projections; }
public static async Task WaitUntilAvailable(this IStreamStore store, ILogger <Program> logger, CancellationToken cancellationToken = default) { if (store is MsSqlStreamStore) { var watch = Stopwatch.StartNew(); var exit = false; while (!exit) { try { if (logger.IsEnabled(LogLevel.Information)) { logger.LogInformation($"Waiting until sql stream store becomes available ... ({watch.Elapsed:c})"); } await store.ReadHeadPosition(cancellationToken); exit = true; } catch (Exception exception) { if (logger.IsEnabled(LogLevel.Warning)) { logger.LogWarning(exception, "Encountered an exception while waiting for sql stream store to become available."); } await Task.Delay(1000, cancellationToken); } } } }
public RoadRegistryContext(EventSourcedEntityMap map, IStreamStore store, IRoadNetworkSnapshotReader snapshotReader, JsonSerializerSettings settings, EventMapping mapping) { RoadNetworks = new RoadNetworks(map, store, snapshotReader, settings, mapping); RoadNetworkChangesArchives = new RoadNetworkChangesArchives(map, store, settings, mapping); Organizations = new Organizations(map, store, settings, mapping); }
public StreamCrawler(IStreamStore streamStore) { this.streamStore = streamStore; crawledStreams = new Dictionary<byte[], long>(ByteArrayEqualityComparer.Default); streamsToLoad = new Dictionary<byte[], long>(ByteArrayEqualityComparer.Default); stupidityCounter = 0; }
protected override async Task ConnectAsync() { //Get subscription position _position = await _subscriptionManager.GetSubscriptionPosition(_subscriptionId, true); _store = await _storeProvider.GetStreamStore(); if (_streamId == null) { _allSubscription = _store.SubscribeToAll(_position, HandleSubscriptionEvent, HandleSubscriptionDropped); _status = SubscriptionConnectionStatus.Connected; _startDate = DateTime.UtcNow; } else { int?intPos = (_position != null) ? Convert.ToInt32(_position) : default(int?); _subscription = _store.SubscribeToStream(_streamId.Id, intPos, HandleSubscriptionEvent, HandleSubscriptionDropped); _status = SubscriptionConnectionStatus.Connected; _startDate = DateTime.UtcNow; } }
public DevServerStartup( IStreamStore streamStore, SqlStreamStoreMiddlewareOptions options) { _streamStore = streamStore; _options = options; }
/// <summary> /// Reads the stream from the end and goes back 1 event. This will get us the last version in the stream /// </summary> /// <param name="streamStore">The instance of <see cref="IStreamStore" /></param> /// <param name="streamId">The name of the stream to read</param> /// <param name="cancellationToken">Any <see cref="CancellationToken" /> to use to marshall the request</param> /// <returns>The last version in the stream</returns> public static async Task <int> GetLastVersionOfStream(this IStreamStore streamStore, string streamId, CancellationToken cancellationToken = default) { var streamResult = await GetLastVersionOfStream <object?>(streamStore, streamId, cancellationToken) .ConfigureAwait(false); return(streamResult.LastStreamVersion); }
public RoadNetworkEventModule(IStreamStore store, IRoadNetworkSnapshotReader snapshotReader, IRoadNetworkSnapshotWriter snapshotWriter, IClock clock) { if (store == null) { throw new ArgumentNullException(nameof(store)); } if (clock == null) { throw new ArgumentNullException(nameof(clock)); } if (snapshotReader == null) { throw new ArgumentNullException(nameof(snapshotReader)); } if (snapshotWriter == null) { throw new ArgumentNullException(nameof(snapshotWriter)); } For <CompletedRoadNetworkImport>() .UseRoadRegistryContext(store, snapshotReader, EnrichEvent.WithTime(clock)) .Handle(async(context, message, ct) => { var(network, version) = await context.RoadNetworks.GetWithVersion(ct); await snapshotWriter.WriteSnapshot(network.TakeSnapshot(), version, ct); }); }
public RoadNetworkChangesArchives(EventSourcedEntityMap map, IStreamStore store, JsonSerializerSettings settings, EventMapping mapping) { _map = map ?? throw new ArgumentNullException(nameof(map)); _store = store ?? throw new ArgumentNullException(nameof(store)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _mapping = mapping ?? throw new ArgumentNullException(nameof(mapping)); }
public UnitOfWorkImpl(Guid commitId, IStreamStore streamStore, Action complete) { _commitId = commitId; _streamStore = streamStore; _complete = complete; _aggregateRoots = new Dictionary <string, AggregateRoot>(); }
protected async Task <(IStreamStore, Action)> GetStore(CancellationToken cancellationToken) { IStreamStore streamStore = null; IDisposable disposable = null; Output.WriteLine(ConsoleColor.Yellow, "Store type:"); await new Menu() .AddSync("InMem", () => streamStore = new InMemoryStreamStore()) .Add("MS SQL V2 (Docker)", async _ => { var fixture = new MsSqlStreamStoreDb("dbo"); Console.WriteLine(fixture.ConnectionString); streamStore = await fixture.GetStreamStore(); disposable = fixture; }) .Add("MS SQL V3 (Docker)", async _ => { var fixture = new MsSqlStreamStoreDbV3("dbo"); Console.WriteLine(fixture.ConnectionString); streamStore = await fixture.GetStreamStore(); disposable = fixture; }) .AddSync("MS SQL V3 (LocalDB)", () => { var sqlLocalDb = new SqlLocalDb(); Console.WriteLine(sqlLocalDb.ConnectionString); streamStore = sqlLocalDb.StreamStore; disposable = sqlLocalDb; }) .Add("Postgres (Docker)", async ct => { var fixture = new PostgresStreamStoreDb("dbo"); Console.WriteLine(fixture.ConnectionString); streamStore = await fixture.GetPostgresStreamStore(true); disposable = fixture; }) .Add("Postgres (Server)", async ct => { Console.Write("Enter the connection string: "); var connectionString = Console.ReadLine(); var fixture = new PostgresStreamStoreDb("dbo", connectionString); Console.WriteLine(fixture.ConnectionString); streamStore = await fixture.GetPostgresStreamStore(true); disposable = fixture; }) .Display(cancellationToken); return( streamStore, () => { streamStore.Dispose(); disposable?.Dispose(); }); }
public DvrCodeGenerator( BackofficeContext context, IStreamStore streamStore) { _context = context; _streamStore = streamStore; }
public WebHooksRepository(IStreamStore streamStore, string name, GetUtcNow getUtcNow, int maxWebHookCount) { _streamStore = streamStore; _name = name; _getUtcNow = getUtcNow; _maxWebHookCount = maxWebHookCount; }
private static async Task GenerateMessages(IStreamStore store, int chunksCount, int chunkSize) { var dictStreamMessage = new Dictionary <string, NewStreamMessage>(); var random = new Random(); var messageJsonDataSize = 50 * 1024; for (int n = 0; n < chunksCount; n++) { var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < chunkSize; i++) //generate chunk of messages { string jsonData = $"message-{n * chunksCount + i}" + new string('m', random.Next(messageJsonDataSize)); var message = new NewStreamMessage(Guid.NewGuid(), jsonData, "{}", $"{i}"); var streamId = $"streamId{random.Next(n * chunksCount + i)}"; dictStreamMessage[streamId] = message; } //await -in-parallel await dictStreamMessage.ForEachAsync(chunkSize, async kvp => { await store.AppendToStream(kvp.Key, ExpectedVersion.Any, kvp.Value); }, t => { //will be called only if t.IsFaulted var exception = t.Exception; var errorMessage = $"Task {t.Id} failed " + exception?.GetBaseException().Message; throw new Exception(errorMessage, exception); }); Console.WriteLine($"Chunk number {n} saved. Elapsed {stopwatch.Elapsed} "); } }
private async Task <OpenStreamResult> GetFileStreamAsync(Context context, ContentHash hash) { Debug.Assert(_contentStoreByCacheName != null); // Iterate through all known stores, looking for content in each. // In most of our configurations there is just one store anyway, // and doing this means both we can callers don't have // to deal with cache roots and drive letters. foreach (KeyValuePair <string, IContentStore> entry in _contentStoreByCacheName) { IStreamStore store = entry.Value as IStreamStore; if (store != null) { OpenStreamResult result = await store.StreamContentAsync(context, hash); if (result.Code != OpenStreamResult.ResultCode.ContentNotFound) { return(result); } } } return(new OpenStreamResult(OpenStreamResult.ResultCode.ContentNotFound, $"{hash} to found")); }
public async Task <long> GetManyPagesAsync(IStreamStore store, int chunksCount, int batchSize) { long start = 0; //var events = new List<StreamMessage>(); for (int i = 0; i < chunksCount; i++) { var stopwatch = Stopwatch.StartNew(); var timesSlept = 0; bool moreThanPage = false; while (!moreThanPage) { var page = await store.ReadAllForwards(start, batchSize); if (page.IsEnd) { Thread.Sleep(10); timesSlept++; } else { start = page.NextPosition; moreThanPage = true; Console.WriteLine($"Page start from {start} read. Slept {timesSlept} times by 10ms.Elapsed {stopwatch.Elapsed}"); } } } return(start); }
public RepositoryScenarioBuilder() { _eventStore = new InMemoryStreamStore(() => DateTime.UtcNow); _unitOfWork = new UnitOfWork(); _eventStoreSchedule = new List <Action <IStreamStore> >(); _unitOfWorkSchedule = new List <Action <UnitOfWork> >(); }
/// <summary> /// Initializes a new instance of the <see cref="ShareLink"/> class. /// </summary> /// <param name="streamStore"> /// The stream store. /// </param> /// <param name="subscriptionStore"></param> public ShareLink(IStreamStore streamStore, SubscriptionStore subscriptionStore) { this.streamStore = streamStore; this.subscriptionStore = subscriptionStore; this.InitializeComponent(); this.viewModel = this.DataContext as ShareLinkViewModel; }
public SnapshotProcessor(IStreamStore streamStore, IServiceProvider serviceProvider, IOptions <StorageOptions> optionsAccessor) { if (streamStore == null) { throw new ArgumentNullException(nameof(streamStore)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (optionsAccessor == null) { throw new ArgumentNullException(nameof(optionsAccessor)); } _streamStore = streamStore; _serviceProvider = serviceProvider; _differ = new JsonDiffPatch(); _options = optionsAccessor.Value ?? new StorageOptions(); _snapshotProcess = new AsyncProcess(SnapshotProcess); _initialization = InitializeInternalAsync(_cancellationSource.Token); }
protected (IStreamStore, Action) GetStore() { IStreamStore streamStore = null; IDisposable disposable = null; Output.WriteLine(ConsoleColor.Yellow, "Store type:"); new Menu() .Add("InMem", () => streamStore = new InMemoryStreamStore()) .Add("MS SQL V2 (Docker)", () => { var fixture = new MsSqlStreamStoreFixture("dbo"); Console.WriteLine(fixture.ConnectionString); streamStore = fixture.GetStreamStore().Result; disposable = fixture; }) .Add("MS SQL V3 (Docker)", () => { var fixture = new MsSqlStreamStoreV3Fixture("dbo"); Console.WriteLine(fixture.ConnectionString); streamStore = fixture.GetStreamStore().Result; disposable = fixture; }) .Add("MS SQL V3 (LocalDB)", () => { var sqlLocalDb = new SqlLocalDb(); Console.WriteLine(sqlLocalDb.ConnectionString); streamStore = sqlLocalDb.StreamStore; disposable = sqlLocalDb; }) .Add("Postgres (Docker)", () => { var fixture = new PostgresStreamStoreFixture("dbo"); Console.WriteLine(fixture.ConnectionString); streamStore = fixture.GetPostgresStreamStore(true).Result; disposable = fixture; }) .Add("Postgres (Server)", () => { Console.Write("Enter the connection string: "); var connectionString = Console.ReadLine(); var fixture = new PostgresStreamStoreFixture("dbo", connectionString); Console.WriteLine(fixture.ConnectionString); streamStore = fixture.GetPostgresStreamStore(true).Result; disposable = fixture; }) .Display(); return( streamStore, () => { streamStore.Dispose(); disposable?.Dispose(); }); }
/// <summary> /// Initializes a new instance of the <see cref="NewStream"/> class. /// </summary> /// <param name="streamStore"> /// The stream Store. /// </param> /// <param name="accountStore"> /// The account Store. /// </param> public NewStream(IStreamStore streamStore, AccountStore accountStore) { this.streamStore = streamStore; this.accountStore = accountStore; this.InitializeComponent(); this.viewModel = this.DataContext as NewSlapStreamViewModel; }
public AllStreamMessageResource(IStreamStore streamStore) { if (streamStore == null) { throw new ArgumentNullException(nameof(streamStore)); } _streamStore = streamStore; }
public PurchaseOrderRepository(IStreamStore streamStore, string schema, Func <CancellationToken, Task <NpgsqlConnection> > connectionFactory) { _schema = schema; _connectionFactory = connectionFactory; _inner = new StreamStoreBusinessTransactionRepository <PurchaseOrder>(streamStore, order => GetStreamName(order.PurchaseOrderId), new JsonSerializerOptions()); }
private static async Task AppendMessages(IStreamStore streamStore, string streamId, int numberOfEvents) { for (int i = 0; i < numberOfEvents; i++) { var newmessage = new NewStreamMessage(Guid.NewGuid(), "MyEvent", "{}"); await streamStore.AppendToStream(streamId, ExpectedVersion.Any, newmessage); } }
public void SetUp() { _store = new InMemoryStreamStore(() => DateTime.UtcNow); _unitOfWork = new ConcurrentUnitOfWork(); _factory = AggregateRootEntityStub.Factory; _eventDeserializer = new EventDeserializer(SimpleJson.DeserializeObject); _eventMapping = new EventMapping(new Dictionary <string, Type>()); }
public SqlProjectionSubscription(IStreamStore store, ISqlProjection projection, SqlSubscriptionPersistence persistence) { _store = store; _projection = projection; _persistence = persistence; _lastReadPosition = persistence.InitialReadPosition; _runningLive = false; }
public ScenarioRunner(CommandHandlerResolver resolver, IStreamStore store, JsonSerializerSettings settings, EventMapping mapping, StreamNameConverter converter) { _resolver = resolver ?? throw new ArgumentNullException(nameof(resolver)); _store = store ?? throw new ArgumentNullException(nameof(store)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _mapping = mapping ?? throw new ArgumentNullException(nameof(mapping)); _converter = converter ?? throw new ArgumentNullException(nameof(converter)); }
/// <summary> /// Initializes a new instance of the <see cref="SMProtocol"/> class. /// </summary> /// <param name="uri">The URI.</param> /// <param name="streamsStore">The streams store.</param> internal SMProtocol(Uri uri, IStreamStore streamsStore) { this.streamsStore = streamsStore; this.webSocket = new WebSocket(uri.ToString()); this.webSocket.OnOpen += this.OnSocketOpen; this.webSocket.OnPing += this.OnSocketPing; this.webSocket.OnClose += this.OnSocketClose; this.serializer = new FrameSerializer(); this.builder = new FrameBuilder(); }
/// <summary> /// Initializes a new instance of the <see cref="ViewStream"/> class. /// </summary> /// <param name="streamStore"> /// The stream store. /// </param> /// <param name="accountStore"></param> public ViewStream(IStreamStore streamStore, AccountStore accountStore) { this.streamStore = streamStore; this.accountStore = accountStore; this.InitializeComponent(); this.viewModel = this.DataContext as ViewStreamViewModel; this.dataTransferManager = DataTransferManager.GetForCurrentView(); this.dataTransferManager.DataRequested += this.ShareStream; }
public RoomieEngine() { _engineState = EngineState.New; GlobalScope = new HierarchicalVariableScope(); DataStore = new DataStore(); StreamStore = new SafeWritingStreamStore(new BasicStreamStore()); ThreadPools = new List<ThreadPool>(); Threads = CreateThreadPool("Root Threads"); CommandLibrary = new RoomieCommandLibrary(); CommandLibrary.Message += CommandLibrary_Message; PrintCommandCalls = false; DevelopmentEnvironment = Environment.CurrentDirectory.EndsWith(@"\bin\Debug"); ArgumentTypes = new ArgumentTypeCollection(); }
/// <summary> /// Initializes a new instance of the <see cref="ShareLinkViewModel"/> class. /// </summary> /// <param name="subscriptionStore"> /// The subscription store. /// </param> /// <param name="streamStore"> /// The stream Store. /// </param> public ShareLinkViewModel(ISubscriptionStore subscriptionStore, IStreamStore streamStore) { this.streamStore = streamStore; this.Subscriptions = new ObservableCollection<SubscriptionViewModel>(); var subscriptions = subscriptionStore.GetSubsriptions(); var mappedSubscriptions = new List<SubscriptionViewModel>(); mappedSubscriptions = Mapper.Map(subscriptions, mappedSubscriptions); this.Subscriptions.AddRange(mappedSubscriptions); subscriptions.CollectionChanged += (sender, args) => { var newItems = new List<SubscriptionViewModel>(); newItems = Mapper.Map(args.NewItems, newItems); this.Subscriptions.AddRange(newItems); var oldItems = new List<SubscriptionViewModel>(); oldItems = Mapper.Map(args.NewItems, oldItems); this.Subscriptions.RemoveRange(oldItems); }; }
public DefaultStreamRepository(IStreamStore store) { this.store = store; }
public AppDataRepository(IStreamStore streamStore) { _streamStore = streamStore; }
public DefaultActivityRepository(IActivityStore store, IStreamStore streamStore) { this.store = store; this.streamStore = streamStore; }
internal Http2Protocol(SecureSocket socket, IStreamStore streamsStore, ProtocolOptions options) { this.options = options; this.streamsStore = streamsStore; this.serializer = new FrameSerializer(this.options); this.builder = new FrameBuilder(); this.socket = socket; this.isServer = true; this.handshakeFinishedEventRaised = new ManualResetEvent(false); }
/// <summary> /// Initializes a new instance of the <see cref="Http2Protocol"/> class. /// </summary> /// <param name="uri">The URI.</param> /// <param name="streamsStore">The streams store.</param> /// <param name="options">Protocol options</param> internal Http2Protocol(Uri uri, IStreamStore streamsStore, ProtocolOptions options) { this.options = options; this.streamsStore = streamsStore; this.serializer = new FrameSerializer(this.options); this.builder = new FrameBuilder(); this.uri = uri; this.isServer = false; this.handshakeFinishedEventRaised = new ManualResetEvent(false); }
/// <summary> /// Initializes a new instance of the <see cref="Http2Protocol"/> class. /// </summary> /// <param name="uri">The URI.</param> /// <param name="streamsStore">The streams store.</param> /// <param name="options">Protocol options</param> internal Http2Protocol(Uri uri, IStreamStore streamsStore, ProtocolOptions options) { this.options = options; this.streamsStore = streamsStore; this.serializer = new FrameSerializer(this.options); this.builder = new FrameBuilder(); this.uri = uri; }
/// <summary> /// Initializes a new instance of the <see cref="Http2Protocol"/> class. /// </summary> /// <param name="uri">The URI.</param> /// <param name="streamsStore">The streams store.</param> internal Http2Protocol(Uri uri, IStreamStore streamsStore) : this(uri, streamsStore, null) { }
public SafeWritingStreamStore(IStreamStore streamStore) { _streamStore = streamStore; }