internal CosmosStore(ICosmonautClient cosmonautClient, string databaseName, string overriddenCollectionName, IDatabaseCreator databaseCreator = null, ICollectionCreator collectionCreator = null, bool scaleable = false) { CollectionName = overriddenCollectionName; DatabaseName = databaseName; CosmonautClient = cosmonautClient ?? throw new ArgumentNullException(nameof(cosmonautClient)); Settings = new CosmosStoreSettings(databaseName, cosmonautClient.DocumentClient.ServiceEndpoint.ToString(), string.Empty, cosmonautClient.DocumentClient.ConnectionPolicy, scaleCollectionRUsAutomatically: scaleable); if (Settings.InfiniteRetries) { CosmonautClient.DocumentClient.SetupInfiniteRetries(); } if (string.IsNullOrEmpty(Settings.DatabaseName)) { throw new ArgumentNullException(nameof(Settings.DatabaseName)); } _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(CosmonautClient); _databaseCreator = databaseCreator ?? new CosmosDatabaseCreator(CosmonautClient); _cosmosScaler = new CosmosScaler <TEntity>(this); InitialiseCosmosStore(); }
public Train GetTrainDetails(int trainId) { ICollectionCreator cc = _cf.CreateCollection(); var mTrain = cc.Trains.Find(new BsonDocument("TrainId", trainId)).FirstOrDefault(); Train train = new Train() { Carriages = mTrain.Carriages, StartLocation = mTrain.StartLocation, EndLocation = mTrain.EndLocation, Id = mTrain.TrainId, Number = mTrain.Number }; foreach (var car in train.Carriages) { car.Train = train; foreach (var place in car.Places) { place.Carriage = car; } } ; return(train); }
internal CosmosStore(IDocumentClient documentClient, string databaseName, string authKey, string endpoint, string overriddenCollectionName, IDatabaseCreator databaseCreator = null, ICollectionCreator collectionCreator = null, bool scaleable = false) { CollectionName = overriddenCollectionName; DatabaseName = databaseName; if (documentClient == null) { throw new ArgumentNullException(nameof(documentClient)); } var cosmonautClient = new CosmonautClient(documentClient); Settings = new CosmosStoreSettings(databaseName, endpoint, authKey, documentClient.ConnectionPolicy, scaleCollectionRUsAutomatically: scaleable); if (string.IsNullOrEmpty(Settings.DatabaseName)) { throw new ArgumentNullException(nameof(Settings.DatabaseName)); } _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(cosmonautClient); _databaseCreator = databaseCreator ?? new CosmosDatabaseCreator(cosmonautClient); _cosmosScaler = new CosmosScaler <TEntity>(this); InitialiseCosmosStore(); }
public static IServiceCollection AddCosmosStore <TEntity>(this IServiceCollection services, IDocumentClient documentClient, string databaseName, IDatabaseCreator databaseCreator, ICollectionCreator collectionCreator) where TEntity : class { services.AddSingleton <ICosmosStore <TEntity> >(x => new CosmosStore <TEntity>(documentClient, databaseName, databaseCreator, collectionCreator)); return(services); }
public List <Train> GetAllTrains() { ICollectionCreator cc = _cf.CreateCollection(); return(cc.Trains.Find(train => true).ToList().Select(mt => new Train() { Carriages = mt.Carriages, StartLocation = mt.StartLocation, EndLocation = mt.EndLocation, Id = mt.TrainId, Number = mt.Number }).ToList()); }
public void UpdateTrain(Train train) { ICollectionCreator cc = _cf.CreateCollection(); MongoTrain mTrain = new MongoTrain() { Carriages = train.Carriages, StartLocation = train.StartLocation, EndLocation = train.EndLocation, TrainId = train.Id, Number = train.Number }; cc.Trains.ReplaceOneAsync(new BsonDocument("_id", train.Id), mTrain); }
public void CreateTrain(Train train) { ICollectionCreator cc = _cf.CreateCollection(); MongoTrain mTrain = new MongoTrain { Carriages = train.Carriages, StartLocation = train.StartLocation, EndLocation = train.EndLocation, TrainId = train.Id, Number = train.Number }; cc.Trains.InsertOne(mTrain); }
internal CosmosStore(IDocumentClient documentClient, string databaseName, IDatabaseCreator databaseCreator, ICollectionCreator collectionCreator) { DocumentClient = documentClient ?? throw new ArgumentNullException(nameof(documentClient)); Settings = new CosmosStoreSettings(databaseName, documentClient.ServiceEndpoint, documentClient.AuthKey.ToString(), documentClient.ConnectionPolicy); if (string.IsNullOrEmpty(Settings.DatabaseName)) { throw new ArgumentNullException(nameof(Settings.DatabaseName)); } _databaseCreator = databaseCreator ?? throw new ArgumentNullException(nameof(databaseCreator)); _collectionCreator = collectionCreator ?? throw new ArgumentNullException(nameof(collectionCreator)); InitialiseCosmosStore(); }
public CosmosStore(CosmosStoreSettings settings, string overriddenCollectionName) { Settings = settings ?? throw new ArgumentNullException(nameof(settings)); DatabaseName = settings.DatabaseName; var documentClient = DocumentClientFactory.CreateDocumentClient(settings); CosmonautClient = new CosmonautClient(documentClient, Settings.InfiniteRetries); if (string.IsNullOrEmpty(Settings.DatabaseName)) { throw new ArgumentNullException(nameof(Settings.DatabaseName)); } _collectionCreator = new CosmosCollectionCreator(CosmonautClient); _databaseCreator = new CosmosDatabaseCreator(CosmonautClient); InitialiseCosmosStore(overriddenCollectionName); }
public CosmosStore(CosmosStoreSettings settings, IDatabaseCreator databaseCreator, ICollectionCreator collectionCreator) { Settings = settings ?? throw new ArgumentNullException(nameof(settings)); var endpointUrl = Settings.EndpointUrl ?? throw new ArgumentNullException(nameof(Settings.EndpointUrl)); var authKey = Settings.AuthKey ?? throw new ArgumentNullException(nameof(Settings.AuthKey)); DocumentClient = DocumentClientFactory.CreateDocumentClient(endpointUrl, authKey); if (string.IsNullOrEmpty(Settings.DatabaseName)) { throw new ArgumentNullException(nameof(Settings.DatabaseName)); } _collectionCreator = collectionCreator ?? throw new ArgumentNullException(nameof(collectionCreator)); _databaseCreator = databaseCreator ?? throw new ArgumentNullException(nameof(databaseCreator)); InitialiseCosmosStore(); }
public MongoCollectionResolver([NotNull] ICacheKeyFactory cacheKeyFactory, [NotNull] ICollectionCreator collectionCreator, [NotNull] IMongoDatabaseFactory mongoDatabaseFactory) { if (cacheKeyFactory == null) { throw new ArgumentNullException(nameof(cacheKeyFactory)); } if (collectionCreator == null) { throw new ArgumentNullException(nameof(collectionCreator)); } if (mongoDatabaseFactory == null) { throw new ArgumentNullException(nameof(mongoDatabaseFactory)); } _cacheKeyFactory = cacheKeyFactory; _collectionCreator = collectionCreator; _mongoDatabaseFactory = mongoDatabaseFactory; }
public QueueListener( IMessageTypesCache messageTypesCache, IMessagingLogger messagingLogger, UnprocessedMessagesResender unprocessedMessagesResender, IMessagingConfiguration messagingConfiguration, IListeningAgent listeningAgent, IDocumentMappingInitializer documentMappingInitializer, ISubscriptionAgent subscriptionAgent, ICollectionCreator collectionCreator ) { _messageTypesCache = messageTypesCache; _messagingLogger = messagingLogger; _unprocessedMessagesResender = unprocessedMessagesResender; _messagingConfiguration = messagingConfiguration; _listeningAgent = listeningAgent; _documentMappingInitializer = documentMappingInitializer; _subscriptionAgent = subscriptionAgent; _collectionCreator = collectionCreator; }
internal CosmosStore(ICosmonautClient cosmonautClient, string databaseName, string overriddenCollectionName, IDatabaseCreator databaseCreator = null, ICollectionCreator collectionCreator = null) { DatabaseName = databaseName; CosmonautClient = cosmonautClient ?? throw new ArgumentNullException(nameof(cosmonautClient)); Settings = new CosmosStoreSettings(databaseName, cosmonautClient.DocumentClient.ServiceEndpoint.ToString(), string.Empty, cosmonautClient.DocumentClient.ConnectionPolicy); if (Settings.InfiniteRetries) { CosmonautClient.DocumentClient.SetupInfiniteRetries(); } if (string.IsNullOrEmpty(Settings.DatabaseName)) { throw new ArgumentNullException(nameof(Settings.DatabaseName)); } _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(CosmonautClient); _databaseCreator = databaseCreator ?? new CosmosDatabaseCreator(CosmonautClient); InitialiseCosmosStore(overriddenCollectionName); }
static void Main(string[] args) { IConnectionStringProvider _csp = new ConnectionStringProvider(); ICollectionFactory _cf = new CollectionFactory(_csp); ICollectionCreator cc = _cf.CreateCollection(); Func <List <Place> > placeGenerator = () => { var retIt = new List <Place>(); Random random = new Random(); for (int i = 0; i < 100; i++) { decimal randomNumber = random.Next(80, 120); var newPlace = new Place() { Number = i, PriceMultiplier = randomNumber / 100 }; retIt.Add(newPlace); } return(retIt); }; cc.Trains.InsertMany(new List <MongoTrain> { new MongoTrain { TrainId = 1, Number = 90, StartLocation = "Kiev", EndLocation = "Odessa", Carriages = new List <Carriage>() { new Carriage() { Places = placeGenerator(), Type = CarriageType.SecondClassSleeping, DefaultPrice = 100m, Number = 1, }, new Carriage() { Places = placeGenerator(), Type = CarriageType.SecondClassSleeping, DefaultPrice = 100m, Number = 2, }, new Carriage() { Places = placeGenerator(), Type = CarriageType.FirstClassSleeping, DefaultPrice = 120m, Number = 3, }, new Carriage() { Places = placeGenerator(), Type = CarriageType.FirstClassSleeping, DefaultPrice = 130m, Number = 4, } } }, new MongoTrain { TrainId = 2, Number = 720, StartLocation = "Kiev", EndLocation = "Vinnitsa", Carriages = new List <Carriage>() { new Carriage() { Places = placeGenerator(), Type = CarriageType.Sedentary, DefaultPrice = 40m, Number = 1, }, new Carriage() { Places = placeGenerator(), Type = CarriageType.Sedentary, DefaultPrice = 40m, Number = 2, }, new Carriage() { Places = placeGenerator(), Type = CarriageType.Sedentary, DefaultPrice = 40m, Number = 3, } } } }); }