Exemplo n.º 1
0
        private static List<Ticker> LoadTickers()
        {
            string fileName = "/companylist_all.csv";
            string path = HostingEnvironment.MapPath(Path.Combine(new DirectoryInfo(HostingEnvironment.ApplicationPhysicalPath).Parent.Name, fileName));
            List<string[]> parsedData = new List<string[]>();
            using (CsvReader reader = new CsvReader(path))
            {
                foreach (string[] values in reader.RowEnumerator)
                {
                    //if (reader.RowIndex == 1)
                    //{
                    //    // skip header row
                    //    continue;
                    //}

                    parsedData.Add(values);
                }
            }

            // Create list of tickers
            List<Ticker> tmp = new List<Ticker>();
            foreach (var line in parsedData)
            {
                tmp.Add(
                    new Ticker()
                    {
                        Company = line[1],
                        Industry = line[6],
                        Sector = line[5],
                        Symbol = line[0],
                        Exchange = line[8]
                    }
                );
            }

            // sort the list
            var q = from t in tmp
                    orderby t.Symbol
                    select t;
            tmp = q.ToList();

            return tmp;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="BonusProvider" /> class.
        /// </summary>
        /// <param name="stream">The experience bonus stream.</param>
        public BonusProvider(Stream stream)
        {
            using (var csv = new CsvReader(new StreamReader(stream)))
            {
                csv.Configuration.AutoMap<BonusData>();
                csv.Configuration.AllowComments = true;
                csv.Configuration.Delimiter = "\t";
                csv.Configuration.HasHeaderRecord = false;
                csv.Configuration.WillThrowOnMissingField = false;
                csv.Configuration.SkipEmptyRecords = true;

                var records =
                    csv.GetRecords<BonusData>()
                       .Zip(Enum.GetValues(typeof(UnitType)).Cast<UnitType>(),
                            (data, type) => new { BonusData = data, Type = type })
                       .ToArray();

                foreach (var record in records)
                {
                    var bonus = new Bonus
                                {
                                    Initiative = record.BonusData.Initiative / 100.0,
                                    SoftAttack = record.BonusData.SoftAttack / 100.0,
                                    HardAttack = record.BonusData.HardAttack / 100.0,
                                    AirAttack = record.BonusData.AirAttack / 100.0,
                                    NavalAttack = record.BonusData.NavalAttack / 100.0,
                                    GroundDefense = record.BonusData.GroundDefense / 100.0,
                                    AirDefense = record.BonusData.AirDefense / 100.0,
                                    CloseDefense = record.BonusData.CloseDefense / 100.0,
                                    Range = 0.0,
                                    Movement = 0.0,
                                    Spotting = 0.0,
                                };

                    this._boni.Add(record.Type, bonus);
                }
            }
        }
Exemplo n.º 3
0
 public static int ImportCsv(string path)
 {
     var importCounter = 0;
     using (var csv = new CsvReader(new StreamReader(path)))
     {
         csv.Configuration.RegisterClassMap<Models.ComputerCsvMap>();
         var records = csv.GetRecords<Models.Computer>();
         foreach (var computer in records)
         {
             if (AddComputer(computer).IsValid)
                 importCounter++;
         }
     }
     return importCounter;
 }