Advertisement
Guest User

reer

a guest
Dec 11th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using StorageService.Model;
  4.  
  5. namespace StorageService.GenerateData
  6. {
  7.     public class Generate
  8.     {
  9.         private static int _storeNumber;
  10.         private static int _supermarketNumber;
  11.  
  12.         public static Storage Store;
  13.  
  14.         private const int StorageSize = 30;
  15.         private const int MinAmount = 1;
  16.         private const int MaxAmount = 100;
  17.         private const int MinOrderSize = 1;
  18.         private const int MaxOrderSize = 10;
  19.         private const int MinPrice = 1;
  20.         private const int MaxPrice = 1000;
  21.         private const int NumberOfSupermarkets = 30;
  22.  
  23.         private static string[] _productList = {"banan", "apple", "beef", "cereal", "chocolate cake", "lolipop"};
  24.         private static List<Supermarket> _supermarkets;
  25.  
  26.         public static void Init()
  27.         {
  28.             _storeNumber = 1;
  29.             _supermarketNumber = 1;
  30.             _supermarkets = new List<Supermarket>();
  31.  
  32.             Store = GenerateStorage();
  33.             Store._orders = SelectOrders();
  34.         }
  35.  
  36.         public static Storage GenerateStorage()
  37.         {
  38.             var avaliabl = new List<StorageProduct>();
  39.  
  40.             return new Storage()
  41.             {
  42.                 _avaliableProducts = GenerateAvaliableProducts(ref avaliabl),
  43.                 _id = Guid.NewGuid(),
  44.                 _name = "Store_" + _storeNumber,
  45.                 _needToOrder = GenerateNeedToOrder()
  46.             };
  47.         }
  48.  
  49.         public static List<StorageProduct> GenerateAvaliableProducts(ref List<StorageProduct> avaliable)
  50.         {
  51.             var rand = new Random();
  52.             for (var num = 0; num < StorageSize; num++)
  53.             {
  54.  
  55.                 avaliable.Add(new StorageProduct(Guid.NewGuid(), _productList[rand.Next(0, _productList.Length)],
  56.                     rand.Next(MinAmount, MaxAmount), rand.Next(MinAmount, MaxAmount)));
  57.    
  58.             }
  59.             return avaliable;
  60.         }
  61.  
  62.         public static StorageProduct CreateStorageProduct()
  63.         {
  64.             var rand = new Random();
  65.             return new StorageProduct(Guid.NewGuid(), _productList[rand.Next(0, _productList.Length)],
  66.                 rand.Next(MinAmount, MaxAmount), rand.Next(MinPrice, MaxPrice));
  67.         }
  68.  
  69.         public static List<Order> SelectOrders()
  70.         {
  71.             _supermarkets = GenerateSupermarkets(_supermarkets);
  72.             var selectSupermarketWithOrders = new List<Order>();
  73.             foreach (var supermarket in _supermarkets)
  74.             {
  75.                 if (supermarket._todayOrder != null)
  76.                 {
  77.                     selectSupermarketWithOrders.Add(supermarket._todayOrder);
  78.                 }
  79.             }
  80.             return selectSupermarketWithOrders;
  81.         }
  82.  
  83.         public static List<Supermarket> GenerateSupermarkets( List<Supermarket> supermarkets)
  84.         {
  85.             for (var num = 0; num < NumberOfSupermarkets; num++)
  86.             {
  87.                 supermarkets.Add(new Supermarket(Guid.NewGuid(), "Supermarket_" + _supermarketNumber, null));
  88.                 _supermarketNumber++;
  89.             }
  90.             var rndWantToOrder = new Random();
  91.  
  92.             foreach (var supermarket in supermarkets)
  93.             {
  94.                 if (rndWantToOrder.Next(0, 2) > 0)
  95.                 {
  96.                     supermarket._todayOrder = GenerateOrder(supermarket._name);
  97.                 }
  98.             }
  99.             return supermarkets;
  100.         }
  101.  
  102.         public static Order GenerateOrder( string supermarketName)
  103.         {
  104.             var rnd = new Random();
  105.             var orderSize = rnd.Next(MinOrderSize, MaxOrderSize);
  106.             var products = new List<StorageProduct>();
  107.             for (var num = 0; num < orderSize; num++)
  108.             {
  109.                 var index = rnd.Next(0, Store._avaliableProducts.Count - 1);
  110.                 var product = Store._avaliableProducts[index];
  111.  
  112.                 products.Add(new StorageProduct(product.Id, product.Name, rnd.Next(MinAmount, MaxAmount), product.Price));
  113.                
  114.             }
  115.             return new Order(Guid.NewGuid(), supermarketName, Status.Accepted, Date._today, products);
  116.  
  117.         }
  118.        
  119.  
  120.         public static List<Order> GenerateNeedToOrder()
  121.         {
  122.             return null;
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement