public BuildingUpgradeHandlerResponse CalculateBuildQueue(BuildingUpgradeHandlerRequest request)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 2
0
 private void CalculateBuildQueue(HandlerEntities.City mappedCity, City city)
 {
     var calcRequest = new BuildingUpgradeHandlerRequest
     {
         City = mappedCity,
         CalculateBuidingUpgradeStatistics = true,
         ReturnInventory = true,
         ReturnFaciltiyAssignment = false
     };
     var calculateResults = _buildingUpgradeHandler.CalculateBuildQueue(calcRequest);
     city.RequiredProducts = calculateResults.RequiredProductQueue.Select(Mapper.Map<Product>).ToArray();
     city.RequiredProductsInCityStorage =
         calculateResults.RequiredProductsInCityStorageQueue.Select(Mapper.Map<Product>).ToArray();
     city.TotalProducts = calculateResults.TotalProductQueue.Select(Mapper.Map<Product>).ToArray();
     city.AvailableStorage = calculateResults.AvailableStorage.Select(Mapper.Map<Product>).ToArray();
 }
Ejemplo n.º 3
0
        public City Get(SupplyChainRequest request)
        {
            var logStart = LogHelper.StartLog("Begin Supply Chain Get", Logger);
            //Get the current city from the database.
            var currentCity = ConvertRequestToHandlerCity(request);
            var prodTypes = _dbContext.ProductTypes
                                    .AsQueryable()
                                    .Include(x=>x.RequiredProducts)
                                    .Include(y=>y.ManufacturerType.ProductTypes)
                                    .ToArray();

            var calcRequest = new BuildingUpgradeHandlerRequest
            {
                ReturnInventory = true,
                ReturnFaciltiyAssignment = request.ReturnFacilityAssignment,
                City = Mapper.Map<Handler.Entities.City>(currentCity),
                ProductTypes = prodTypes
            };
            var strgResults = CalculateNewCityStorageAmounts(request, calcRequest, prodTypes);

            var ret = _buldingUpgradeHandler.CalculateBuildQueue(calcRequest);

            var city = new City
            {
                CurrentCityStorage = Mapper.Map<CityStorage>(strgResults.CityStorage),
                RequiredProducts = ret.RequiredProductQueue.Select(Mapper.Map<Product>).ToArray(),
                RequiredProductsInCityStorage = ret.RequiredProductsInCityStorageQueue.Select(Mapper.Map<Product>).ToArray(),
                TotalProducts = ret.TotalProductQueue.Select(Mapper.Map<Product>).ToArray(),
                AvailableStorage = ret.AvailableStorage.Select(Mapper.Map<Product>).ToArray(),
                BuildingUpgrades = ret.OrderedUpgrades.Select(Mapper.Map<BuildingUpgrade>).ToArray().OrderBy(x=>x.Name).ToArray()
            };
            UpdateBuildingUpgradeUiInfo(prodTypes, city);
            return LogHelper.EndLog(logStart, city);
        }
Ejemplo n.º 4
0
 private CalculateStorageResponse CalculateNewCityStorageAmounts(SupplyChainRequest request, BuildingUpgradeHandlerRequest calcRequest, ProductType[] productTypes)
 {
     var strgResults = new CalculateStorageResponse
     {
         CityStorage = calcRequest.City.CurrentCityStorage
     };
     //If we have products queued for production then calculate the new city storage.
     if (request.RequiredProductUpdates == null) return strgResults;
     var calculateStorageRequest = new CalculateStorageRequest
     {
         ProductTypes = productTypes,
         NewProductQuantities = request.RequiredProductUpdates.Select(Mapper.Map<Handler.Entities.Product>).ToArray(),
         CityStorage = calcRequest.City.CurrentCityStorage
     };
     return _cityStorageCalculator.CalculateNewStorageAmounts(calculateStorageRequest);
 }
Ejemplo n.º 5
0
        public BuildingUpgradeHandlerResponse CalculateBuildQueue(BuildingUpgradeHandlerRequest request)
        {
            //Early out if we don't have required data.
            if (request == null || request.City == null)
                return new BuildingUpgradeHandlerResponse
                {
                    RequiredProductQueue = new Product[]{},
                    CityStorage = request != null && request.City != null ? request.City.CurrentCityStorage : new CityStorage(),
                    PendingInventory = new Product[0],
                    TotalProductQueue = new Product[0],
                    RequiredProductsInCityStorageQueue = new Product[0],
                    OrderedUpgrades = new BuildingUpgrade[0],
                    AvailableStorage = new Product[0]
                };

            _productTypes = GetProductTypes(request).Select(Mapper.Map<ProductType>).ToArray();

            request.City.CurrentCityStorage.CurrentInventory = PopulateRequiredProducts(_productTypes, request.City.CurrentCityStorage.CurrentInventory);
            var handlerResponse = new BuildingUpgradeHandlerResponse
            {
                CityStorage = request.City.CurrentCityStorage,
                //Get property upgrade orders in the order requested (currently only sorted by shortest to longest duration)
                //  should be able to sort by priority etc...
                OrderedUpgrades = ReorderUpgradesByDuration(request)
            };

            //Get the list of inventory items from the orders including prerequisites to be queued.

            if (request.ReturnInventory)
            {
                var buildingUpgradeProductConsolidatorResponse = _buildingUpgradeProductConsolidator.GetConsolidatedProductQueue(new BuildingUpgradeProductConsoldatorRequest
                {
                    BuildingUpgrades = handlerResponse.OrderedUpgrades,
                    CityStorage = handlerResponse.CityStorage,
                    ProductTypes = _productTypes
                });
                handlerResponse.RequiredProductQueue = PopulateRequiredProducts(_productTypes, buildingUpgradeProductConsolidatorResponse.ConsolidatedRequiredProductQueue.ToArray());
                handlerResponse.TotalProductQueue = PopulateRequiredProducts(_productTypes, buildingUpgradeProductConsolidatorResponse.ConsolidatedTotalProductQueue.ToArray());
                handlerResponse.AvailableStorage = PopulateRequiredProducts(_productTypes, buildingUpgradeProductConsolidatorResponse.AvailableStorage.ToArray());
                handlerResponse.RequiredProductsInCityStorageQueue = PopulateRequiredProducts(_productTypes, buildingUpgradeProductConsolidatorResponse.ConsolidatedRequiredProductsInStorage.ToArray());
            }
            else
            {
                handlerResponse.RequiredProductQueue = new Product[0];
                handlerResponse.TotalProductQueue = new Product[0];
                handlerResponse.AvailableStorage = new Product[0];
                handlerResponse.RequiredProductsInCityStorageQueue = new Product[0];
            }

            if (request.CalculateBuidingUpgradeStatistics)
            {
                var statisticsRequest = new BuildingUpgradeStatisticsCalculatorRequest();
                _buildingUpgradeStatisticsCalculator.CalculateStatistics(statisticsRequest);
            }

            //now create manufacturing order to be placed.
            //  NOTE only creates one order where it maxes out supply chain limits.
            //            List<LegacyProduct> pendingInventory;
            //            var manufactingOrder = CreateManufacturingOrder(request, orderedInventoryQueue, out pendingInventory);

            return handlerResponse;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Upgrade Orders ordered by the order that takes the least time to process.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private BuildingUpgrade[] ReorderUpgradesByDuration(BuildingUpgradeHandlerRequest request)
        {
            var requestPropUpgrades = request.City.BuildingUpgrades;
            //                            var upgradeDurationCalculatorRequest = new BuildingUpgradeDurationCalculatorRequest
            //                            {
            //                                BuildingUpgrades = requestPropUpgrades,
            //                                ProductTypes = _productTypes,
            //                                CityStorage = request.City.CurrentCityStorage
            //                            };
            //            var propUpgradeDurationCalcResponse = _buildingUpgradeDurationCalculator.CalculateUpgradeTimes(upgradeDurationCalculatorRequest);
            foreach (var propUpgrade in requestPropUpgrades)
            {
                var upgradeDurationCalculatorRequest = new BuildingUpgradeDurationCalculatorRequest
                {
                    BuildingUpgrade = propUpgrade,
                    ProductTypes = _productTypes,
                    CityStorage = request.City.CurrentCityStorage
                };
                var propUpgradeDurationCalcResponse = _buildingUpgradeDurationCalculator.CalculateUpgradeTime(upgradeDurationCalculatorRequest);
                propUpgrade.TotalUpgradeTime = propUpgradeDurationCalcResponse.TotalUpgradeTime;
                propUpgrade.RemainingUpgradeTime = propUpgradeDurationCalcResponse.RemainingUpgradeTime;
                propUpgrade.ProductsInStorage = GetProductsAlreadyInStorage(propUpgrade, request.City.CurrentCityStorage.CurrentInventory);
            }

            var orderedPropUpgrades = requestPropUpgrades.OrderBy(x => x.TotalUpgradeTime).ToArray();
            return orderedPropUpgrades;
        }
Ejemplo n.º 7
0
 private Domain.ProductType[] GetProductTypes(BuildingUpgradeHandlerRequest request)
 {
     if (request.ProductTypes != null)
         return request.ProductTypes;
     return _propertyUpgradeUoW.ProductTypeRepository.Context.ProductTypes.AsQueryable()
         .Include(x => x.RequiredProducts).ToArray();
 }