public static async Task TransferMoney( [EventHubTrigger(@"%TransferEventHubName%", Connection = @"EventHubsNamespaceConnection")] EventData[] eventsData, [EventHub(@"%ReplyEventHubName%", Connection = @"EventHubsNamespaceConnection")] IAsyncCollector <EventData> eventCollector, [CosmosDB( databaseName: @"%CosmosDbDatabaseName%", collectionName: @"%CosmosDbTransferCollectionName%", ConnectionStringSetting = @"CosmosDbConnectionString")] IAsyncCollector <CheckingAccountLine> stateCollector, ILogger logger) { IMessageProducer eventProducer = new EventHubMessageProducer(eventCollector); IRepository <CheckingAccountLine> repository = new CosmosDbRepository <CheckingAccountLine>(stateCollector); var processors = TransferServiceCommandProcessorFactory.BuildProcessorMap(eventProducer, repository); var dispatcher = new CommandProcessorDispatcher(processors); foreach (EventData eventData in eventsData) { try { var commandContainer = CommandContainerFactory.BuildCommandContainer(eventData); await dispatcher.ProcessCommandAsync(commandContainer); } catch (Exception ex) { logger.LogError(ex, ex.Message); } } }
static async Task Main(string[] args) { CosmosDbRepository <Product> .Initialize(); //var product = new Product() //{ // Id = Guid.NewGuid().ToString(), // Images = new List<string>() { "image1", "image2", "image3" }, // Name = "Điện thoại Oppo reno", // Price = 100000, // ProductProperties = new ProductProperty() { Name = "color", Value = "red" } //}; //await CosmosDbRepository<Product>.CreateItemAsync(product); var product = await CosmosDbRepository <Product> .GetItemAsync("175a40c9-bfd9-4aed-bef6-68a68ed62994"); if (product != null) { Console.WriteLine(product.Name); } var redItem = await CosmosDbRepository <Product> .GetItemsAsync(x => x.ProductProperties.Name == "color"); if (redItem != null) { Console.WriteLine(redItem.FirstOrDefault()?.Name); } Console.ReadLine(); }
public async Task <ActionResult> CreateAsync([Bind(Include = "ProductID,Name,ProductModel,Culture,Description")] ProductsFromCosmos item) { if (ModelState.IsValid) { await CosmosDbRepository <ProductsFromCosmos> .CreateItemAsync(item); return(RedirectToAction("Index")); } return(View(item)); }
public async Task NotInitializedAsync() { var localRepository = new CosmosDbRepository <CosmosDbItem>(null, new CosmosDbRepositoryOptions { ConnectionString = ConnecntionString }); localRepository.IsInitialized.Should().BeFalse(); var item = await localRepository.InsertAsync(new CosmosDbItem()); item.Should().NotBeNull(); }
private static CosmosDbRepository InitializeDocumentClient() { string endpoint = Configuration.Get("AzureCosmosEndpoint"); string authKey = Configuration.Get("AzureCosmosKey"); string database = Configuration.Get("DatabaseName"); string collection = Configuration.Get("SessionLogTable"); CosmosDbRepository repo = CosmosDbRepository.Instance .Endpoint(endpoint) .AuthKeyOrResourceToken(authKey) .Database(database) .Collection(collection); return(repo); }
static int Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) .AddEnvironmentVariables("ChangeLog:") .AddCommandLine(args) .Build(); var githubSettings = new GithubSettings(); configuration.Bind(githubSettings); var gitSettings = new GitSettings(); configuration.Bind(gitSettings); var cosmosDbSettings = new CosmosDbSettings(); configuration.Bind(cosmosDbSettings); var gitHubService = new GithubService(githubSettings); var gitService = new GitService(gitSettings); var cosmoDbRepository = new CosmosDbRepository(cosmosDbSettings); var directAccessRepository = new DirectAccessChangeLogRepository(gitHubService, gitService); var app = new CommandLineApplication(); app.HelpOption(inherited: true); var showCommand = new ShowCommand(cosmoDbRepository, directAccessRepository); var loadCommand = new LoadCommand(cosmoDbRepository, directAccessRepository); app.Command("show", showCommand.Configure); app.Command("load", loadCommand.Configure); app.OnExecute(() => { Console.WriteLine("Specify a subcommand"); app.ShowHelp(); return(1); }); return(app.Execute(args)); }
public void Arrange() { _containerMock = new Mock <Container>(); _containerMock.Setup(c => c.GetItemQueryIterator <CosmosRegisteredEntity>( It.IsAny <QueryDefinition>(), It.IsAny <string>(), It.IsAny <QueryRequestOptions>())) .Returns(new Mock <FeedIterator <CosmosRegisteredEntity> >().Object); _mapperMock = new Mock <IMapper>(); _mapperMock.Setup(m => m.Map(It.IsAny <RegisteredEntity>())) .Returns((RegisteredEntity re) => new CosmosRegisteredEntity { Id = re.Id }); _queryMock = new Mock <CosmosQuery>(); _queryMock.Setup(q => q.AddCondition(It.IsAny <string>(), It.IsAny <DataOperator>(), It.IsAny <string>())) .Returns(_queryMock.Object); _queryMock.Setup(q => q.AddTypeCondition(It.IsAny <string>())) .Returns(_queryMock.Object); _queryMock.Setup(q => q.AddSourceSystemIdCondition(It.IsAny <string>(), It.IsAny <string>())) .Returns(_queryMock.Object); _queryMock.Setup(q => q.AddPointInTimeCondition(It.IsAny <DateTime>())) .Returns(_queryMock.Object); _queryMock.Setup(q => q.ToString()) .Returns("query-text"); _queryFactoryMock = new Mock <Func <CosmosCombinationOperator, CosmosQuery> >(); _queryFactoryMock.Setup(f => f.Invoke(It.IsAny <CosmosCombinationOperator>())) .Returns(_queryMock.Object); _loggerMock = new Mock <ILoggerWrapper>(); _repository = new CosmosDbRepository( new CosmosDbConnection(_containerMock.Object), _mapperMock.Object, _queryFactoryMock.Object, _loggerMock.Object); _cancellationToken = new CancellationToken(); }
public void Arrange() { _containerMock = new Mock <Container>(); _mapperMock = new Mock <IMapper>(); _mapperMock.Setup(m => m.Map(It.IsAny <RegisteredEntity>())) .Returns((RegisteredEntity re) => new CosmosRegisteredEntity { Id = re.Id }); _queryFactoryMock = new Mock <Func <CosmosCombinationOperator, CosmosQuery> >(); _queryFactoryMock.Setup(f => f.Invoke(It.IsAny <CosmosCombinationOperator>())) .Returns((CosmosCombinationOperator @operator) => new CosmosQuery(@operator)); _loggerMock = new Mock <ILoggerWrapper>(); _repository = new CosmosDbRepository( new CosmosDbConnection(_containerMock.Object), _mapperMock.Object, _queryFactoryMock.Object, _loggerMock.Object); _cancellationToken = new CancellationToken(); }
public LoadCommand(CosmosDbRepository cosmoDbRepository, DirectAccessChangeLogRepository directAccessRepository) { _cosmosDbRepository = cosmoDbRepository; _directAccessRepository = directAccessRepository; }
public DeliveryService() { _deliveryRepository = new CosmosDbRepository <Delivery>(_partitionKey); }
public async Task <ActionResult> Index() { var items = await CosmosDbRepository <ProductsFromCosmos> .GetItemsAsync(); return(View(items)); }
public CustomerService() { _customerRepository = new CosmosDbRepository <Customer>(_partitionKey); }