Exemple #1
0
        /// <summary>
        /// Reads initial file and imports data
        /// </summary>
        /// <returns></returns>
        public List <T> ImportFile(ref bool IsSucceeded)
        {
            IsSucceeded = true;
            List <T>  prices = new List <T>(100);
            XlsParser parser = new XlsParser(new System.IO.FileInfo(_filename), 2, 0);

            try
            {
                List <DataRow> parsed = parser.Parse();
                foreach (DataRow dr in parsed)
                {
                    T instance = this.ParseRow(dr);
                    if (instance == null)
                    {
                        IsSucceeded = false;
                        continue;
                    }
                    prices.Add(instance);
                }
            }
            catch (Exception ex)
            {
                ErrorMessages.Add(new ImportErrorMessage("XLSFileIncorrectFormatError"));

                IsSucceeded = false;
                WebVariables.Logger.Fatal("Exception during parsing", ex);
                Logger.Log(string.Format("Inner exception: {0}", ex.InnerException), LogLevel.Fatal);
            }

            return(prices);
        }
Exemple #2
0
        /// <summary>
        /// Reads initial file and imports data
        /// </summary>
        /// <returns></returns>
        public List <T> ImportFile()
        {
            List <T>  products = new List <T>(100);
            XlsParser parser   = new XlsParser(new System.IO.FileInfo(_filename), 6, 0);

            try
            {
                List <DataRow> parsed = parser.Parse();
                //Go throw rows and validate each row
                foreach (DataRow dr in parsed)
                {
                    T instance = this.ParseRow(dr);
                    if (instance == null)
                    {
                        continue;
                    }
                    products.Add(instance);
                }
            }
            catch (Exception ex)
            {
                WebVariables.Logger.Fatal("Exception during parsing", ex);
                Logger.Log(string.Format("Inner exception: {0}", ex.InnerException.Message), LogLevel.Fatal);
            }
            return(products);
        }
Exemple #3
0
        private void Parse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                generateButton.IsEnabled = false;

                currentSrt = XlsParser.Load(textBox.Text);

                generateButton.IsEnabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erreur");
            }
        }
        public async Task <IActionResult> Post(List <IFormFile> files)
        {
            foreach (var file in files)
            {
                using (var stream = file.OpenReadStream())
                {
                    await db.Weathers.AddRangeAsync(XlsParser.Parse(stream));

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateException)
                    {
                        db.ChangeTracker.AcceptAllChanges();
                    }
                }
            }


            return(RedirectToAction("Upload"));
        }