当前位置: 首页>>代码示例>>C#>>正文


C# CsvReader.Read方法代码示例

本文整理汇总了C#中CsvReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.Read方法的具体用法?C# CsvReader.Read怎么用?C# CsvReader.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvReader的用法示例。


在下文中一共展示了CsvReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertGopIpIpBlocks

        private static void InsertGopIpIpBlocks()
        {
            Console.WriteLine("inserting ip blocks");

            var csv = new CsvReader(new StreamReader("GeoLiteCity-Blocks.csv"));

            csv.Read();

            var bsonDocuments = new List<BsonDocument>();

            while (csv.Read())
            {
                var document = new BsonDocument();

                document.Add(new BsonElement("start_ip_num", long.Parse(csv.GetField(0))));
                document.Add(new BsonElement("end_ip_num", long.Parse(csv.GetField(1))));
                document.Add(new BsonElement("location_id", int.Parse(csv.GetField(2))));

                bsonDocuments.Add(document);
            }

            var geoIpDataProvider = new GeoIpDataProvider();

            geoIpDataProvider.InsertGeoIpBlocks(bsonDocuments);

            Console.WriteLine("done");
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:27,代码来源:Program.cs

示例2: InsertGopIpLocations

        private static void InsertGopIpLocations()
        {
            Console.WriteLine("inserting ip locations");

            var csv = new CsvReader(new StreamReader("GeoLiteCity-Location.csv"));

            csv.Read();

            var bsonDocuments = new List<BsonDocument>();

            while (csv.Read())
            {
                var document = new BsonDocument();

                document.Add(new BsonElement("location_id", int.Parse(csv.GetField(0))));
                document.Add(new BsonElement("country", csv.GetField(1)));
                document.Add(new BsonElement("region", csv.GetField(2)));
                document.Add(new BsonElement("city_name", csv.GetField(3).ToLower()));
                document.Add(new BsonElement("city_display_name", csv.GetField(3)));
                document.Add(new BsonElement("postal_code", csv.GetField(4)));
                document.Add(new BsonElement("latitude", double.Parse(csv.GetField(5))));
                document.Add(new BsonElement("longitude", double.Parse(csv.GetField(6))));
                document.Add(new BsonElement("metro_code",
                    string.IsNullOrEmpty(csv.GetField(7)) ? 0 : int.Parse(csv.GetField(7))));
                document.Add(new BsonElement("area_code", csv.GetField(8)));

                bsonDocuments.Add(document);
            }

            var geoIpDataProvider = new GeoIpDataProvider();

            geoIpDataProvider.InsertGeoIpLocations(bsonDocuments);

            Console.WriteLine("done");
        }
开发者ID:xoperator,项目名称:GoKapara,代码行数:35,代码来源:Program.cs

示例3: BatchProcess

        private static int? BatchProcess(CsvReader csv, DateTime date, int? fundid)
        {
            BundleHeader bh = null;
            var fid = fundid ?? BatchImportContributions.FirstFundId();
            var now = DateTime.Now;

            csv.Read(); // skip first row which is the total row

            while (csv.Read())
            {
                var amount = csv[0];
                var routing = csv[1];
                var checkno = csv[2];
                var account = csv[3];
                var dt = csv[4].ToDate();

                if (!amount.HasValue() || !dt.HasValue)
                    continue;

                if (bh == null)
                    bh = BatchImportContributions.GetBundleHeader(date, now);

                var bd = BatchImportContributions.AddContributionDetail(dt.Value, fid, amount, checkno, routing, account);
                bd.Contribution.PostingDate = now;

                bh.BundleDetails.Add(bd);
            }

            BatchImportContributions.FinishBundle(bh);

            return bh?.BundleHeaderId ?? 0;
        }
开发者ID:stevesloka,项目名称:bvcms,代码行数:32,代码来源:HunterStreetImporter.cs

示例4: MergerToOneCsv

        public void MergerToOneCsv()
        {
            bool b = true;

            foreach (string item in CsvFilesPath)
            {
                using (var reader = new CsvReader(new StreamReader(item)))
                {
                    if (FirstLine.Count <= 0)
                    {
                        reader.Read();
                        FirstLine = new List<string>(reader.FieldHeaders);
                    }
                    if (b)
                    {
                        using (var writer = new CsvWriter(new StreamWriter(_strBatchResult, true)))
                        {
                            foreach (string s in FirstLine)
                            {
                                writer.WriteField(s);
                            }
                            writer.NextRecord();
                            foreach (string s in FirstLine)
                            {
                                writer.WriteField(reader.GetField(s));
                            }
                            writer.NextRecord();
                        }
                        b = false;
                    }

                    while (reader.Read())
                    {
                        using (var writer = new CsvWriter(new StreamWriter(_strBatchResult, true)))
                        {
                            foreach (string strHeader in reader.FieldHeaders)
                            {
                                Console.WriteLine(reader.GetField(strHeader));
                            }
                            foreach (string s in FirstLine)
                            {
                                writer.WriteField(reader.GetField(s));
                            }
                            writer.NextRecord();
                        }

                    }
                }
            }
        }
开发者ID:wangjidilidun,项目名称:UIInterFace,代码行数:50,代码来源:MergerCsv.cs

示例5: LoadSunspots

        public IList<BasicData> LoadSunspots()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            var res = assembly.GetManifestResourceStream("AIFH_Vol3.Resources.sunspots.csv");

            // did we fail to read the resouce
            if (res == null)
            {
                Console.WriteLine("Can't read sunspots data from embedded resources.");
                return null;
            }

            // load the data
            var istream = new StreamReader(res);
            CsvReader csv = new CsvReader(istream);
            csv.Read();

            // determine how many entries in file
            int sunspotCount = 0;
            while (csv.Read())
            {
                sunspotCount++;
            }
            Console.WriteLine("Sunspot count:" + sunspotCount);

            // allocate array to hold file
            double[][] dataset = new double[sunspotCount][];

            // read file
            var istream2 = new StreamReader(res);
            CsvReader csv2 = new CsvReader(istream2);

            csv2.Read();

            string[] nextLine;
            int idx = 0;
            while (csv2.Read())
            {
                double ssn = double.Parse(csv2.CurrentRecord[3], CultureInfo.InvariantCulture);
                dataset[idx] = new double[1];
                dataset[idx++][0] = ssn;
            }

            // timseries encode
            IList<BasicData> result = TimeSeriesUtil.SlidingWindow(dataset, this.INPUT_WINDOW, 1, new int[] {0},
                new int[] {0});

            return result;
        }
开发者ID:legendvijay,项目名称:aifh,代码行数:49,代码来源:PredictSunspots.cs

示例6: ImportProductsTest

        public void ImportProductsTest()
        {
            //Auto detect mapping configuration
            var importConfiguration = GetMapConfiguration();


            var csvProducts = new List<CsvProduct>();
            using (var reader = new CsvReader(new StreamReader(@"c:\Projects\VCF\vc-community\PLATFORM\Modules\Catalog\VirtoCommerce.CatalogModule.Test\products.csv")))
            {
                reader.Configuration.Delimiter = ";";
                var initialized = false;
                while (reader.Read())
                {
                    if (!initialized)
                    {
                        importConfiguration.AutoMap(reader.FieldHeaders);
                        reader.Configuration.RegisterClassMap(new CsvProductMap(importConfiguration));
                        initialized = true;
                    }

                    var csvProduct = reader.GetRecord<CsvProduct>();
                    csvProducts.Add(csvProduct);
                }
            };

            var categories = new List<coreModel.Category>();


        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:29,代码来源:ImportExportTest.cs

示例7: FetchShowNamesFromEpGuides

 public ShowInfoCache[] FetchShowNamesFromEpGuides()
 {
     var request = WebRequest.Create("http://epguides.com/common/allshows.txt");
     var response = request.GetResponse();
     using (var r = new StreamReader(response.GetResponseStream()))
     {
         //title,directory,tvrage,start date,end date,number of episodes,run time,network,country
         var parser = new CsvReader(r);
         var ids = new HashSet<string>(); //The datasource is a bit crap so we need to remove their dupes
         var result = new List<ShowInfoCache>();
         while (parser.Read())
         {
             DateTimeOffset d;
             var hasEnded = false;
             if(DateTimeOffset.TryParseExact(
                 parser.GetField("end date"),
                 "MMM yyyy", CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.None, out d))
             {
                 hasEnded = true;
             }
             var id = ShowInfoCache.IdFromSourceId(parser.GetField("tvrage"));
             if (!ids.Contains(id))
                 result.Add(new ShowInfoCache
                                {
                                    Id = id,
                                    Name = parser.GetField("title"),
                                    HasEnded = hasEnded
                                });
             ids.Add(id);
         }
         return result.ToArray();
     }
 }
开发者ID:alundgren,项目名称:alun-tv,代码行数:33,代码来源:EpGuideShowSource.cs

示例8: GetAllMatchesInfo

        public List<MatchData> GetAllMatchesInfo()
        {
            string text = ReadFileAsAnsi(RootFolder + "matches.MAT.csv");
            TextReader reader = new StringReader(text);
            CsvReader csv = new CsvReader(reader);

            List<MatchData> matches = new List<MatchData>();
            while (csv.Read())
            {
                MatchData data = new MatchData();
                data.Title = csv.GetField<string>("Description").Trim();
                data.MatchId = csv.GetField<int>("Matchid");
                data.Date = DateTime.Parse(csv.GetField<string>("Date")); // yyyy-mm-dd
                data.IsClassification = csv.GetField<string>("Classifier") == "Y";
                data.MaxStrings = csv.GetField<int>("Strings");
                data.NumberOfRegisteredShooters = csv.GetField<int>("Registered");
                data.NumberOfStages = csv.GetField<int>("Numstages");
                matches.Add(data);
                matchesInfo.Add(data.MatchId, data);

                //string d = string.Empty;
                //d += "Matchid: " + csv.GetField<string>("Matchid") + "; ";
                //d += "Date: " + csv.GetField<string>("Date") + "; ";
                //d += "Strings: " + csv.GetField<string>("Strings") + "; ";
                //d += "Numstages: " + csv.GetField<string>("Numstages") + "; ";
                //d += "Description: " + csv.GetField<string>("Description") + "; ";
                //d += "Classifier: " + csv.GetField<string>("Classifier") + "; ";
                //d += "Registered: " + csv.GetField<string>("Registered") + "; ";

                //Debug.WriteLine(d);
            }

            return matches;
        }
开发者ID:jernejk,项目名称:ForScore-data-export-tool,代码行数:34,代码来源:CsvDataProvider.cs

示例9: do_it

        public void do_it()
        {
            string path = @"c:\work\id-list.csv";

            using (var reader = new StreamReader(path))
            {
                var csv = new CsvReader(reader);

                csv.Configuration.HasHeaderRecord = false;

                var list = new List<Tuple<string, List<string>>>();

                while (csv.Read())
                {
                    var id = csv.GetField<string>(0);
                    var resourcePaths = csv.CurrentRecord.Skip(1)
                        .Where(value => value.IsNotBlank())
                        .ToList();

                    list.Add(new Tuple<string, List<string>>(id, resourcePaths));
                }

                list.Count.Should().Be(2);
                list[0].Item1.Should().Be("id1");
                list[0].Item2.Should().Contain(@"x:\some\path\2");
            }
        }
开发者ID:jncc,项目名称:topcat,代码行数:27,代码来源:multi_resource_spike.cs

示例10: OnStart

        protected override void OnStart()
        {
            var newBets = new List<Bet>();

            using (TextReader textReader = File.OpenText(_filePath))
            {
                var csv = new CsvReader(textReader);
                while (csv.Read())
                {
                    if (!Running)
                        break;

                    var bet = CreateBet(csv);
                    newBets.Add(bet);

                    if (newBets.Count == _maxBetBatchSize)
                    {
                        OnBetsProvided(new BetsProvidedEventArgs(newBets));
                        newBets.Clear();
                    }
                }

                if (newBets.Any())
                {
                    OnBetsProvided(new BetsProvidedEventArgs(newBets));
                }

                OnBetsProvidedFinished(new BetsProviderFinishedEventArgs());
            }
        }
开发者ID:bambos-xiouros,项目名称:SimpleRiskApplication,代码行数:30,代码来源:CsvBetDataProvider.cs

示例11: TestRead

 public void TestRead()
 {
     CsvRecord[] expected_records =
         {
             new CsvRecord
             {
                 Name = "John Doe",
                 Email = "[email protected]",
                 Department = "Lolailo"
             },
             new CsvRecord
             {
                 Name = "Rita Marley",
                 Email = "[email protected]",
                 Department = "Potheads"
             }
         };
     var reader = new CsvReader(
                      new StreamReader(GetDataStream()));
     var records = reader.Read();
     var pairs = records.Zip(expected_records, Tuple.Create);
     foreach (var p in pairs)
     {
         Assert.AreEqual(p.Item1, p.Item2);
     }
 }
开发者ID:dgquintas,项目名称:my-code-samples,代码行数:26,代码来源:CsvReaderTest.cs

示例12: Parse

        public static List<YahooFinanceApiData> Parse(string csvData)
        {
            var prices = new List<YahooFinanceApiData>();

            var csv = new CsvReader(new StringReader(csvData), new CsvConfiguration { HasHeaderRecord = false });
            while (csv.Read())
            {
                var p = new YahooFinanceApiData
                {
                    Symbol = csv.GetField(0),
                    Name = csv.GetField(1),
                    Bid = csv.GetField(3),
                    Open = csv.GetField(4),
                    PreviousClose = csv.GetField(5),
                    Change = csv.GetField(6),
                    PercentChange = csv.GetField(7),
                    DayLow = csv.GetField(8),
                    DayHigh = csv.GetField(9),
                    AfterHoursChange = csv.GetField(10),
                    WeekRange52 = csv.GetField(11),
                    Volume = csv.GetField(12),
                    PE = csv.GetField(13),
                    LastTradePrice = csv.GetField(14),
                    LastTradeTime = csv.GetField(15),
                    LastTradeDate = csv.GetField(16)
                };
                //.Replace("\"", string.Empty);
                prices.Add(p);
            }

            return prices;
        }
开发者ID:christopherbauer,项目名称:IrcSomeBot,代码行数:32,代码来源:YahooFinanceApi.cs

示例13: Read

        public List<Player> Read()
        {
            string name;
            bool won;
            try
            {
                using (FileStream log = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    using (StreamReader reader = new StreamReader(log))
                    {
                        using (var csvReader = new CsvReader(reader))
                        {
                            while (csvReader.Read())
                            {
                                name = csvReader.GetField<string>(0);
                                won = csvReader.GetField<bool>(1);
                                Player player = new Player(name, won);
                                players.Add(player);
                            }
                        }
                    
                    }
      
                }
                return players;
            }
            catch (Exception)
            {
                Console.WriteLine("Sorry, no scores have been recorded yet");
                return players;
            }

        }
开发者ID:gwenhidwy,项目名称:RockPaperScissors,代码行数:33,代码来源:FileReader.cs

示例14: ImportTranslationsCsv

        public static void ImportTranslationsCsv(DataContext db, CsvReader csv, TranslationArea area)
        {
            while (csv.Read())
            {
                var code = csv.GetField<string>(0);
                var key = csv.GetField<string>(1);
                var value = csv.GetField<string>(2);

                // ToList is called on purpose for case sensitive search
                var translation =
                    db.Translations.ToList().FirstOrDefault(
                        t => t.LanguageCode == code && t.Key == key && t.Area == area);

                if (translation == null)
                {
                    translation = new Translation
                                  {
                                      LanguageCode = code,
                                      Key = key,
                                      Value = value,
                                      Area = area
                                  };
                    db.Translations.Add(translation);
                }
                else
                {
                    translation.Value = value;
                }
            }

            db.SaveChanges();

            TranslationHelper.ClearCache();
        }
开发者ID:alin-rautoiu,项目名称:Cart42,代码行数:34,代码来源:DataImportController.cs

示例15: Consume

        public static void Consume()
        {
            try
            {

                var csvReader = new CsvReader(AppPath + "\\test.csv") {Splitter = ','};
                while (csvReader.Read())
                {
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.DebugFormat(
                            "Found project \"{0}\" for customer \"{1}\" with period {2} to {3} with a budget of {4} hours ({5})",
                            csvReader.GetString("ProjectName"),
                            csvReader.GetString("CustomerName"),
                            csvReader.GetDateTime("StartDate").ToString("r"),
                            csvReader.GetDateTime("EndDate").ToString("r"),
                            csvReader.GetDouble("BudgetHours"),
                            csvReader.GetString("Comment"));
                    }
                }
            }
            catch (Exception ex)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error("Failed to read file", ex);
                }
            }
        }
开发者ID:maxwalter,项目名称:TimeLogApiSdk,代码行数:29,代码来源:ConsumeCsvFile.cs


注:本文中的CsvReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。