public async Task<IEnumerable<ChimetDataRecord>> DownloadData(DateTime day)
        {
            WebRequest dateRequest = HttpWebRequest.Create(string.Format("http://{1}/archive/{0:yyyy}/{0:MMMM}/CSV/{2}{0:ddMMMyyyy}.csv", day, this.Station.Address, this.Station.ShortName));

            WebResponse data = await dateRequest.GetResponseAsync().ConfigureAwait(false);

            CsvHelper.Configuration.CsvConfiguration config = new CsvHelper.Configuration.CsvConfiguration();
            config.RegisterClassMap<ChimetDataRecordMap>();

            using (var reader = new CsvHelper.CsvReader(new System.IO.StreamReader(data.GetResponseStream()), config))
            {
                return reader.GetRecords<ChimetDataRecord>().ToList().AsReadOnly();
            }
        }
 public IEnumerable<UnsettledBetItem> GetUnsettledBets()
 {
     using (var fileReader = File.OpenText(GetFilePath(UnsettledBetsFileName)))
     using (var csvReader = new CsvHelper.CsvReader(fileReader))
     {
         return csvReader.GetRecords<UnsettledBetItem>().ToList();
     }
 }
Пример #3
0
 public override dynamic Load(Slice slice)
 {
     var ret = new List<dynamic>();
     if (!Blob.Exists())
         return ret;
     using (var reader = new CsvHelper.CsvReader(new StreamReader(Blob.OpenRead(), Configuration.Encoding)))
     {
         var records = reader.GetRecords<dynamic>();
         foreach (IDictionary<string, object> record in records)
             ret.Add(Helpers.DictionaryToObject(record, Structure));
     }
     return ret;
 }
Пример #4
0
        public override void Denormalize()
        {
            var conf = new CsvHelper.Configuration.Configuration()
            {
                HasHeaderRecord = false
            };
            using (var streamReader = new StreamReader(Path, Encoding.GetEncoding("SHIFT_JIS")))
            using (var csv = new CsvHelper.CsvReader(streamReader, conf))
            {
                csv.Configuration.RegisterClassMap<SourceMapper>();
                csv.Configuration.ReadingExceptionOccurred = ex =>
                {
                    // Do something instead of throwing an exception.
                    return true;
                };
                var source = csv.GetRecords<Source>().ToList();
                DataTable products = FetchProducts(source.Select(r => r.JanCode).Distinct());

                Func<Source, DataRow, Result> resultSelector = (a, b) =>
                {
                    return new Result()
                    {
                        DeliveredAt = a.DeliveredAt,
                        SupplyChainManagementCode = a.SupplyChainManagementCode,
                        SupplierCode = b["supplier_code"].ToString(),
                        VarietyCode = a.VarietyCode,
                        ModelNo = b["model_no"].ToString(),
                        ProductName = b["product_name"].ToString(),
                        JanCode = a.JanCode,
                        StoreCode = a.StoreCode,
                        StoreName = a.StoreName,
                        Qty = a.Qty,
                        UnitCost = a.UnitCost,
                        Cost = a.Cost,
                        UnitPrice = a.UnitPrice,
                        Price = a.Price,
                    };
                };
                var cmp = EqualityComparer<string>.Default;
                var alookup = source.ToLookup((x) => x.JanCode, cmp);
                var blookup = products.AsEnumerable().ToLookup((x) => x["jan"].ToString(), cmp);

                var keys = new HashSet<string>(alookup.Select(p => p.Key), cmp);
                var query = from key in keys
                            from xa in alookup[key].DefaultIfEmpty(null)
                            from xb in blookup[key].DefaultIfEmpty(null)
                            select resultSelector(xa, xb);
                DenormalizedSchema_ = query.ToList();
            }
        }
Пример #5
0
        public static List <T> ReadFile <T>(TextReader reader, Type Mapper = null) where T : class
        {
            var configuration = new CsvConfiguration();

            if (Mapper != null)
            {
                configuration.RegisterClassMap(Mapper);
            }

            using (var csvReader = new CsvHelper.CsvReader(reader, configuration))
            {
                return(csvReader.GetRecords <T>().ToList());
            }
        }
Пример #6
0
 public static List <T> GetDataFromCsv <T>(string fName)
 {
     using (var reader = new StreamReader(fName))
     {
         using (var csv = new CsvHelper.CsvReader(reader))
         {
             csv.Configuration.ReadingExceptionOccurred = (ex) =>
             {
                 return(true);
             };
             return(csv.GetRecords <T>().ToList());
         }
     }
 }
Пример #7
0
        public static IList <Transaction> ReadFileStream(Stream stream)
        {
            var csvTrans = new List <CsvTransaction>();

            using (var reader = new StreamReader(stream))
            {
                using var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture);
                csv.Configuration.HasHeaderRecord = false;
                csv.Configuration.RegisterClassMap <CsvTransactionMap>();
                var records = csv.GetRecords <CsvTransaction>();
                csvTrans.AddRange(records);
            }
            return(ConvertCsvTransactionToTransaction(csvTrans));
        }
        public static Import Upload(HttpPostedFileWrapper file, int userId)
        {
            var newImport = NewMethod(userId);

            var csvConf = new CsvHelper.Configuration.CsvConfiguration
            {
                SkipEmptyRecords = true,
                IsCaseSensitive  = false,
                IsStrictMode     = true
            };

            csvConf.ClassMapping <MasterIdImportCsvMap>();
            var streamReader = new System.IO.StreamReader(file.InputStream);

            using (var csvReader = new CsvHelper.CsvReader(streamReader, csvConf))
            {
                var data = csvReader.GetRecords <ImportClient>().Select((record, i) =>
                                                                        new ImportClient
                {
                    RowIndex = i,
                    ImportId = newImport.Id,

                    ClientId = record.ClientId,
                    MasterId = record.MasterId,

                    UpdatedAt   = newImport.StartedAt,
                    UpdatedById = newImport.UserId,
                });


                string connectionString = System.Data.SqlClient.ConnectionStringHelper.GetProviderConnectionString();
                var    sqlBulkCopy      = new System.Data.SqlClient.SqlBulkCopy(connectionString);
                sqlBulkCopy.DestinationTableName = "ImportClients";
                sqlBulkCopy.ColumnMappings.Add("ImportId", "ImportId");
                sqlBulkCopy.ColumnMappings.Add("RowIndex", "RowIndex");
                sqlBulkCopy.ColumnMappings.Add("ClientId", "ClientId");
                sqlBulkCopy.ColumnMappings.Add("MasterId", "MasterId");
                sqlBulkCopy.ColumnMappings.Add("UpdatedAt", "UpdatedAt");
                sqlBulkCopy.ColumnMappings.Add("UpdatedById", "UpdatedById");

                var dataReader = new IEnumerableDataReader <ImportClient>(data);

                sqlBulkCopy.WriteToServer(dataReader);

                sqlBulkCopy.Close();
            }

            return(newImport);
        }
            public static Iso639Data?GetTag(string tag)
            {
                if (_data == null)
                {
                    var uri    = new Uri("pack://application:,,,/Resources/iso639-autonyms.tsv");
                    var reader = new StreamReader(Application.GetResourceStream(uri)?.Stream ??
                                                  throw new NullReferenceException());
                    var csv = new CsvHelper.CsvReader(reader);
                    csv.Configuration.Delimiter = "\t";
                    csv.Configuration.RegisterClassMap <Iso639DataMap>();
                    _data = csv.GetRecords <Iso639Data>().ToArray();
                }

                return(_data.First(x => x.Tag1 == tag) ?? _data.First(y => y.Tag3 == tag));
            }
Пример #10
0
        public static IEnumerable <T> ReadFileWithoutHeader <T>(TextReader reader, Type map = null) where T : class
        {
            using (var csvReader = new CsvHelper.CsvReader(reader))
            {
                if (map != null)
                {
                    csvReader.Configuration.RegisterClassMap(map);
                }

                csvReader.Configuration.HasHeaderRecord = false;
                csvReader.Configuration.TrimOptions     = CsvHelper.Configuration.TrimOptions.Trim;

                return(csvReader.GetRecords <T>().ToList());
            }
        }
Пример #11
0
        public static ObservableCollection <NugetData> GetNugetData(System.IO.StreamReader sr)
        {
            sr.ReadLine();
            var csv = new CsvHelper.CsvReader(sr);

            csv.Configuration.RegisterClassMap <AccountMap>();
            var records = csv.GetRecords <NugetData>();
            var result  = new ObservableCollection <NugetData>();

            foreach (var item in records)
            {
                result.Add(item);
            }
            return(result);
        }
 private IEnumerable<Employee> GetEmployeeAdjustments(Stream content)
 {
     using (var reader = new CsvHelper.CsvReader(new StreamReader(content))) {
         return reader.GetRecords<CsvAdjustment>().Where(x => x.Year > 0)
                      .Select(x => new Employee {
                             Id = 0,
                             Ssn = x.Ssn,
                             DeductionSchema = new DeductionSchema {
                                 Adjustment = x.Amount,
                                 Year = x.Year
                             }
                       })
                      .ToList();
     }
 }
Пример #13
0
        private static HabHubPredictionPoint getLastRecord(string csv)
        {
            // last record is garbage, chop it off
            var lastIndex = csv.LastIndexOf("\r\n");

            csv = csv.Substring(0, lastIndex - 1);

            var csvOfRecords = new CsvHelper.CsvReader(new StringReader(csv));

            csvOfRecords.Configuration.IgnoreQuotes      = true;
            csvOfRecords.Configuration.HasHeaderRecord   = false;
            csvOfRecords.Configuration.MissingFieldFound = null;
            csvOfRecords.Read();

            return(csvOfRecords.GetRecords <HabHubPredictionPoint>().LastOrDefault());
        }
        public List<PublicationTarget> Read()
        {
            using (var tr = new StreamReader(_filename))
            {
                var csv = new CsvHelper.CsvReader(tr);
                csv.Configuration.Delimiter = ",";
                csv.Configuration.IsHeaderCaseSensitive = false;
                csv.Configuration.SkipEmptyRecords = true;
                csv.Configuration.IgnoreBlankLines = true;
                csv.Configuration.RegisterClassMap<PublicationTargetCsvMapping>();
                //csv.Configuration.TrimHeaders = true;

                var records = csv.GetRecords<PublicationTarget>().ToList();
                return records;
            }
        }
Пример #15
0
        static void Main2(string[] args)
        {
            var sr = new System.IO.StreamReader(@"D:\temp\WordbookImpressApp\res\nuget\list.csv");

            sr.ReadLine();
            var csv = new CsvHelper.CsvReader(sr);

            csv.Configuration.RegisterClassMap <AccountMap>();
            var records = csv.GetRecords <NugetData>();

            foreach (var item in records)
            {
                Console.WriteLine(item.Id + " " + item.Version + " " + item.LicenseUrl);
            }
            Console.ReadLine();
        }
        public List <PublicationTarget> Read()
        {
            using (var tr = new StreamReader(_filename))
            {
                var csv = new CsvHelper.CsvReader(tr);
                csv.Configuration.Delimiter             = ",";
                csv.Configuration.IsHeaderCaseSensitive = false;
                csv.Configuration.SkipEmptyRecords      = true;
                csv.Configuration.IgnoreBlankLines      = true;
                csv.Configuration.RegisterClassMap <PublicationTargetCsvMapping>();
                //csv.Configuration.TrimHeaders = true;

                var records = csv.GetRecords <PublicationTarget>().ToList();
                return(records);
            }
        }
Пример #17
0
        private void SeedData()
        {
            if (File.Exists("../Data/seedData.csv"))
            {
                using (var contents = new StreamReader("../Data/seedData.csv"))
                    using (var reader = new CsvHelper.CsvReader(contents))
                    {
                        reader.Configuration.RegisterClassMap <LocationEntityMap>();
                        reader.Configuration.PrepareHeaderForMatch = header => header.ToLower();
                        var items = reader.GetRecords <LocationEntity>();

                        _context.LocationEntities.AddRange(items);

                        _context.SaveChanges();
                    }
            }
        }
Пример #18
0
        public Fact[] Read(string message)
        {
            var csvConfig = new CsvConfiguration
            {
                Delimiter = "|",
                Encoding = Encoding.UTF8,
                HasHeaderRecord = true,
            };
            csvConfig.RegisterClassMap<FactMap>();
            csvConfig.CultureInfo = CultureInfo.InvariantCulture;

            using (var reader = new StringReader(message))
            using (var parser = new CsvHelper.CsvReader(reader, csvConfig))
            {
                return parser.GetRecords<Fact>().ToArray();
            }
        }
Пример #19
0
        public DataTable Load()
        {
            var tbl    = new DataTable();
            var config = new CsvHelper.Configuration.CsvConfiguration {
                HasHeaderRecord = _hasHeader
            };

            using (var reader = new CsvHelper.CsvReader(_reader, config))
            {
                foreach (var d in reader.GetRecords <T>())
                {
                    var row = tbl.NewRow();
                    tbl.Rows.Add(row);
                }
            }
            return(tbl);
        }
Пример #20
0
        static void Main(string[] args)
        {
            //http://www.omdbapi.com/?apikey=4e220919&t=Star+Wars%3A+Episode+IV+-+A+New+Hope

            var path = @"C:\DL\MovieLensRecommender\MovieLensRecommender\data\movies.csv";

            using (var file = File.OpenText(path))
            {
                var csv    = new CsvHelper.CsvReader(file);
                var movies = csv.GetRecords <Movie>()
                             .OrderByDescending(a => a.RatingCount)
                             .Take(1000)
                             .ToList();

                movies.ForEach(m => ProcessMovie(m));
            }
        }
Пример #21
0
 private void btnRead_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog()
     {
         Filter = "CSV|*.csv", ValidateNames = true
     })
     {
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             using (var sr = new StreamReader(new FileStream(ofd.FileName, FileMode.Open)))
             {
                 var csvReader = new CsvHelper.CsvReader(sr);
                 studentBindingSource.DataSource = csvReader.GetRecords <Student>();
             }
         }
     }
 }
Пример #22
0
        public Box[] BoxFromCsv(TextReader rdr)
        {
            using var parser = new CsvHelper.CsvReader(rdr, CultureInfo.InvariantCulture);
            parser.Configuration.HeaderValidated   = null;
            parser.Configuration.MissingFieldFound = null;
            parser.Configuration.IgnoreBlankLines  = false;
            var ret = parser.GetRecords <Box>().ToArray();

            foreach (var b in ret)
            {
                if (b.BoxTime == "")
                {
                    b.BoxTime = null;
                }
            }
            return(ret);
        }
 public int GetRecordCount(string fileWithFullPath)
 {
     using (var reader = File.OpenText(fileWithFullPath))
     {
         try
         {
             var csv = new CsvHelper.CsvReader(reader);
             csv.Configuration.Delimiter = @"|";
             var records = csv.GetRecords(typeof(object));
             return(records.Skip(0).Count());
         }
         finally
         {
             reader.Close();
         }
     }
 }
Пример #24
0
        /// Add a string of text to a table
        public void AddStringTable(string text)
        {
            // Create the dictionary that will contain these values
            var stringTable = new Dictionary <string, string>();

            using (var reader = new System.IO.StringReader(text)) {
                using (var csv = new CsvHelper.CsvReader(reader)) {
                    var records = csv.GetRecords <Yarn.LocalisedLine>();

                    foreach (var record in records)
                    {
                        stringTable[record.LineCode] = record.LineText;
                    }
                }
            }

            AddStringTable(stringTable);
        }
Пример #25
0
 /// <summary>
 /// Deserialize
 /// </summary>
 /// <param name="content"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public object Deserialize(string content, Type type)
 {
     if (type.IsAssignableFrom(typeof(System.Collections.IEnumerable)))
     {
         var instan = (System.Collections.IEnumerable)type.Assembly.CreateInstance(type.FullName);
         var list   = new List <object>();
         using (CsvHelper.CsvReader reader = new CsvHelper.CsvReader(new StreamReader(ConvertHelper.ConvertToStream(content))))
         {
             foreach (var per in reader.GetRecords(instan.AsQueryable().ElementType))
             {
                 list.Add(per);
             }
         }
         instan = list;
         return(instan);
     }
     throw new InvalidCastException(type.Name + " is not IEnumerable");
 }
Пример #26
0
        /// <summary>
        /// Parses the pipe delimeted csv files of Top Ranking books
        /// </summary>
        /// <param name="importFiles"></param>
        /// <returns>An im-memory enumerable of books</returns>
        public static Task <IEnumerable <Book> > LoadBooks(string[] importFiles)
        {
            var books = new List <Book>();

            foreach (var file in importFiles)
            {
                using (var textReader = File.OpenText(file))
                {
                    var csvHelper = new CsvHelper.CsvReader(textReader, CultureInfo.InvariantCulture);
                    csvHelper.Configuration.Delimiter       = COLUMN_DELIMITER.ToString();
                    csvHelper.Configuration.IgnoreQuotes    = true;
                    csvHelper.Configuration.HasHeaderRecord = true;
                    books.AddRange(csvHelper.GetRecords <Book>());
                }
            }

            return(Task.FromResult((IEnumerable <Book>)books));
        }
Пример #27
0
        public RecordResults <TUnprocessedRecord> ExtractRecordsFromFile(string filePath)
        {
            using (var fileHanlde = new StreamReader(filePath))
                using (var csv = new CsvHelper.CsvReader(fileHanlde, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.HasHeaderRecord = false;
                    csv.Configuration.RegisterClassMap <TRecordClassMap>();

                    try
                    {
                        return(new RecordResults <TUnprocessedRecord>(csv.GetRecords <TUnprocessedRecord>().ToList()));
                    }
                    catch (Exception ex)
                    {
                        return(new RecordResults <TUnprocessedRecord>(null, ex.Message));
                    }
                }
        }
Пример #28
0
        static void Main(string[] args)
        {
            List <Musteri> musterilerim = new List <Musteri>();

            for (int i = 0; i < 50; i++)
            {
                Musteri m1 = new Musteri();
                m1.ID              = Guid.NewGuid();
                m1.Isim            = FakeData.NameData.GetFirstName();
                m1.Soyisim         = FakeData.NameData.GetSurname();
                m1.Telefonnumarasi = FakeData.PhoneNumberData.GetPhoneNumber();
                m1.Emailadres      = $"{m1.Isim}.{m1.Soyisim}@{FakeData.NetworkData.GetDomain()}";
                musterilerim.Add(m1);
            }

            if (Directory.Exists("C:\\CSV\\"))
            {
            }
            else
            {
                Directory.CreateDirectory("C:\\CSV\\");
            }

            StreamReader SR = new StreamReader("C:\\CSV\\Musteriler.csv");

            CsvHelper.CsvReader reader     = new CsvHelper.CsvReader(SR);
            List <Musteri>      okunandata = reader.GetRecords <Musteri>().ToList();


            StreamWriter SW = new StreamWriter("C:\\CSV\\Musteriler.csv");

            CsvHelper.CsvWriter write = new CsvHelper.CsvWriter(SW);
            write.WriteHeader(typeof(Musteri));
            foreach (Musteri item in musterilerim)
            {
                write.WriteRecord(item);
            }
            SW.Close();

            Console.WriteLine("CSV olarak kayit islemi tamamlanmistir.");
            Console.WriteLine($"Toplam Adet: {musterilerim.Count}");
            Console.ReadKey();
        }
Пример #29
0
        private void GetSourceRecords()
        {
            if (SourceRecords != null)
            {
                return;
            }

            using (var streamReader = new StreamReader(Path))
                using (var csv = new CsvHelper.CsvReader(streamReader, CsvConf))
                {
                    //csv.Configuration.RegisterClassMap<SourceMapper>();
                    csv.Configuration.ReadingExceptionOccurred = ex =>
                    {
                        // Do something instead of throwing an exception.
                        return(true);
                    };
                    SourceRecords = csv.GetRecords <Source>().ToList();
                }
        }
Пример #30
0
        /// <summary>
        /// Read a test data file from the specified path.
        /// </summary>
        /// <typeparam name="T">The data record type to read from the file.</typeparam>
        /// <param name="filename">The path to the data file, both absolute and relative paths are allowed.</param>
        /// <returns>A sequence of messages from the "Messages" column of the data file.</returns>
        public static IEnumerable <string> Read <T>(string filename)
            where T : IDataRecord
        {
            // make path relative to appdomain directory instead of Environment.CurrentDirectory
            if (!Path.IsPathRooted(filename))
            {
                filename = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    filename);
            }

            using (var inputFile = new StreamReader(filename))
                using (var reader = new CsvHelper.CsvReader(inputFile))
                {
                    var records = reader.GetRecords <T>();

                    return(records.Select(r => r.Message).ToArray());
                }
        }
Пример #31
0
        public override void Denormalize()
        {
            using (var streamReader = new StreamReader(Path))
                using (var csv = new CsvHelper.CsvReader(streamReader))
                {
                    // CSVに対して事前処理を行う。(JAN毎に在庫数量を合計)
                    var source = csv.GetRecords <Source>()
                                 .GroupBy(r => r.JanCode)
                                 .Select(g => new Source()
                    {
                        JanCode = g.Key, Qty = g.Sum(r => r.Qty)
                    })
                                 .ToList();
                    DataTable products = FetchProducts(source.Select(r => r.JanCode).Distinct());

                    Func <Source, DataRow, Result> resultSelector = (a, b) =>
                    {
                        return(new Result()
                        {
                            JanCode = a.JanCode,
                            Qty = a.Qty,
                            SupplierCode = b["supplier_code"].ToString(),
                            SupplierName = b["supplier_name"].ToString(),
                            VarietyCode = b["item_code"].ToString(),
                            ModelNo = b["model_no"].ToString(),
                            ProductName = b["product_name"].ToString(),
                            Price = int.Parse(b["price"].ToString()),
                        });
                    };
                    var cmp     = EqualityComparer <string> .Default;
                    var alookup = source.ToLookup((x) => x.JanCode, cmp);
                    var blookup = products.AsEnumerable().ToLookup((x) => x["jan"].ToString(), cmp);

                    var keys  = new HashSet <string>(alookup.Select(p => p.Key), cmp);
                    var query = from key in keys
                                from xa in alookup[key].DefaultIfEmpty(null)
                                from xb in blookup[key].DefaultIfEmpty(null)
                                select resultSelector(xa, xb);

                    DenormalizedSchema_ = query.ToList();
                }
        }
Пример #32
0
 public static void GetRefs(string refPath)
 {
     try
     {
         refs.Clear();
         using (var sr = new StreamReader(refPath))
         {
             var csv = new CsvHelper.CsvReader(sr);
             var res = csv.GetRecords <PartUrl>().ToList();
             if (res != null && res.Count() > 0)
             {
                 res.ForEach(r => refs.Add(r));
             }
         }
     }
     catch (Exception x)
     {
         XLogger.Error(x);
     }
 }
Пример #33
0
 private void roadFile(String fileName)
 {
     cleaNames();
     using (var csv = new CsvHelper.CsvReader(new StreamReader(fileName, Encoding.UTF8)))
     {
         csv.Configuration.HasHeaderRecord = true;
         var list = csv.GetRecords <Talking>();
         talkings = new List <Talking>();
         foreach (var line in list)
         {
             if (comboBox_talkingName.Items.IndexOf(line.name) == -1)
             {
                 comboBox_talkingName.Items.Add(line.name);
             }
             talkings.Add(line);
         }
         dataGridView_talk.DataSource = null;
         dataGridView_talk.DataSource = talkings;
     }
 }
Пример #34
0
        public List <PaymentRecord> getFileRecords(IFormFile file)
        {
            List <PaymentRecord> records = new List <PaymentRecord>();

            try
            {
                using (var reader = new StreamReader(file.OpenReadStream()))
                    using (var csv = new CsvHelper.CsvReader(reader))
                    {
                        csv.Configuration.HeaderValidated   = null;
                        csv.Configuration.MissingFieldFound = null;
                        records = csv.GetRecords <PaymentRecord>().ToList();
                    }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Error:" + ex.Message;
            }
            return(records);
        }
Пример #35
0
        public IEnumerable <IAccount> ImportData(string cultureName)
        {
            IEnumerable <DataRecord> data = null;
            var stream = new StreamReader(this.fileName);

            using (var reader = new CsvHelper.CsvReader(stream, new CultureInfo(cultureName)))
            {
                data = reader.GetRecords <DataRecord>().ToList();
            }
            RunOnXboxOnly($"In {nameof(ImportData)}.");
            var result = new List <IAccount>();

            foreach (var item in data)
            {
                var accHolder = new AccountHolder(item.IdNo, item.FirstName, item.LastName);
                var account   = new DebitAccount(item.Iban, item.Balance, accHolder);
                result.Add(account);
            }
            return(result);
        }
Пример #36
0
        public static List <T> GetFileDataToList <T>(string filePath, CsvHelper.Configuration.CsvConfiguration configuration)
        {
            List <T> records = new List <T>();

            try
            {
                using (var fileReader = new StreamReader(filePath))
                    using (var csvReader = new CsvHelper.CsvReader(fileReader, configuration))
                    {
                        records = csvReader.GetRecords <T>().ToList();
                        ActivityLogger.Log("INFO", $"{new FileInfo(filePath).Name} has {records.Count}");
                    }
            }
            catch (Exception ex)
            {
                ActivityLogger.Log(ex);
            }

            return(records);
        }
Пример #37
0
        public void ImportCharityData()
        {
            var dbConnectionFactory = appHost.Container.Resolve<IDbConnectionFactory>();
            using (var db = dbConnectionFactory.OpenDbConnection())
            {
                db.DropAndCreateTable<Charity>();
            }
            using (var db = dbConnectionFactory.OpenDbConnection())
            {
                string currentPath = AppDomain.CurrentDomain.BaseDirectory;

                var filestream = File.OpenRead(Path.Combine(currentPath, ConfigurationManager.AppSettings["CharityPath"]));
                TextReader textreader = new StreamReader(filestream);
                var reader = new CsvHelper.CsvReader(textreader);

                var lol = reader.GetRecords<dynamic>();
                var charityJson = lol.ToJson();
                var data = JsonSerializer.DeserializeFromString<List<Charity>>(charityJson);

                db.InsertAll(data);
            }
        }
Пример #38
0
        public static SqlTable CsvToSqlTable(TextReader textReader, ISqlWriter sqlWriter, bool hasHeader = true, string delimiter = ",", int count = -1)
        {
            var config = new CsvHelper.Configuration.CsvConfiguration();
            config.Delimiter = delimiter;
            config.HasHeaderRecord = hasHeader;

            var reader = new CsvHelper.CsvReader(textReader, config);
            var rows = reader.GetRecords<object>().ToList();

            textReader.Close();
            SqlTable sqlTable = null;
            if (rows.Count > 0)
            {
                sqlTable = new SqlTable();
                sqlTable.Headers = new List<SqlColumnTypeDefinition>();
                sqlTable.Rows = new List<SqlRow>();
                var i = 0;
                foreach (var row in rows)
                {
                    if (i == count)
                        break;

                    i++;

                    var columns = (System.Dynamic.ExpandoObject)row;
                    var sqlRow = new SqlRow();
                    sqlTable.Rows.Add(sqlRow);
                    var countUnkown = 1;
                    foreach (var col in columns)
                    {
                        // set rows
                        var sqlColumn = new SqlColumn();
                        sqlColumn.Type = sqlWriter.SqlTypeToCSharpType(col.Value);
                        sqlColumn.Value = col.Value;
                        sqlRow.Columns.Add(sqlColumn);

                        // set headers
                        var key = col.Key;
                        if (string.IsNullOrWhiteSpace(key))
                        {
                            key = "Unkown" + countUnkown;
                            countUnkown++;
                        }

                        SqlColumnTypeDefinition sqlColumnTypeDefinition = sqlTable.Headers.FirstOrDefault(f => f.Name == key);
                        if (sqlColumnTypeDefinition == null)
                        {
                            sqlColumnTypeDefinition = new SqlColumnTypeDefinition();
                            sqlColumnTypeDefinition.Name = col.Key;
                            sqlColumnTypeDefinition.Type = sqlColumn.Type;
                            sqlTable.Headers.Add(sqlColumnTypeDefinition);
                        }

                        sqlColumn.ColumnTypeDefinition = sqlColumnTypeDefinition;

                        // override type of header to STRING because exists a string in the column
                        if (sqlColumnTypeDefinition.Type != typeof(string) && sqlColumn.Type == typeof(string))
                            sqlColumnTypeDefinition.Type = typeof(string);
                    }
                }

                // Fix type to STRING if all values is 'NULL'
                foreach (var sqlHeader in sqlTable.Headers)
                {
                    if (sqlHeader.Type == null)
                        sqlHeader.Type = typeof(string);

                    sqlHeader.TypeFormatted = sqlWriter.CSharpTypeToSqlType(sqlHeader.Type);
                }
            }

            return sqlTable;
        }
        private async void ImportPathfinderSpellsCSV(IStorageFile file)
        {

            using (var reader = new StreamReader(await file.OpenStreamForReadAsync()))
            {
                var csvHelper = new CsvHelper.CsvReader(reader);
                var spells = csvHelper.GetRecords<PathfinderSpellsCSV>();
                foreach(var spell in spells)
                {
                    //spell.
                }
                
            }

        }