public List <T> Parse(string filename)
        {
            Console.WriteLine("Read File and parse bus routes.");
            var result = _parser.Parse(filename);

            Console.WriteLine("Successfully read file {0}", filename);
            Console.WriteLine("Updating OSGB36 to WGS84.");
            return(result);
        }
Ejemplo n.º 2
0
            public async Task <CommandResponse> Handle(Command request, CancellationToken cancellationToken)
            {
                var(records, err) = _parser.Parse <TransactionRecord>(request.Content);
                if (err != null)
                {
                    return(CommandResponse.Failed(err));
                }

                var user = await _storage.GetUser(request.UserId);

                if (user == null)
                {
                    return(CommandResponse.Failed("User not found"));
                }

                await SendEmail(user, subject : "Started importing transactions", body : "");

                var errors = new List <string>();

                try
                {
                    foreach (var cmd in GetCommands(records))
                    {
                        cmd.WithUserId(request.UserId);
                        var response = await _mediator.Send(cmd);

                        if (response is CommandResponse r && r.Error != null)
                        {
                            errors.Add(r.Error);
                        }
                    }
                }
                catch (Exception ex)
                {
                    await SendEmail(
                        user : user,
                        subject : "Failed to import transactions",
                        body : ex.ToString()
                        );

                    return(CommandResponse.Failed($"Entry Failed: {ex}"));
                }

                var onFinished = errors.Count switch
                {
                    0 => AfterSuccess(user),
                    _ => AfterFailure(errors, user)
                };

                return(await onFinished);
            }
        public void ParseAndSave()
        {
            var file = httpContext.Request.Files[0];

            IEnumerable <ISupplier> list = null;

            Dictionary <string, Dictionary <string, int> > ConversionDictionary = null;

            switch (model.Supplier)
            {
            case "Igal":
                list = csvParser.Parse <Igal>(file.InputStream);
                ConversionDictionary = Igal.ConversionDictionary;
                break;

            case "IgalGIA":
                list = csvParser.Parse <IgalGIA>(file.InputStream);
                ConversionDictionary = IgalGIA.ConversionDictionary;
                break;
            }

            list = list.Distinct().ToList();



            var mapper = new Mapper <INV_DIAMONDS_INVENTORY>(ConversionDictionary);

            mapper.SetPricePolicy(PricePolicy.Calibrate);
            mapper.OurPriceCalibration((decimal)1.07);

            var dblist = list.Select(mapper.Map).ToList();

            var db = new DatabasePersistence();

            db.AddSupplierDiamondList(dblist);
            db.SaveOrUpdate();
        }
Ejemplo n.º 4
0
 public List <Transaction> Parse(TextReader reader, string fileType)
 {
     if (fileType == ".xml")
     {
         return(_xMLParser.Parse(reader));
     }
     else if (fileType == ".csv")
     {
         return(_cSVParser.Parse(reader));
     }
     else
     {
         throw new NotImplementedException($"File type {fileType} parser is not implemented");
     }
 }
Ejemplo n.º 5
0
            public async Task <CommandResponse> Handle(Command request, CancellationToken cancellationToken)
            {
                var(records, err) = _parser.Parse <CoinbaseProRecord>(request.Content);
                if (err != null)
                {
                    return(CommandResponse.Failed(err));
                }

                try
                {
                    var coinbaseProContainer = new CoinbaseProContainer();
                    coinbaseProContainer.AddRecords(records);

                    foreach (var b in coinbaseProContainer.GetBuys())
                    {
                        var cmd = new core.Cryptos.Handlers.Buy.Command {
                            Date         = b.Date,
                            DollarAmount = b.DollarAmount,
                            Quantity     = b.Quantity,
                            Token        = b.Token
                        };
                        cmd.WithUserId(request.UserId);
                        await _mediator.Send(cmd);
                    }

                    foreach (var b in coinbaseProContainer.GetSells())
                    {
                        var cmd = new core.Cryptos.Handlers.Sell.Command {
                            Date         = b.Date,
                            DollarAmount = b.DollarAmount,
                            Quantity     = b.Quantity,
                            Token        = b.Token
                        };
                        cmd.WithUserId(request.UserId);
                        await _mediator.Send(cmd);
                    }

                    return(CommandResponse.Success());
                }
                catch (Exception ex)
                {
                    return(CommandResponse.Failed(
                               $"Entry Failed: {ex.Message}"
                               ));
                }
            }
Ejemplo n.º 6
0
        public async Task <IActionResult> UploadCSV(IFormFile csvFile)
        {
            var csvData = _csvParser.Parse(csvFile);

            return(Ok(await _unitSession.UploadSessions(csvData)));
        }