Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using StorageService.Model;
- namespace StorageService.GenerateData
- {
- public class Generate
- {
- private static int _storeNumber;
- private static int _supermarketNumber;
- public static Storage Store;
- private const int StorageSize = 30;
- private const int MinAmount = 1;
- private const int MaxAmount = 100;
- private const int MinOrderSize = 1;
- private const int MaxOrderSize = 10;
- private const int MinPrice = 1;
- private const int MaxPrice = 1000;
- private const int NumberOfSupermarkets = 30;
- private static string[] _productList = {"banan", "apple", "beef", "cereal", "chocolate cake", "lolipop"};
- private static List<Supermarket> _supermarkets;
- public static void Init()
- {
- _storeNumber = 1;
- _supermarketNumber = 1;
- _supermarkets = new List<Supermarket>();
- Store = GenerateStorage();
- Store._orders = SelectOrders();
- }
- public static Storage GenerateStorage()
- {
- var avaliabl = new List<StorageProduct>();
- return new Storage()
- {
- _avaliableProducts = GenerateAvaliableProducts(ref avaliabl),
- _id = Guid.NewGuid(),
- _name = "Store_" + _storeNumber,
- _needToOrder = GenerateNeedToOrder()
- };
- }
- public static List<StorageProduct> GenerateAvaliableProducts(ref List<StorageProduct> avaliable)
- {
- var rand = new Random();
- for (var num = 0; num < StorageSize; num++)
- {
- avaliable.Add(new StorageProduct(Guid.NewGuid(), _productList[rand.Next(0, _productList.Length)],
- rand.Next(MinAmount, MaxAmount), rand.Next(MinAmount, MaxAmount)));
- }
- return avaliable;
- }
- public static StorageProduct CreateStorageProduct()
- {
- var rand = new Random();
- return new StorageProduct(Guid.NewGuid(), _productList[rand.Next(0, _productList.Length)],
- rand.Next(MinAmount, MaxAmount), rand.Next(MinPrice, MaxPrice));
- }
- public static List<Order> SelectOrders()
- {
- _supermarkets = GenerateSupermarkets(_supermarkets);
- var selectSupermarketWithOrders = new List<Order>();
- foreach (var supermarket in _supermarkets)
- {
- if (supermarket._todayOrder != null)
- {
- selectSupermarketWithOrders.Add(supermarket._todayOrder);
- }
- }
- return selectSupermarketWithOrders;
- }
- public static List<Supermarket> GenerateSupermarkets( List<Supermarket> supermarkets)
- {
- for (var num = 0; num < NumberOfSupermarkets; num++)
- {
- supermarkets.Add(new Supermarket(Guid.NewGuid(), "Supermarket_" + _supermarketNumber, null));
- _supermarketNumber++;
- }
- var rndWantToOrder = new Random();
- foreach (var supermarket in supermarkets)
- {
- if (rndWantToOrder.Next(0, 2) > 0)
- {
- supermarket._todayOrder = GenerateOrder(supermarket._name);
- }
- }
- return supermarkets;
- }
- public static Order GenerateOrder( string supermarketName)
- {
- var rnd = new Random();
- var orderSize = rnd.Next(MinOrderSize, MaxOrderSize);
- var products = new List<StorageProduct>();
- for (var num = 0; num < orderSize; num++)
- {
- var index = rnd.Next(0, Store._avaliableProducts.Count - 1);
- var product = Store._avaliableProducts[index];
- products.Add(new StorageProduct(product.Id, product.Name, rnd.Next(MinAmount, MaxAmount), product.Price));
- }
- return new Order(Guid.NewGuid(), supermarketName, Status.Accepted, Date._today, products);
- }
- public static List<Order> GenerateNeedToOrder()
- {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement