public static void ReadAll_LumenWorks(DelimitedRecordReaderBenchmarkArguments args)
        {
            using (var reader = new LW.CsvReader(new StreamReader(args.Path, args.Encoding, true, args.BufferSize), false, LW.CsvReader.DefaultDelimiter, LW.CsvReader.DefaultQuote, LW.CsvReader.DefaultEscape, LW.CsvReader.DefaultComment, args.TrimWhiteSpaces ? LW.ValueTrimmingOptions.All : LW.ValueTrimmingOptions.None, args.BufferSize))
            {
                reader.SkipEmptyLines = args.SkipEmptyLines;

                string s;

                if (args.FieldIndex < 0)
                {
                    while (reader.ReadNextRecord())
                    {
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            s = reader[i];
                        }
                    }
                }
                else
                {
                    while (reader.ReadNextRecord())
                    {
                        for (int i = 0; i < args.FieldIndex + 1; i++)
                        {
                            s = reader[i];
                        }
                    }
                }
            }
        }
		public static void ReadAll_LumenWorks(DelimitedRecordReaderBenchmarkArguments args)
		{
			using (var reader = new LW.CsvReader(new StreamReader(args.Path, args.Encoding, true, args.BufferSize), false, LW.CsvReader.DefaultDelimiter, LW.CsvReader.DefaultQuote, LW.CsvReader.DefaultEscape, LW.CsvReader.DefaultComment, args.TrimWhiteSpaces ? LW.ValueTrimmingOptions.All : LW.ValueTrimmingOptions.None, args.BufferSize))
			{
				reader.SkipEmptyLines = args.SkipEmptyLines;

				string s;

				if (args.FieldIndex < 0)
				{
					while (reader.ReadNextRecord())
					{
						for (int i = 0; i < reader.FieldCount; i++)
							s = reader[i];
					}
				}
				else
				{
					while (reader.ReadNextRecord())
					{
						for (int i = 0; i < args.FieldIndex + 1; i++)
							s = reader[i];
					}
				}
			}
		}
Beispiel #3
0
        private void loadDatabase()
        {
            //read movies.csv
            using (var fs = File.OpenRead(@"db/movies.csv"))
                using (var reader = new StreamReader(fs))
                {
                    using (var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(reader, true))
                    {
                        while (csvReader.ReadNextRecord())
                        {
                            //the first line is the headers line (movieID,Title,genres)
                            Movie movie = new Movie(csvReader[0]);
                            movie.MovieTitle = csvReader[1];
                            movie.Genres     = Movie.splitToGenres(csvReader[2]);
                            moviesDictionary[csvReader[0]] = movie;
                            moviesToGrab.Enqueue(movie);
                        }
                    }
                }

            using (var fs = File.OpenRead(@"db/links.csv"))
                using (var reader = new StreamReader(fs))
                {
                    using (var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(reader, true))
                    {
                        while (csvReader.ReadNextRecord())
                        {
                            if (moviesDictionary.ContainsKey(csvReader[0]))
                            {
                                moviesDictionary[csvReader[0]].UrlLink = "tt" + csvReader[1]; //add the IMDB link
                            }
                        }
                    }
                }
        }
Beispiel #4
0
        private TableInfo GetStructure(LumenWorks.Framework.IO.Csv.CsvReader reader)
        {
            var res = new TableInfo(null);

            if (HasHeaders)
            {
                foreach (string col in reader.GetFieldHeaders())
                {
                    res.Columns.Add(new ColumnInfo(res)
                    {
                        CommonType = new DbTypeString(), DataType = "nvarchar", Name = col
                    });
                }
            }
            else
            {
                for (int i = 1; i <= reader.FieldCount; i++)
                {
                    res.Columns.Add(new ColumnInfo(res)
                    {
                        CommonType = new DbTypeString(), DataType = "nvarchar", Name = String.Format("#{0}", i)
                    });
                }
            }
            return(res);
        }
Beispiel #5
0
 public Nullable <BusStop> getStopInfo(int id)
 {
     using (LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(getReader("stops.txt"), true)) {
         while (csv.ReadNextRecord())
         {
             if (int.Parse(csv["stop_id"]) == id)
             {
                 return(new BusStop(csv["stop_name"], id, new CLLocation(double.Parse(csv["stop_lat"]), double.Parse(csv["stop_lon"]))));
             }
         }
         return(null);
     }
 }
Beispiel #6
0
 //Caution: If radius is too large results will be HUGE!
 //radius in meters
 public IEnumerable<BusStop> getAllBusStops(CLLocation aboutLoc, double radius)
 {
     List<BusStop> stops = new List<BusStop>(30);
     using (LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(getReader("stops.txt"),true)) {
         while (csv.ReadNextRecord()){
             CLLocation loc = new CLLocation(double.Parse(csv["stop_lat"]), double.Parse(csv["stop_lon"]));
             if (loc.DistanceFrom(aboutLoc)<=radius)
                 stops.Add(new BusStop(csv["stop_name"],int.Parse(csv["stop_id"]), loc));
             loc.Dispose();
         }
         return stops;
     }
 }
Beispiel #7
0
        private LumenWorks.Framework.IO.Csv.CsvReader CreateCsvReader(TextReader textReader, string file = null)
        {
            char delim = Delimiter;

            if (file != null && AutoDetectDelimiter)
            {
                delim = DetectDelimiter(file);
            }
            var reader = new LumenWorks.Framework.IO.Csv.CsvReader(textReader, HasHeaders, delim, Quote, Escape, Comment,
                                                                   TrimSpaces ? LumenWorks.Framework.IO.Csv.ValueTrimmingOptions.UnquotedOnly : LumenWorks.Framework.IO.Csv.ValueTrimmingOptions.None);

            reader.DefaultParseErrorAction = ParseErrorAction.AdvanceToNextLine;
            return(reader);
        }
Beispiel #8
0
        public static importOHLCV DoImportRow(LumenWorks.Framework.IO.Csv.CsvReader csv, importStat importStat)
        {
            importOHLCV data = new importOHLCV();

            if (csv[0] == null)
            {
                return(null);
            }
            data.code = csv[0];

            if (!common.dateTimeLibs.Str2Date(csv[1], importStat.dateDataFormat, out tmpDate))
            {
                return(null);
            }
            data.dateTime = tmpDate;

            if (!double.TryParse(csv[2], NumberStyles.Number, importStat.srcCulture, out tmpVal))
            {
                return(null);
            }
            data.Open = tmpVal;

            if (!double.TryParse(csv[3], NumberStyles.Number, importStat.srcCulture, out tmpVal))
            {
                return(null);
            }
            data.High = tmpVal;

            if (!double.TryParse(csv[4], NumberStyles.Number, importStat.srcCulture, out tmpVal))
            {
                return(null);
            }
            data.Low = tmpVal;

            if (!double.TryParse(csv[5], NumberStyles.Number, importStat.srcCulture, out tmpVal))
            {
                return(null);
            }
            data.Close = tmpVal;

            if (!double.TryParse(csv[6], NumberStyles.Number, importStat.srcCulture, out tmpVal))
            {
                return(null);
            }
            data.Volume = tmpVal;
            return(data);
        }
Beispiel #9
0
        //Caution: If radius is too large results will be HUGE!
        //radius in meters
        public IEnumerable <BusStop> getAllBusStops(CLLocation aboutLoc, double radius)
        {
            List <BusStop> stops = new List <BusStop>(30);

            using (LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(getReader("stops.txt"), true)) {
                while (csv.ReadNextRecord())
                {
                    CLLocation loc = new CLLocation(double.Parse(csv["stop_lat"]), double.Parse(csv["stop_lon"]));
                    if (loc.DistanceFrom(aboutLoc) <= radius)
                    {
                        stops.Add(new BusStop(csv["stop_name"], int.Parse(csv["stop_id"]), loc));
                    }
                    loc.Dispose();
                }
                return(stops);
            }
        }
Beispiel #10
0
        public List <SearchParameters> getitems()
        {
            var csvTable = new DataTable();

            using (var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(System.IO.File.OpenRead(inventario_csv)), false))
            {
                csvTable.Load(csvReader);
            }
            List <SearchParameters> Inventario = new List <SearchParameters>();

            for (int i = 0; i < csvTable.Rows.Count; i++)
            {
                Inventario.Add(new SearchParameters {
                    Nombre = csvTable.Rows[i][0].ToString(), Unidad_Kg = csvTable.Rows[i][1].ToString(), Precio = csvTable.Rows[i][2].ToString(), Inventario = csvTable.Rows[i][3].ToString(), Costo = csvTable.Rows[i][4].ToString()
                });
            }
            return(Inventario);
        }
        private void CountActivities(CsvReader csv)
        {
            int fieldCount = csv.FieldCount;

            string[] headers = csv.GetFieldHeaders();
            while (csv.ReadNextRecord())
            {
                string activityName = csv[(int)Fields.ActivityName];
                if (_activityCount.ContainsKey(activityName))
                {
                    _activityCount[activityName]++;
                }
                else
                {
                    _activityCount.Add(activityName, 1);
                }
            }
        }
        private string SerializeCsv(CsvReader csv)
        {
            string results = "";

            int fieldCount = csv.FieldCount;

            string[] headers = csv.GetFieldHeaders();
            while (csv.ReadNextRecord())
            {
                for (int i = 0; i < fieldCount; i++)
                {
                    results += csv[i] + " ";
                }
                results += "\n";
            }

            return(results);
        }
Beispiel #13
0
        public List <VentaParameters> getventas(string fecha)
        {
            //search if day exist
            string[] FilesVenta           = Directory.GetFiles(ruta_ventas);
            List <VentaParameters> ventas = new List <VentaParameters>();
            int count = 0;

            foreach (string Filename in FilesVenta)
            {
                if (Filename == ruta_ventas + fecha + ".csv")
                {
                    var csvTable = new DataTable();
                    using (var csvReader = new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(System.IO.File.OpenRead(ruta_ventas + fecha + ".csv")), false))
                    {
                        csvTable.Load(csvReader);
                    }

                    for (int i = 0; i < csvTable.Rows.Count; i++)
                    {
                        ventas.Add(new VentaParameters {
                            Nombre = csvTable.Rows[i][0].ToString(), Precio = csvTable.Rows[i][1].ToString(), Cantidades = csvTable.Rows[i][2].ToString(), Costo = csvTable.Rows[i][3].ToString(), hora = csvTable.Rows[i][4].ToString(), corte = csvTable.Rows[i][5].ToString()
                        });
                    }
                }
                else
                {
                    count++;
                }
            }
            if (count == FilesVenta.Length)
            {
                List <VentaParameters> ventasinicial = new List <VentaParameters>();
                using (var writer = new StreamWriter(ruta_ventas + fecha + ".csv"))
                    using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                    {
                        csv.WriteRecords(ventasinicial);
                    }
            }
            return(ventas);
        }
        static void ReadCsvFile()
        {
            var csvTable = new DataTable();

            using (var csvReader = new CsvReader(new StreamReader(System.IO.File.OpenRead(@"C:\Users\itay.m\Downloads\SR-5543\MNN2_FAILS.csv")), true))
            {
                csvTable.Load(csvReader);
            }

            var csv = new StringBuilder();

            /*
             * var firstHL = "WebSite";
             * var secondHL = "IP";
             * var thirdHL = "TotalOrderCost";
             * var fourthHL = "ShippingCountry";
             * var fifthHL = "IPLocationName";
             * var sixthHL = "Num ShippingCountry <> Order IP Location";
             * var Headines = string.Format("{0},{1},{2},{3},{4},{5}", firstHL, secondHL, thirdHL, fourthHL, fifthHL, sixthHL);
             *
             * csv.Append(string.Format("{0},{1},{2},{3},{4},{5}", firstHL, secondHL, thirdHL, fourthHL, fifthHL, sixthHL, Environment.NewLine));
             *
             * File.WriteAllText(@"C:\Users\itay.m\Downloads\SR-5543\KR_Get_IP_list_from_customers_10.14.2020_NEW.csv", csv.ToString());   */
            int count = 0;

            for (int i = 0; i < csvTable.Rows.Count; i++)
            {
                Filedatas.Add(new FileData {
                    WebSite         = csvTable.Rows[i][0].ToString(), IP = csvTable.Rows[i][1].ToString(), TotalOrderCost = csvTable.Rows[i][2].ToString(),
                    ShippingCountry = csvTable.Rows[i][3].ToString(), IPLocationName = csvTable.Rows[i][4].ToString()
                });
                if (i == count + 199)
                {
                    Console.WriteLine($"Counter:{i}");
                    count = count + 199;
                }

                try
                {
                    GetLocationIP(Filedatas[i]);
                    Console.WriteLine(Filedatas[i]);
                    var first  = Filedatas[i].WebSite;
                    var second = Filedatas[i].IP;
                    var third  = Filedatas[i].TotalOrderCost;
                    var fourth = Filedatas[i].ShippingCountry;
                    var fifth  = Filedatas[i].IPLocationName;

                    var newLine = string.Format("{0},{1},{2},{3},{4}", first, second, third, fourth, fifth);
                    csv.Append(newLine + Environment.NewLine);
                }
                catch (Exception)
                {
                    var first  = Filedatas[i].WebSite;
                    var second = Filedatas[i].IP;
                    var third  = Filedatas[i].TotalOrderCost;
                    var fourth = Filedatas[i].ShippingCountry;
                    csv.Append(string.Format("{0},{1},{2},{3},fail{4}", first, second, third, fourth, Environment.NewLine));
                    continue;
                }

                File.WriteAllText(@"C:\Users\itay.m\Downloads\SR-5543\EXPORTS\MNN2_FAILS_NEW.csv", csv.ToString());
            }
        }
Beispiel #15
0
 public Nullable<BusStop> getStopInfo(int id)
 {
     using (LumenWorks.Framework.IO.Csv.CsvReader csv = new LumenWorks.Framework.IO.Csv.CsvReader(getReader("stops.txt"),true)) {
         while (csv.ReadNextRecord()){
             if (int.Parse(csv["stop_id"])== id){
                 return new BusStop(csv["stop_name"],id, new CLLocation(double.Parse(csv["stop_lat"]), double.Parse(csv["stop_lon"])));
             }
         }
         return null;
     }
 }