コード例 #1
0
        public async Task ProccessByItemListAsync(IEnumerable <CoverageBuilding> coverageBuildingList, string functionName, TraceWriter log)
        {
            log.Info($"{functionName} Registros encontrados {coverageBuildingList.Count()}");
            if (coverageBuildingList.Any())
            {
                var gescales = coverageBuildingList.Select(b => b.Gescal).ToList();

                await _cosmosHelper.InitializeAsync(log);

                log.Info($"{functionName} Cosmos inicializado");

                var dbBuildings = await _cosmosHelper.GetItemsAsync(b => gescales.Contains(b.id));

                log.Info($"{functionName} En cosmos hay {dbBuildings.Count()}");

                foreach (var building in coverageBuildingList)
                {
                    var dbBuilding = dbBuildings.FirstOrDefault(dbb => dbb.Gescal.Equals(building.Gescal));
                    if (dbBuilding != null)
                    {
                        building.Verticals = dbBuilding.Verticals;
                    }

                    await _cosmosHelper.UpsertDocumentAsync(building, functionName, log).ConfigureAwait(false);
                }

                log.Info($"{functionName} All items inserted");
            }
        }
コード例 #2
0
        public async Task ProccessByItemListAsync(IEnumerable <VerticalsCsv> verticalList, string functionName, TraceWriter log)
        {
            if (verticalList.Any())
            {
                await _cosmosHelper.InitializeAsync(log);

                log.Info($"{functionName} Cosmos inicializado");

                var groupByBuilding = verticalList.GroupBy(x => x.Gescal).ToList();
                var buildingsInList = groupByBuilding.Select(gbd => gbd.Key).ToList();
                var dbBuildings     = await _cosmosHelper.GetItemsAsync(b => buildingsInList.Contains(b.id));

                foreach (var buildingGroup in groupByBuilding)
                {
                    var dbBuilding = dbBuildings.FirstOrDefault(dbb => dbb.Gescal.Equals(buildingGroup.Key));
                    if (dbBuilding != null)
                    {
                        var homesSerialized = GetHomesForBuilding(buildingGroup.ToList());
                        dbBuilding.Verticals = homesSerialized;

                        await _cosmosHelper.UpsertDocumentAsync(dbBuilding, functionName, log);

                        log.Info($"{functionName} {dbBuilding.Gescal} homes updated");
                    }
                }

                log.Info($"{functionName} All items inserted");
            }
        }