public CosmosDbEventStoreFixture() { client = new DocumentClient(new Uri(EmulatorUri), EmulatorKey, TestUtils.DefaultSettings()); EventStore = new CosmosDbEventStore(client, EmulatorKey, "Test", TestUtils.DefaultSettings()); EventStore.InitializeAsync().Wait(); }
public CosmosDbSubscription(CosmosDbEventStore store, IEventSubscriber subscriber, string streamFilter, string position = null) { this.store = store; var fromBeginning = string.IsNullOrWhiteSpace(position); if (fromBeginning) { hostName = $"squidex.{DateTime.UtcNow.Ticks.ToString()}"; } else { hostName = position; } if (!StreamFilter.IsAll(streamFilter)) { regex = new Regex(streamFilter); } this.subscriber = subscriber; processorTask = Task.Run(async() => { try { Collection CreateCollection(string name) { var collection = new Collection(); collection.CollectionName = name; collection.DatabaseName = store.DatabaseId; collection.MasterKey = store.MasterKey; collection.Uri = store.ServiceUri; return(collection); } var processor = await new Builder() .WithFeedCollection(CreateCollection(Constants.Collection)) .WithLeaseCollection(CreateCollection(Constants.LeaseCollection)) .WithHostName(hostName) .WithProcessorOptions(new Options { StartFromBeginning = fromBeginning, LeasePrefix = hostName }) .WithObserverFactory(this) .BuildAsync(); await processor.StartAsync(); await processorStopRequested.Task; await processor.StopAsync(); } catch (Exception ex) { await subscriber.OnErrorAsync(this, ex); } }); }
private static Collection CreateCollection(CosmosDbEventStore store, string name) { var collection = new Collection(); collection.CollectionName = name; collection.DatabaseName = store.DatabaseId; collection.MasterKey = store.MasterKey; collection.Uri = store.ServiceUri; return(collection); }
public CosmosDbSubscription(CosmosDbEventStore store, IEventSubscriber subscriber, string?streamFilter, string?position = null) { this.store = store; var fromBeginning = string.IsNullOrWhiteSpace(position); if (fromBeginning) { hostName = $"squidex.{DateTime.UtcNow.Ticks}"; } else { hostName = position ?? "none"; } if (!StreamFilter.IsAll(streamFilter)) { regex = new Regex(streamFilter); } this.subscriber = subscriber; Task.Run(async() => { try { var processor = await new Builder() .WithFeedCollection(CreateCollection(store, Constants.Collection)) .WithLeaseCollection(CreateCollection(store, Constants.LeaseCollection)) .WithHostName(hostName) .WithProcessorOptions(new Options { StartFromBeginning = fromBeginning, LeasePrefix = hostName }) .WithObserverFactory(this) .BuildAsync(); await processor.StartAsync(); await processorStopRequested.Task; await processor.StopAsync(); } catch (Exception ex) { await subscriber.OnErrorAsync(this, ex); } }); }