Beispiel #1
0
        /// <summary>
        /// CSVを読み込み、薬品情報のリストを返す
        /// </summary>
        /// <param name="path">CSVファイルの絶対パス</param>
        /// <returns>薬品情報のリスト</returns>
        static List <Yakuhin> ReadCsv(string path)
        {
            List <Yakuhin> list = new List <Yakuhin>();
            var            enc  = new System.Text.UTF8Encoding(false);

            using (var reader = new System.IO.StreamReader(path, enc))
            {
                var csv = new CsvHelper.CsvReader(reader);
                while (csv.Read())
                {
                    string drugCode = csv.GetField <string>(0);
                    string clsCode  = csv.GetField <string>(1);
                    string clsName  = csv.GetField <string>(2);
                    string drugName = csv.GetField <string>(3);
                    string company  = csv.GetField <string>(4);

                    var yakuhin = new Yakuhin
                    {
                        DrugCode           = drugCode,
                        ClassificationCode = clsCode,
                        ClassificationName = clsName,
                        DrugName           = drugName,
                        Company            = company
                    };

                    list.Add(yakuhin);
                }
            }

            return(list);
        }
Beispiel #2
0
        static DataSet LoadCsv(Gpt2Encoder encoder, string root, string field)
        {
            var texts            = new List <string>();
            var csvConfiguration = new CsvHelper.Configuration.Configuration {
                Delimiter       = ",",
                HasHeaderRecord = true,
            };

            foreach (string file in Directory.EnumerateFiles(root, "*.csv", SearchOption.AllDirectories))
            {
                using var reader = new CsvHelper.CsvReader(new StreamReader(file, Encoding.UTF8), csvConfiguration);
                reader.Read();
                reader.ReadHeader();
                while (reader.Read())
                {
                    string entry = reader.GetField(field);
                    System.Diagnostics.Debug.Assert(reader.GetField(0).Length < 300);
                    if (!string.IsNullOrWhiteSpace(entry))
                    {
                        texts.Add(entry);
                    }
                }
            }
            return(Gpt2Dataset.FromTexts(encoder, texts));
        }
        /// <summary>
        /// CSVを読み込み、薬品情報のリストを返す
        /// </summary>
        /// <param name="path">CSVファイルの絶対パス</param>
        /// <returns>薬品情報のリスト</returns>
        static List<Yakuhin> ReadCsv(string path)
        {
            List<Yakuhin> list = new List<Yakuhin>();
            var enc = new System.Text.UTF8Encoding(false);

            using (var reader = new System.IO.StreamReader(path, enc))
            {
                var csv = new CsvHelper.CsvReader(reader);
                while (csv.Read())
                {
                    string drugCode = csv.GetField<string>(0);
                    string clsCode = csv.GetField<string>(1);
                    string clsName = csv.GetField<string>(2);
                    string drugName = csv.GetField<string>(3);
                    string company = csv.GetField<string>(4);

                    var yakuhin = new Yakuhin
                    {
                        DrugCode = drugCode,
                        ClassificationCode = clsCode,
                        ClassificationName = clsName,
                        DrugName = drugName,
                        Company = company
                    };

                    list.Add(yakuhin);
                }
            }

            return list;
        }
Beispiel #4
0
        public List <Fund> GetFunds(string url)
        {
            var            funds   = new List <Fund>();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        CsvHelper.CsvReader csvReader = new CsvHelper.CsvReader(reader);
                        csvReader.Configuration.HasHeaderRecord = true;

                        csvReader.Read();
                        csvReader.ReadHeader();

                        while (csvReader.Read())
                        {
                            funds.Add(new Fund
                            {
                                Exchange = this.ExchangeName,
                                IsActive = true,
                                Symbol   = csvReader.GetField <string>(0),
                                Name     = csvReader.GetField <string>(1)
                            });
                        }
                    }
                }
            }
            return(funds);
        }
        public void ParseResultCSV(CmsAlbum album)
        {
            var csvFolder = this.GetCSVFolderSoundRecording(album.AlbumCode);

            if (!string.IsNullOrEmpty(csvFolder))
            {
                var reportFilePath = Directory.GetFiles(csvFolder, "report-*");
                if (reportFilePath != null && reportFilePath.Any())
                {
                    using (var streamReader = System.IO.File.OpenText(reportFilePath[0]))
                    {
                        using (var reader = new CsvHelper.CsvReader(streamReader, System.Threading.Thread.CurrentThread.CurrentCulture))
                        {
                            reader.Read();
                            reader.ReadHeader();
                            while (reader.Read())
                            {
                                var isrc    = reader.GetField("ISRC");
                                var assetID = reader.GetField("Asset ID");

                                foreach (var asset in album.Assets)
                                {
                                    if (isrc == asset.ISRC)
                                    {
                                        asset.AssetID = assetID;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        static bool courseHasMoreRecords(CsvHelper.CsvReader reader)
        {
            string courseHeader       = reader.GetField(0);
            string firstFieldOfRecord = reader.GetField(1);
            bool   hasRecordsLeft     = string.IsNullOrEmpty(courseHeader) && !string.IsNullOrEmpty(firstFieldOfRecord);

            return(hasRecordsLeft);
        }
 static void Main()
 {
     // load recods from users csv file
     using (var reader = new StreamReader(Functions.bingPathToAppDir("\\data\\users.csv")))
         using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture))
         {
             csv.Read();
             csv.ReadHeader();
             while (csv.Read())
             {
                 var record = new user
                 {
                     Username    = csv.GetField("Username"),
                     Password    = csv.GetField("Password"),
                     UserType    = csv.GetField("UserType"),
                     Name        = csv.GetField("Name"),
                     Surname     = csv.GetField("Surname"),
                     Phonenumber = csv.GetField("Phonenumber"),
                     Address     = csv.GetField("Address"),
                     Email       = csv.GetField("Email"),
                     Photo       = csv.GetField("Photo")
                 };
                 NoUser = false;
                 Program.records.Add(record);
             }
         }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Login());
 }
Beispiel #8
0
        public void LoadData(DataContainer container)
        {
            if (Domain != null)
            {
                ((CrossDomainDataContainer)container).CurrentDomain = Domain;
            }

            while (_reader.Read())
            {
                // userId, itemId, rating
                container.AddRating(_reader.GetField(0), _reader.GetField(1), float.Parse(_reader.GetField(2)), IsTestReader);
            }
        }
Beispiel #9
0
        private static List <Address> ReadCsv(string path)
        {
            List <Address> list = new List <Address>();
            var            enc  = new System.Text.UTF8Encoding(false);

            using (var reader = new System.IO.StreamReader(path, enc))
            {
                var  csv      = new CsvHelper.CsvReader(reader);
                bool isHeader = true;

                while (csv.Read())
                {
                    if (isHeader)
                    {
                        isHeader = false;
                        continue;
                    }

                    Address item = new Address()
                    {
                        Name          = csv.GetField <string>(0),
                        Kana          = csv.GetField <string>(1),
                        ZipCode       = csv.GetField <string>(4).Replace("-", ""),
                        Prefecture    = csv.GetField <string>(5),
                        StreetAddress = $"{csv.GetField<string>(6)}{csv.GetField<string>(7)}{csv.GetField<string>(8)}{csv.GetField<string>(9)}",
                        Telephone     = csv.GetField <string>(2),
                        Mail          = csv.GetField <string>(3)
                    };
                    list.Add(item);
                }
            }

            return(list);
        }
Beispiel #10
0
        static List <Address> ReadCSV(string path)
        {
            var results = new List <Address>();
            var encode  = new System.Text.UTF8Encoding(false);

            using (var reader = new System.IO.StreamReader(path, encode))
            {
                var csv    = new CsvHelper.CsvReader(reader);
                var isSkip = true;
                while (csv.Read())
                {
                    if (isSkip)
                    {
                        isSkip = false;
                        continue;
                    }

                    var address = new Address
                    {
                        Name          = csv.GetField <string>(0),
                        Kana          = csv.GetField <string>(1),
                        Telephone     = csv.GetField <string>(2),
                        Mail          = csv.GetField <string>(3),
                        ZipCode       = csv.GetField <string>(4).Replace("-", ""),
                        Prefecture    = csv.GetField <string>(5),
                        StreetAddress = $"{csv.GetField<string>(6)}{csv.GetField<string>(7)}{csv.GetField<string>(8)}"
                    };

                    results.Add(address);
                }
            }

            return(results);
        }
Beispiel #11
0
        private static List <Models.CacheIPRange> LoadIPRanges()
        {
            var result = new List <Models.CacheIPRange>();
            var csv    = new CsvHelper.CsvReader(File.OpenText("ranges.csv"));

            while (csv.Read())
            {
                var       ipfrom = csv.GetField(0);
                IPAddress ipaddrfrom;
                if (!IPAddress.TryParse(ipfrom, out ipaddrfrom))
                {
                    break;
                }

                var       ipto = csv.GetField(1);
                IPAddress ipaddrto;
                if (!IPAddress.TryParse(ipfrom, out ipaddrto))
                {
                    break;
                }

                var            fromlist = ipaddrfrom.GetAddressBytes().ToList();
                var            tolist   = ipaddrto.GetAddressBytes().ToList();
                BigMath.Int128 outFrom;
                BigMath.Int128 outTo;
                if (fromlist.Count == 4)
                {
                    outFrom = new BigMath.Int128(BitConverter.ToUInt32(fromlist.Take(4).ToArray(), 0));
                    outTo   = new BigMath.Int128(BitConverter.ToUInt32(tolist.Take(4).ToArray(), 0));
                }
                else
                {
                    outFrom = new BigMath.Int128(BitConverter.ToUInt64(tolist.Take(8).ToArray(), 0), BitConverter.ToUInt64(fromlist.Skip(8).Take(8).ToArray(), 0));
                    outTo   = new BigMath.Int128(BitConverter.ToUInt64(tolist.Take(8).ToArray(), 0), BitConverter.ToUInt64(tolist.Take(8).ToArray(), 0));
                }


                var item = new Models.CacheIPRange
                {
                    IpFrom   = Kres.Man.Models.Int128.Convert(outFrom),
                    IpTo     = Kres.Man.Models.Int128.Convert(outTo),
                    Identity = csv.GetField(2),
                    PolicyId = Convert.ToInt32(csv.GetField(3))
                };
                result.Add(item);
            }

            return(result);
        }
Beispiel #12
0
        public async Task MainAsync()
        {
            string token;

            using (TextReader reader = File.OpenText(@"/root/BPR/secrets.csv"))
            {
                var csv = new CsvHelper.CsvReader(reader);
                csv.Read();
                token = csv.GetField <String>(0);

                csv.Read();
                Globals.conn = new MySqlConnection(csv.GetField <String>(0));
                reader.Close();
            }

            await Globals.InitRegions();

            _client   = new DiscordSocketClient();
            _commands = new CommandService();
            _timer    = new TimerService(_client);

            _client.Log += Log;

            await Globals.tiersNA1.InitTierList();

            await Globals.tiersNA2.InitTierList();

            await Globals.tiersEU1.InitTierList();

            await Globals.tiersEU2.InitTierList();

            await Globals.tiersTEST1.InitTierList();

            await Globals.tiersTEST2.InitTierList();

            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .BuildServiceProvider();

            await InstallCommandsAsync();

            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }
Beispiel #13
0
        public SourceExcel(CsvHelper.CsvReader csvReader)
        {
            string REFE = "";

            TestScript       = csvReader.GetField(cTestScript);
            ScriptStep       = csvReader.GetField(cScriptStep);
            ScriptStepId     = csvReader.GetField <float>(cScriptStepId);
            ResultType       = csvReader.GetField(cResultType);
            StepResultValues = csvReader.GetField(cStepResultValues);
            Section          = csvReader.GetField(cSection);
            Sequence         = csvReader.GetField(cSequence);
            HRAE             = csvReader.GetField(cHRAE);
            ShowComments     = csvReader.GetField(cShowComments);
            CanStepFail      = csvReader.GetField(cCanStepFail);
        }
Beispiel #14
0
        public static DataTable ReadFromCSV(string path, bool hasTitle = false)
        {
            DataTable dt = new DataTable();

            using (TextReader reader = File.OpenText(path))
            {
                var csv = new CsvHelper.CsvReader(reader);

                csv.ReadHeader();

                var headers = csv.FieldHeaders;

                foreach (var header in headers)
                {
                    dt.Columns.Add(header);
                }

                while (csv.Read())
                {
                    var row = dt.NewRow();
                    foreach (DataColumn column in dt.Columns)
                    {
                        row[column.ColumnName] = csv.GetField(column.ColumnName);
                    }

                    dt.Rows.Add(row);
                }
            }

            return(dt);
        }
Beispiel #15
0
 public void ReadCurrentData()
 {
     try
     {
         using (var reader = new StreamReader(FileName))
             using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture))
             {
                 var records = new List <CurencyDataViewModel>();
                 csv.Read();
                 csv.ReadHeader();
                 string[] headerRows = csv.HeaderRecord;
                 while (csv.Read())
                 {
                     var      dateAsString              = csv.GetField(0);
                     DateTime?dateOfCurrencyRate        = dateAsString.GetDateTimeFromString();
                     List <CurencyViewModel> currencies = GetAllCurencies(headerRows, csv);
                     records.Add(new CurencyDataViewModel {
                         DateTimeOf = dateOfCurrencyRate, Curencies = currencies
                     });
                 }
                 CurencyList = records;
             }
     }
     catch (Exception ex) {
         CurencyList = null;
     }
 }
Beispiel #16
0
 public List <CurencyDataViewModel> ReadHistoricalData(string date)
 {
     try
     {
         using (var reader = new StreamReader(HistoricalFileName))
             using (var csv = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture))
             {
                 var records = new List <CurencyDataViewModel>();
                 csv.Read();
                 csv.ReadHeader();
                 string[] headerRows = csv.HeaderRecord;
                 while (csv.Read())
                 {
                     var dateAsString = csv.GetField(0);
                     if (dateAsString == date)
                     {
                         List <CurencyViewModel> currencies = GetAllCurencies(headerRows, csv);
                         return(new List <CurencyDataViewModel>
                         {
                             new CurencyDataViewModel {
                                 DateTimeOf = dateAsString.GetDateTimeFromString(),
                                 Curencies = currencies
                             }
                         });
                     }
                 }
                 return(null);
             }
     }
     catch (Exception ex) {
         return(null);
     }
 }
        static double[,] read_data(string file, int rows, int cols)
        {
            var csv = new CsvHelper.CsvReader(new StreamReader(file));

            csv.Configuration.HasHeaderRecord = false;
            double[,] data = new double[rows, cols];

            Console.WriteLine("Reading {0}... rows={1}, cols={2}", file, rows, cols);
            for (int i = 0; i < rows; i++)
            {
                if (!csv.Read())
                {
                    break;
                }
                if (i % 100 == 0)
                {
                    Console.WriteLine("Reading {0}... {1}", file, i);
                }
                for (int j = 0; j < cols; j++)
                {
                    try
                    {
                        data[i, j] = Double.Parse(csv.GetField(j));
                    }
                    catch (CsvHelper.CsvMissingFieldException e)
                    {
                        Console.WriteLine("read_data: " + a2s(np.row(data, i)));
                        break;
                    }
                }
            }
            Console.WriteLine("Reading {0}... done.", file);
            return(data);
        }
Beispiel #18
0
        public string Readfile(string infil, DateTime refdatum)
        {
            string MessageResult = "OK";

            try
            {
                using (var fileReader = File.OpenText(infil))
                {
                    using (var csv = new CsvHelper.CsvReader(fileReader))
                    {
                        csv.Configuration.Delimiter = ";";

                        while (csv.Read())
                        {
                            string strKonto  = csv.GetField <string>("Konto");
                            string strBelopp = csv.GetField <string>("Belopp");
                            if (!(decimal.TryParse(strBelopp, out decimal decBelopp)))
                            {
                                throw new ImportFileFormatException();
                            }
                            DateTime    dtDatum = csv.GetField <DateTime>("Datum");
                            string      strBank = csv.GetField <string>("Bank");
                            Transaction trans   = new Transaction(strBank, strKonto, dtDatum, strBelopp, refdatum);
                            translista.Add(trans);
                        }
                    }
                }
            }
            catch (IOException e)
            {
                MessageResult = "Ett fel förekom när filen skulle läsas in." + e.Message;
            }

            catch (ImportFileFormatException)
            {
                MessageResult = "Ett fel förekom när filen skulle läsas in, beloppfältet har fel format.";
            }

            catch (Exception e)
            {
                MessageResult = e.Message;
            }


            return(MessageResult);
        }
Beispiel #19
0
        public async IAsyncEnumerable <string[]> ReadAsync()
        {
            using var stream       = this.fileSystem.File.Open(@"Resources\karttimes.csv", FileMode.Open);
            using var streamReader = new StreamReader(stream);
            using var csvReader    = new CsvHelper.CsvReader(streamReader, new CsvConfiguration(CultureInfo.InvariantCulture)
            {
                HasHeaderRecord = true
            });

            await csvReader.ReadAsync().ConfigureAwait(false);

            csvReader.ReadHeader();
            while (await csvReader.ReadAsync().ConfigureAwait(false))
            {
                yield return(new[] { csvReader.GetField <string>("kart"), csvReader.GetField <string>("passingtime") });
            }
        }
Beispiel #20
0
        public IList <Nutrition> Parse(string fileName, NutrientType nutrientType1, NutrientType nutrientType2, NutrientType nutrientType3)
        {
            var result = new List <Nutrition>();

            using (var file = File.OpenText(fileName))
            {
                var csv = new CsvHelper.CsvReader(file);
                while (csv.Read())
                {
                    var     id = csv.GetField <string>(0);
                    var     name = csv.GetField <string>(1);
                    var     nutrient1Str = csv.GetField <string>(2);
                    var     nutrient2Str = csv.GetField <string>(3);
                    var     nutrient3Str = csv.GetField <string>(4);
                    var     nutrients = new List <Nutrient>();
                    decimal nutrient1, nutrient2, nutrient3;
                    if (decimal.TryParse(nutrient1Str, out nutrient1))
                    {
                        nutrients.Add(new Nutrient {
                            Grams = nutrient1, Type = nutrientType1
                        });
                    }
                    if (decimal.TryParse(nutrient2Str, out nutrient2))
                    {
                        nutrients.Add(new Nutrient {
                            Grams = nutrient2, Type = nutrientType2
                        });
                    }
                    if (decimal.TryParse(nutrient3Str, out nutrient3))
                    {
                        nutrients.Add(new Nutrient {
                            Grams = nutrient3, Type = nutrientType3
                        });
                    }

                    result.Add(new Nutrition
                    {
                        Id        = id,
                        Name      = name,
                        Nutrients = nutrients
                    });
                }
            }

            return(result);
        }
Beispiel #21
0
        private void cmdImport_Click(object sender, EventArgs e)
        {
            var dlg = new OpenFileDialog()
            {
                DefaultExt = "csv", Filter = "Pliki csv (*.csv)|*.csv|Wszystkie pliki (*.*)|*.*"
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                NewUsers = new List <User>();
                using (var R = new CsvHelper.CsvReader(File.OpenText(dlg.FileName)))
                {
                    while (R.Read())
                    {
                        var U = new User();
                        U.Login     = R.GetField("Login");
                        U.LastName  = R.GetField("Nazwisko");
                        U.FirstName = R.GetField("Imię");
                        U.Status    = R.GetField <User.UserStatus>("Status");
                        U.Role      = R.GetField <User.UserRole>("Rola");
                        U.Email     = R.GetField("E-mail");
                        U.Sex       = R.GetField <User.UserSex>("Płeć");

                        NewUsers.Add(U);
                    }
                }
                GetData(olvUser);
            }
        }
Beispiel #22
0
        /// <summary>
        /// This method reads student collection from given file.
        /// </summary>
        /// <param name="filePath">Path to .csv file.</param>
        /// <returns>Student collection.</returns>
        public static IEnumerable <Student> Read(string filePath)
        {
            using var reader = new StreamReader(filePath);
            using var csv    = new CsvHelper.CsvReader(reader, CultureInfo.InvariantCulture);

            var records = new List <Student>();

            csv.Read();
            csv.ReadHeader();

            var subjectNames = csv.Context.HeaderRecord.Skip(PersonalInfoCount).ToList();

            while (csv.Read())
            {
                var studentInfo = new Student
                {
                    FirstName  = csv.GetField <string>(0),
                    LastName   = csv.GetField <string>(1),
                    MiddleName = csv.GetField <string>(2),
                };

                var recordFieldCount = csv.Context.Record.Length - PersonalInfoCount;

                if (subjectNames.Count() != recordFieldCount)
                {
                    throw new ArgumentException("Invalid marks count");
                }

                var subjects = new List <Exam>();

                subjectNames.ForEach(
                    name => subjects.Add(
                        new Exam()
                {
                    Subject = name,
                    Mark    = csv.GetField <int>(name),
                }));

                studentInfo.Exams = subjects;

                records.Add(studentInfo);
            }

            return(records.ToList());
        }
Beispiel #23
0
        private static List <Models.CachePolicy> LoadPolicies()
        {
            var result = new List <Models.CachePolicy>();
            var csv    = new CsvHelper.CsvReader(File.OpenText("policy.csv"));

            while (csv.Read())
            {
                var item = new Models.CachePolicy
                {
                    Policy_id = Convert.ToInt32(csv.GetField(0)),
                    Strategy  = Convert.ToInt32(csv.GetField(1)),
                    Audit     = Convert.ToInt32(csv.GetField(2)),
                    Block     = Convert.ToInt32(csv.GetField(3)),
                };
                result.Add(item);
            }

            return(result);
        }
Beispiel #24
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (!fuImportFile.HasFile)
            {
                return;
            }

            var filePath     = FoldersHelper.GetPathAbsolut(FolderType.PriceTemp);
            var fileName     = "redirectsImport.csv";
            var fullFileName = filePath + fileName.FileNamePlusDate();

            FileHelpers.CreateDirectory(filePath);

            fuImportFile.SaveAs(fullFileName);

            using (var csvReader = new CsvHelper.CsvReader(new StreamReader(fullFileName), new CsvConfiguration()
            {
                Delimiter = ";"
            }))
            {
                while (csvReader.Read())
                {
                    var currentRecord = new RedirectSeo
                    {
                        RedirectFrom = csvReader.GetField <string>("RedirectFrom"),
                        RedirectTo   = csvReader.GetField <string>("RedirectTo"),
                        ProductArtNo = csvReader.GetField <string>("ProductArtNo")
                    };

                    var redirect = RedirectSeoService.GetRedirectsSeoByRedirectFrom(currentRecord.RedirectFrom);

                    if (redirect == null)
                    {
                        RedirectSeoService.AddRedirectSeo(currentRecord);
                    }
                    else
                    {
                        currentRecord.ID = redirect.ID;
                        RedirectSeoService.UpdateRedirectSeo(currentRecord);
                    }
                }
            }
        }
Beispiel #25
0
        private void ParseCSV(string input)
        {
            using (TextReader tr = File.OpenText(input))
            {
                var csv = new CsvHelper.CsvReader(tr);
                csv.Configuration.IgnoreHeaderWhiteSpace = true;

                while (csv.Read())
                {
                    FScoreStock fss = new FScoreStock();
                    fss.Ticker    = csv.GetField <string>(0);
                    fss.Name      = csv.GetField <string>(1);
                    fss.Sector    = csv.GetField <string>(2);
                    fss.Industry  = csv.GetField <string>(3);
                    fss.LastPrice = csv.GetField <string>(6);

                    _list.Add(fss);
                }
            }
        }
Beispiel #26
0
        private static List <Models.CacheCustomList> LoadCustomLists()
        {
            var result = new List <Models.CacheCustomList>();
            var csv    = new CsvHelper.CsvReader(File.OpenText("custom.csv"));

            while (csv.Read())
            {
                var item = new Models.CacheCustomList
                {
                    Identity  = csv.GetField(0),
                    WhiteList = csv.GetField(1).Split(';'),
                    BlackList = csv.GetField(2).Split(';'),
                    PolicyId  = Convert.ToInt32(csv.GetField(3))
                };

                result.Add(item);
            }

            return(result);
        }
Beispiel #27
0
        /// <summary>
        /// Czytnik plików CSV, wykorzystujący bibliotekę CsvHelper
        /// </summary>
        public InMemoryDatabase csvReader(String path)
        {
            using (var reader = new StreamReader(path))
                using (var csv = new CsvHelper.CsvReader(reader))
                {
                    // csv.Configuration.RegisterClassMap<OrderMapper>();
                    csv.Configuration.HasHeaderRecord = true;
                    // csv.Configuration.MissingFieldFound = null;
                    csv.Configuration.Delimiter = ",";
                    csv.Read();
                    csv.ReadHeader();

                    while (csv.Read())
                    {
                        String pricestr = csv.GetField <String>("Price");
                        Double price    = Double.Parse(pricestr.Replace('.', ','));
                        database.createOrder(csv.GetField <String>("Client_Id"), csv.GetField <ulong>("Request_id"), csv.GetField <String>("Name"), csv.GetField <uint>("Quantity"), price);
                    }
                }
            return(database);
        }
        public IQuotesDalGetTimeseriesValuesResult GetTimseriesValues(IQuotesDalGetTimeSeriesValuesParams getQuotesParams)
        {
            IQuotesDalGetTimeseriesValuesResult result = new QuotesDalCSVGetQuotesResult();

            foreach (var t in getQuotesParams.Tickers)
            {
                string fileName = t + "." + getQuotesParams.TimeFrame.ToString() + ".csv";
                string filePath = Path.Combine(_rootFolder, getQuotesParams.Country, fileName);

                if (File.Exists(filePath))
                {
                    using (StreamReader sr = new StreamReader(new FileStream(filePath, FileMode.Open)))
                    {
                        IQuotesData data = new BaseQuotesData();
                        data.Ticker    = t;
                        data.TimeFrame = getQuotesParams.TimeFrame;
                        data.Country   = getQuotesParams.Country;

                        using (CsvHelper.CsvReader reader = new CsvHelper.CsvReader(sr))
                        {
                            reader.Read();
                            reader.ReadHeader();
                            while (reader.Read())
                            {
                                ITimeSeriesRecord record = new BaseQuotesRecord();
                                record.Time      = reader.GetField <DateTime>("Time");
                                record["Open"]   = reader.GetField <decimal>("Open");
                                record["High"]   = reader.GetField <decimal>("High");
                                record["Low"]    = reader.GetField <decimal>("Low");
                                record["Close"]  = reader.GetField <decimal>("Close");
                                record["Volume"] = reader.GetField <decimal>("Volume");

                                if (record.Time <= getQuotesParams.PeriodEnd && record.Time >= getQuotesParams.PeriodStart)
                                {
                                    data.AddRecord(record);
                                }
                            }
                        }

                        result.Quotes.Add(data);
                    }
                }
                else
                {
                    result.AddError(Interfaces.EErrorCodes.QuotesNotFound, Interfaces.EErrorType.Warning, string.Format("Quotes not found: {0}, {1}", t, getQuotesParams.TimeFrame));
                }
            }

            if (result.Quotes.Count == 0 && getQuotesParams.Tickers.Count != 0)
            {
                result.Success = false;
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
Beispiel #29
0
        /// <summary>
        /// Delete customer from file. File must contain the CustomerCid from CSP
        /// </summary>
        /// <param name="filename">Path of csv file contain customers to delete</param>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        internal static void DeleteCustomers(string filename, string defaultDomain, string appId, string key, string resellerMicrosoftId)
        {
            GetTokens(defaultDomain, appId, key, resellerMicrosoftId);

            using (var reader = new CsvHelper.CsvReader(new StreamReader(filename)))
            {
                while (reader.Read())
                {
                    string displayName    = reader.GetField <string>("displayName");
                    string cspCustomerCid = reader.GetField <string>("cspCustomerCid");
                    if (cspCustomerCid.Trim().Length == 0)
                    {
                        Console.WriteLine("Unable to delete {0} because CustomerCid is missing.", displayName);
                    }
                    else
                    {
                        Console.WriteLine("Deleting {0}", displayName);
                        Customer.DeleteCustomer(resellerCid, cspCustomerCid, saAuthorizationToken.AccessToken);
                    }
                }
            }
        }
Beispiel #30
0
        private void ParseCsv(string filePath, string fileName, IniParser.Model.IniData iniData, int keyIndex, List <int> listValueIndex)
        {
            iniData.Sections.AddSection(fileName);

            var csv = new CsvHelper.CsvReader(File.OpenText(filePath));

            while (csv.Read())
            {
                var key = csv.GetField(keyIndex);
                foreach (var valueIndex in listValueIndex)
                {
                    var value = csv.GetField(valueIndex);
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        if (!string.IsNullOrWhiteSpace(key))
                        {
                            iniData.Sections.GetSectionData(fileName).Keys.AddKey(valueIndex + "@" + fileName + "@" + key, value.SurroundWithQuotes());
                        }
                    }
                }
            }
        }
Beispiel #31
0
 static void Main4(string[] args)
 {
     using (var reader = new CsvHelper.CsvReader(new System.IO.StringReader("column1,column2\n001,33\navb,aa\n")))
     {
         reader.Read();
         reader.ReadHeader();
         while (reader.Read())
         {
             var s = reader.GetField(1);
             var t = reader.Context.HeaderRecord;
         }
     }
 }
Beispiel #32
0
        public static List<Users.User> getStudents()
        {
            CsvHelper.CsvReader reader;
            List<Users.User> userList = new List<Users.User>();

            reader = new CsvHelper.CsvReader(File.OpenText("student_accounts.csv"));

            while (reader.Read())
            {
                string TNumber = reader.GetField<string>("T_NUMBER");
                string firstName = reader.GetField<string>("FIRSTNAME");
                string lastName = reader.GetField<string>("LAST_NAME");
                string userName = reader.GetField<string>("USERNAME");
                string Email = reader.GetField<string>("EMAILADDRESS");
                long secretKey = reader.GetField<long>("CHECK-N ID");

                userList.Add(new Users.StudentWorker(firstName, lastName, TNumber, secretKey, userName, Email, 110));
            }

            return userList;
        }
        //********************
        //*                  *
        //*  UploadEntities  *
        //*                  *
        //********************
        // Upload a collection of entities from a local file in a selected download format.

        private void UploadEntities(String tableName, String format, String inputFile, String outerElementName, String partitionKeyColumnName, String rowKeyColumnName, bool stopOnError)
        {
            int recordNumber = 1;
            int recordsAdded = 0;
            int recordErrors = 0;
            String serializationError = null;

            String xpath = outerElementName;

            // Create task action.

            String message = null;

            message = "Uploading entities to table " + tableName + " from file " + inputFile;

            Action action = new Action()
            {
                Id = NextAction++,
                ActionType = Action.ACTION_DOWNLOAD_ENTITIES,
                IsCompleted = false,
                Message = message
            };
            Actions.Add(action.Id, action);

            UpdateStatus();

            // Execute background task to perform the downloading.

            Task task = Task.Factory.StartNew(() =>
            {
                CloudTable table = tableClient.GetTableReference(tableName);
                //table.CreateIfNotExists();

                // Upload data using the specified format (csv, json, or xml).

                switch (format)
                {
                    case "json":
                        {
                            // JSON format upload

                            //  {
                            //    "Entities": [
                            //        {
                            //            "RowKey": "Batman",
                            //            "PartitionKey": "DC Comics",
                            //            "Timestamp": "8/6/2014 4:07:06 AM +00:00",
                            //            "Debut": "5/1/1939 12:00:00 AM",
                            //            "SecretIdentity": "Bruce Wayne"
                            //        },
                            //        {
                            //            "RowKey": "Green Lantern",
                            //            "PartitionKey": "DC Comics",
                            //            "Timestamp": "8/6/2014 4:10:52 AM +00:00",
                            //            "Debut": "7/1/1940 12:00:00 AM",
                            //            "SecretIdentity": "Hal Jordan"
                            //        },
                            //        ...
                            //    ]
                            //}

                            Dictionary<String, Object> entries = null;

                            // Parse the data in the JavaScriptSerializer.

                            try
                            {
                                JavaScriptSerializer ser = new JavaScriptSerializer();
                                entries = ser.DeserializeObject(File.ReadAllText(inputFile)) as Dictionary<String, Object>;
                            }
                            catch (Exception ex)
                            {
                                serializationError = "An error occurred deserializing the JSON file: " + ex.Message;
                            }

                            // Walk the result object graph and extract entities.

                            if (entries != null)
                            {
                                foreach (KeyValuePair<String, Object> entry in entries)
                                {
                                    if (entry.Key == outerElementName)
                                    {
                                        Object[] entities = entry.Value as Object[];

                                        foreach (object ent in entities)
                                        {
                                            if (ent is Dictionary<String, Object>)
                                            {
                                                if (WriteEntity(tableName, ent as Dictionary<String, Object>, partitionKeyColumnName, rowKeyColumnName))
                                                {
                                                    recordsAdded++;
                                                    recordNumber++;
                                                }
                                                else
                                                {
                                                    recordErrors++;
                                                    if (stopOnError)
                                                    {
                                                        recordNumber++;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    case "xml":
                        {
                            // XML format upload

                            XmlDocument doc = null;

                            try
                            {
                                doc = new XmlDocument();
                                doc.LoadXml(File.ReadAllText(inputFile));

                                //foreach (XmlElement entities in doc.DocumentElement.GetElementsByTagName(outerElementName))

                                XmlNodeList nodes = doc.DocumentElement.SelectNodes(xpath);
                                //foreach (XmlElement entities in doc.DocumentElement)
                                foreach (XmlElement entities in nodes)
                                {
                                    //<Entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                                    //  <Entity>
                                    //    <RowKey>Batman</RowKey>
                                    //    <PartitionKey>DC Comics</PartitionKey>
                                    //    <Timestamp>8/6/2014 4:07:06 AM +00:00</Timestamp>
                                    //    <Debut>5/1/1939 12:00:00 AM</Debut>
                                    //    <SecretIdentity>Bruce Wayne</SecretIdentity>
                                    //  </Entity>

                                    List<String> columns = new List<string>();
                                    List<String> values = new List<string>();

                                    foreach (XmlElement entity in entities.ChildNodes) // .GetElementsByTagName("Entity"))
                                    //foreach (XmlElement entity in entities.GetElementsByTagName(outerElementName))
                                    {
                                        foreach (XmlNode field in entity.ChildNodes)
                                        {
                                            if (field is XmlText)
                                            {
                                                XmlText node = field as XmlText;
                                                columns.Add(node.ParentNode.Name);
                                                values.Add(node.Value);
                                            }
                                        }
                                    }

                                    if (WriteEntity(tableName, columns.ToArray(), values.ToArray(), partitionKeyColumnName, rowKeyColumnName))
                                    {
                                        recordsAdded++;
                                        recordNumber++;
                                    }
                                    else
                                    {
                                        recordErrors++;
                                        if (stopOnError)
                                        {
                                            recordNumber++;
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                serializationError = "An error occurred parsing the XML file: " + ex.Message;
                            }
                        }
                        break;
                    case "csv":
                        {
                            // CSV format upload. Uses CsvHelper from http://joshclose.github.io/CsvHelper/.

                            try
                            { 
                            using (TextReader reader = File.OpenText(inputFile))
                            {
                                var csv = new CsvHelper.CsvReader(reader);
                                String[] columns = null;
                                String[] values = null;

                                while(csv.Read())
                                {
                                    // If first pass, retrieve column names.

                                    if (recordNumber == 1)
                                    {
                                        columns = csv.FieldHeaders;
                                        values = new String[columns.Length];
                                    }
                                    recordNumber++;

                                    // Retrieve record values.

                                    int col = 0;
                                    foreach (String column in columns)
                                    {
                                        values[col] = csv.GetField(column);
                                        col++;
                                    }

                                    // Write entity.

                                    if (WriteEntity(tableName, columns, values, partitionKeyColumnName, rowKeyColumnName))
                                    {
                                        recordsAdded++;
                                        recordNumber++;
                                    }
                                    else
                                    {
                                        recordErrors++;
                                        if (stopOnError)
                                        {
                                            recordNumber++;
                                            break;
                                        }
                                    }
                                }
                            }
                            }
                            catch (Exception ex)
                            {
                                serializationError = "An error occurred parsing the CSV file: " + ex.Message;
                            }
                        }
                        break;
                    default:
                        ShowError("Cannot upload - unknown format '" + format + "'");
                        break;
                }

                Actions[action.Id].IsCompleted = true;
            });

            // Task complete - update UI.

            task.ContinueWith((t) =>
            {
                if (serializationError != null)
                {
                    ShowError(serializationError);
                }

                switch (recordErrors)
                {
                    case 0:
                        break;
                    case 1:
                        ShowError("An error occurred inserting entity nunber " + (recordNumber-1).ToString() + ".");
                        break;
                    default:
                        ShowError(recordErrors.ToString() + " errors occurred inserting entities.");
                        break;
                }
                UpdateStatus();
                ShowTableContainer(SelectedTableContainer);

            }, TaskScheduler.FromCurrentSynchronizationContext());

        }
Beispiel #34
0
 public static void LoadStellarClasses()
 {
     using(var stream = new System.IO.StreamReader(StellarClassDefinitionFile))
     {
         var csvReader = new CsvHelper.CsvReader(stream);
         // skip 2 header rows
         csvReader.ReadHeader();
         csvReader.Read();
         while (csvReader.Read())
         {
             var item = new StarClass
             {
                 Name = csvReader.GetField(0),
                 Mass = csvReader.GetField<double>(1),
                 Luminosity = csvReader.GetField<double>(2),
                 Radius = csvReader.GetField<double>(3),
                 Temperature = csvReader.GetField<double>(4),
                 ColorIndex = csvReader.GetField<float>(5),
                 AbsoluteMagnitude = csvReader.GetField<float>(6),
                 BolometricCorrection = csvReader.GetField<float>(7),
                 BolometricMagnitude = csvReader.GetField<float>(8),
             };
             var rgb = csvReader.GetField(9).Split(' ').Select(s => byte.Parse(s)).ToArray();
             item.Color = new Color(rgb[0], rgb[1], rgb[2]);
             StellarDefinitions[item.Name] = item;
         }
     }
 }
        /// <summary>
        /// Delete customer from file. File must contain the CustomerCid from CSP
        /// </summary>
        /// <param name="filename">Path of csv file contain customers to delete</param>
        /// <param name="defaultDomain">default domain of the reseller</param>
        /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param>
        /// <param name="key">Key for this application in Azure Active Directory</param>
        /// <param name="resellerMicrosoftId">Microsoft Id of the reseller</param>
        internal static void DeleteCustomers(string filename, string defaultDomain, string appId, string key, string resellerMicrosoftId)
        {
            GetTokens(defaultDomain, appId, key, resellerMicrosoftId);

            using (var reader = new CsvHelper.CsvReader(new StreamReader(filename)))
            {
                while (reader.Read())
                {
                    string displayName = reader.GetField<string>("displayName");
                    string cspCustomerCid = reader.GetField<string>("cspCustomerCid");
                    if (cspCustomerCid.Trim().Length == 0)
                        Console.WriteLine("Unable to delete {0} because CustomerCid is missing.", displayName);
                    else
                    {
                        Console.WriteLine("Deleting {0}", displayName);
                        Customer.DeleteCustomer(resellerCid, cspCustomerCid, saAuthorizationToken.AccessToken);
                    }
                }

            }
        }
Beispiel #36
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="outputDirectory"></param>
        private void ProcessAttachmentHashes(string outputDirectory)
        {
            if (File.Exists(System.IO.Path.Combine(outputDirectory, "Attachment.Hashes.csv")) == false)
            {
                OnError("Cannot locate the \"Attachment.Hashes.csv\" files");
                return;
            }

            CsvConfiguration csvConfig = new CsvConfiguration();

            Regex regex = new Regex("<(.*?)>", RegexOptions.IgnoreCase);
            using (StreamReader sr = new StreamReader(System.IO.Path.Combine(outputDirectory, "Attachment.Hashes.csv")))
            using (CsvHelper.CsvReader csvReader = new CsvHelper.CsvReader(sr, csvConfig))
            {
                List<Attachment> attachments = new List<Attachment>();
                while (csvReader.Read())
                {
                    var md5 = csvReader.GetField(0);
                    var file = csvReader.GetField(1);
                    var fileName = System.IO.Path.GetFileName(file);
                    var srcIp = csvReader.GetField(2);
                    var srcPort = csvReader.GetField(3);
                    var dstIp = csvReader.GetField(4);
                    var dstPort = csvReader.GetField(5);
                    var to = csvReader.GetField(6);
                    var dateSent = csvReader.GetField(11);

                    List<string> tempTo = new List<string>(to.Split(','));
                    for (int index = tempTo.Count() - 1; index > -1; index--)
                    {
                        string person = tempTo[index].Trim().ToLower();
                        if (person.IndexOf("@") == -1)
                        {
                            tempTo.RemoveAt(index);
                            continue;
                        }

                        Match match = regex.Match(person);
                        if (match.Success == true)
                        {
                            person = match.Groups[1].Value;
                        }

                        person = person.Replace(@"""", string.Empty);

                        tempTo[index] = person;
                    }

                    var from = csvReader.GetField(6);
                    var sender = csvReader.GetField(7);
                    var subject = csvReader.GetField(10);

                    var attachment = (from a in attachments where a.Md5 == md5.ToLower() select a).SingleOrDefault();
                    if (attachment == null)
                    {
                        attachment = new Attachment();
                        attachment.Md5 = md5.ToLower();
                        attachment.Recipients.AddRange(tempTo);
                        attachment.Subjects.Add(subject);
                        attachment.Senders.Add(sender);
                        if (fileName.Length > 0)
                        {
                            attachment.FileNames.Add(fileName);
                        }
                        attachment.DateSent = dateSent;
                        attachments.Add(attachment);

                        SubjectRecipents subjectRecipient = new SubjectRecipents();
                        subjectRecipient.Subject = subject;
                        subjectRecipient.File = file;
                        subjectRecipient.Sender = sender;

                        foreach (string person in tempTo)
                        {
                            subjectRecipient.Recipients.Add(person);
                        }

                        attachment.SubjectRecipents.Add(subjectRecipient);
                    }
                    else
                    {
                        foreach (string person in tempTo)
                        {
                            var tempPerson = from r in attachment.Recipients where r == person select r;
                            if (tempPerson.Any() == false)
                            {
                                attachment.Recipients.Add(person);
                            }
                        }

                        var tempFileName = from s in attachment.FileNames where s == fileName select s;
                        if (tempFileName.Any() == false)
                        {
                            attachment.FileNames.Add(fileName);
                        }

                        var tempSubject = from s in attachment.Subjects where s.ToLower() == subject select s;
                        if (tempSubject.Any() == false)
                        {
                            attachment.Subjects.Add(subject);
                        }

                        var tempSender = from s in attachment.Senders where s.ToLower() == sender select s;
                        if (tempSender.Any() == false)
                        {
                            attachment.Senders.Add(sender);
                        }

                        var subjectRecipient = (from s in attachment.SubjectRecipents where s.Subject.ToLower() == subject.ToLower() select s).SingleOrDefault();
                        if (subjectRecipient == null)
                        {
                            subjectRecipient = new SubjectRecipents();
                            subjectRecipient.Subject = subject;
                            subjectRecipient.File = file;
                            subjectRecipient.Sender = sender;

                            foreach (string person in tempTo)
                            {
                                subjectRecipient.Recipients.Add(person);
                            }

                            attachment.SubjectRecipents.Add(subjectRecipient);
                        }
                        else
                        {
                            foreach (string person in tempTo)
                            {
                                var tempPerson = from r in subjectRecipient.Recipients where r == person select r;
                                if (tempPerson.Any() == false)
                                {
                                    subjectRecipient.Recipients.Add(person);
                                }
                            }
                        }
                    }
                }

                OutputSummary(outputDirectory, attachments);
            }
        }