Beispiel #1
0
 public AppInitializer(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger <AppInitializer> logger, IEnumerable <IMenuAction> actions)
 {
     _configurations = configurations;
     _appMongoClient = appMongoClient;
     _logger         = logger;
     _actions        = actions;
 }
Beispiel #2
0
        public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
        {
            //appMongoClient.MongoDatabase.CreateView("RevenueByCountry", "SalesRecords", );
            //var collection = appMongoClient.MongoDatabase.GetCollection<SalesRecord>("SalesRecords");

            //var y = new ProjectionDefinitionBuilder<SalesRecord>().Expression(
            //    (s) => new RevenueByCountry()
            //    {
            //        Country = s.Country, TotalCost = s.TotalCost, TotalProfit = s.TotalProfit,
            //        TotalRevenue = s.TotalRevenue
            //    });

            ////var s = PipelineStageDefinitionBuilder.Group<RevenueByCountry>((SalesRecord s) => new RevenueByCountry()
            ////{
            ////    Country = s.Country,
            ////    TotalCost = s.TotalCost,
            ////    TotalProfit = s.TotalProfit,
            ////    TotalRevenue = s.TotalRevenue
            ////};

            //var grouping = collection
            //    .Aggregate()
            //    .Group(r => new {GroupedCountry = r.Country},
            //        g => new RevenueByCountry()
            //        {
            //            Country = g.Key.ToString(),
            //            TotalProfit = g.Sum(x => x.TotalProfit),
            //            TotalCost = g.Sum(x => x.TotalCost),
            //            TotalRevenue = g.Sum(x => x.TotalRevenue)
            //        }
            //    );
            //var pipelineStageDef = PipelineStageDefinitionBuilder.Group(new ProjectionDefinitionBuilder<SalesRecord>().Expression(r => new { r.Country }));
        }
Beispiel #3
0
        public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
        {
            int counter    = 0;
            var collection = appMongoClient.MongoDatabase.GetCollection <SalesRecord>("SalesRecords", settings: new MongoCollectionSettings()
            {
                AssignIdOnInsert = true
            });

            collection.DeleteMany(s => true);

            foreach (var salesRecord in ReadFromFile())
            {
                collection.InsertOne(salesRecord);
                logger.LogInformation($"inserted order id {salesRecord.OrderId}. Count {++counter}");
            }
        }
Beispiel #4
0
        public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
        {
            var collection = appMongoClient.MongoDatabase.GetCollection <SalesRecord>("SalesRecords");
            var regionKey  = Builders <SalesRecord> .IndexKeys.Ascending(field => field.Region);

            var countryKey = Builders <SalesRecord> .IndexKeys.Ascending(field => field.Country);

            var keys       = new IndexKeysDefinitionBuilder <SalesRecord>().Combine(new[] { regionKey, countryKey });
            var indexModel = new CreateIndexModel <SalesRecord>(keys);
            var result     = collection.Indexes.CreateOne(indexModel);

            logger.LogInformation($"index result {result}");

            var indexes = collection.Indexes.List();

            indexes.ForEachAsync(x => logger.LogInformation($"{x.ToString()}"));
        }
        public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
        {
            Console.WriteLine($"Region");
            var region = Console.ReadLine();

            Console.WriteLine("Country");
            var country = Console.ReadLine();

            var collection = appMongoClient.MongoDatabase.GetCollection <SalesRecord>("SalesRecords");

            //basic find
            Find(logger, collection, region, country);

            //using filters
            FindUsingFilters(logger, region, country, collection);

            //using contains
            FindWildCard(logger, region, country, collection);
        }
Beispiel #6
0
        public async void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
        {
            var urls = new[]
            {
                "http://localhost:8080/databases/gccdev/static/ProductAssembly/505222",
                "http://localhost:8080/databases/gccdev/static/ProductAssembly/507702",
                "http://localhost:8080/databases/gccdev/static/ProductAssembly/507703"
            };

            var client = new HttpClient();

            foreach (var url in urls)
            {
                var response = await client.GetStreamAsync(url);

                using (var ms = new MemoryStream())
                {
                    response.CopyTo(ms);
                    Console.WriteLine($"stream {url} is {ms.Length} bytes");
                }
            }
        }
        public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
        {
            Console.WriteLine($"Region");
            var region = Console.ReadLine();

            Console.WriteLine("Country");
            var country = Console.ReadLine();

            Console.Write("Set OrderPriority as: ");
            var orderPriority = Console.ReadLine();

            var collection = appMongoClient.MongoDatabase.GetCollection <SalesRecord>("SalesRecords");

            // find records and update at the same time
            var filter = Builders <SalesRecord> .Filter.Where(x => x.Region == region && x.Country == country && x.OrderPriority == "M");

            var update = Builders <SalesRecord> .Update.Set(field => field.OrderPriority, "MORE");

            var results = collection.UpdateMany(filter, update);

            logger.LogInformation($"Update completed. IsModifiedCountAvailable: {results.IsModifiedCountAvailable}.\r\n\t {results.MatchedCount} - Matched\r\n\t {results.ModifiedCount} - Modified");
        }
 public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient, ILogger logger)
 {
     Environment.Exit(0);
 }
Beispiel #9
0
 public void Execute(IAppConfigurations configurations, AppMongoClient appMongoClient)
 {
     throw new NotImplementedException();
 }
 public AppMongoClient(IAppConfigurations configurations)
 {
     _configurations = configurations;
     _mongoClient    = new MongoClient(_configurations.MongoDbConnectionString());
     _mongoDatabase  = _mongoClient.GetDatabase(_configurations.MongoDbDatabase());
 }
 public EmailConfigurationProvider(IAppConfigurations appConfigurations)
 {
     _appConfigurations = appConfigurations;
 }