Пример #1
0
        public async Task <CalculationPack> Create(CalculationPack calc)
        {
            //await _calculationPacks. InsertOneAsync(calc);

            var result = _cache.GetOrAdd(calc.Id, () => CreatePack(calc));

            return(calc);
        }
Пример #2
0
        public async Task ProduceResultAsync(CalculationPack data)
        {
            var msg = new Message <int, CalculationPack>()
            {
                Key   = data.Id,
                Value = data
            };

            await _producer.ProduceAsync("results", msg);
        }
Пример #3
0
        public async Task <IActionResult> CreateSinglePack(CalculationPack calc)
        {
            var result = await _calculationPackService.Create(calc);

            if (result != null)
            {
                return(Ok(result));
            }

            return(NotFound());
        }
Пример #4
0
        public async Task <int> GeneratePacks(int numOfCalcs, int numOfUnits)
        {
            var result = new List <CalculationPack>();

            for (int i = 0; i < numOfCalcs; i++)
            {
                Random rand = new Random();
                var    id   = rand.Next();

                var pack = new CalculationPack()
                {
                    Id    = id,
                    Count = numOfCalcs,
                    EqId  = 1,
                    Data  = GenerateUnits(numOfUnits, id)
                };
                result.Add(pack);
            }

            await _calculationPackProducer.GeneratePacks(result);

            return(numOfCalcs);
        }
Пример #5
0
        public async Task <CalculationPack> Save(CalculationPack pack)
        {
            await _calculationPacks.InsertOneAsync(pack);

            return(pack);
        }
Пример #6
0
 public async Task <CalculationPack> Create(CalculationPack calc)
 {
     return(await _calculationPackRepository.Create(calc));
 }
Пример #7
0
        private CalculationPack CreatePack(CalculationPack calc)
        {
            _calculationPacks.InsertOneAsync(calc);

            return(calc);
        }