Exemplo n.º 1
0
        private static void WriteCsv(List <WixPortfolioImportRowModel> buffer)
        {
            var CsvFactory    = new CsvHelper.Factory();
            var configuration = new CsvHelper.Configuration.CsvConfiguration(System.Globalization.CultureInfo.CurrentCulture);

            // Configure CSV reader
            configuration.DetectColumnCountChanges = true;
            configuration.HasHeaderRecord          = true;
            configuration.IgnoreBlankLines         = true;
            configuration.TrimOptions      = CsvHelper.Configuration.TrimOptions.Trim;
            configuration.Delimiter        = ",";
            configuration.IgnoreReferences = false;

            // Map properties of row model to field headers in CSV file
            configuration.RegisterClassMap <WixPortfolioImportCsvRowMap>();

            var dateStamp = System.DateTime.Now.ToString("yyyy-MM-dd HHmmss");
            var filename  = $"{dateStamp} - Portfolio products import.csv";

            using (var txtreader = new StreamWriter(filename))
            {
                using (var csv = CsvFactory.CreateWriter(txtreader, configuration))
                {
                    csv.WriteRecords(buffer);
                }

                txtreader.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read Alice's Inventory CSV to pull things not available from Finerworks API, like handleId, description, material, and size
        /// </summary>
        /// <returns></returns>
        public static List <AliceInventoryRowModel> ReadCsv()
        {
            var results       = new List <AliceInventoryRowModel>();
            var CsvFactory    = new CsvHelper.Factory();
            var configuration = new CsvHelper.Configuration.CsvConfiguration(System.Globalization.CultureInfo.CurrentCulture);

            // Configure CSV reader
            configuration.DetectColumnCountChanges = true;
            configuration.HasHeaderRecord          = true;
            configuration.IgnoreBlankLines         = true;
            configuration.TrimOptions = CsvHelper.Configuration.TrimOptions.Trim;
            configuration.Delimiter   = ",";

            // Map properties of RegisterBulkCsvRowModel to field headers in CSV file
            configuration.RegisterClassMap <AliceInventoryCsvRowMap>();

            using (var txtreader = new StreamReader("Inventory3.csv"))
            {
                using (var csv = CsvFactory.CreateReader(txtreader, configuration))
                {
                    // For each row in CSV file
                    results.AddRange(csv.GetRecords <AliceInventoryRowModel>());
                }

                txtreader.Close();
            }

            return(results);
        }
Exemplo n.º 3
0
 static void Main(string[] args)
 {
     var csvHelper = new CsvHelper.Factory();
 }