示例#1
0
        public int ToGetDataFromCSVFile()
        {
            try
            {
                string pa     = cSVBuilder.Path;
                char   del    = cSVBuilder.Delimeter;
                string header = cSVBuilder.Header;


                int count = CSVOperations.CountRecords(cSVBuilder.Records);
                return(count);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Sorts the CSV file write in json and return number of states sorted.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="jsonFilepath">The json filepath.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static int SortCSVFileOnNumberAndWriteInJsonAndReturnNumberOfStatesSorted(string filePath, string jsonFilepath, string key)
        {
            string        re = File.ReadAllText(filePath);
            StringBuilder sb = new StringBuilder();

            using (var p = ChoCSVReader.LoadText(re)
                           .WithFirstLineHeader()
                   )
            {
                using (var w = new ChoJSONWriter(sb))
                    w.Write(p);
            }
            File.WriteAllText(jsonFilepath, sb.ToString());
            int count = CSVOperations.SortJsonBasedOnKeyAndReturnNumberOfStatesSorted(jsonFilepath, key);

            return(count);
        }
示例#3
0
        static void Main(string[] args)
        {
            /*Console.WriteLine( StateCensusAnalyser.GetRecordsFromCSVFile(path));
             * Console.WriteLine(CSVStateCensus.ToGetDataFromCSVFileUsigEnumerator(path));*/
            // var fi = CSVStateCensus.ToGetDataFromCSVFile(path);
            //Console.WriteLine(fi);

            /* string stateCensusData = StateCensusAnalyser.SortStateCodeandWriteInJson(CsvStateCensuspath, jsonCsvStateCensuspath, "State");
             * string stateCode = StateCensusAnalyser.SortStateCodeandWriteInJson(CsvStateCodePath, jsonCsvStateCodepath, "StateCode");
             *
             * Console.WriteLine(stateCensusData);
             * Console.WriteLine(stateCode);
             */
            string val = CSVOperations.RetriveFirstDataOnKey(jsonCsvStateCensuspath, "State");
            string lat = CSVOperations.RetriveLastDataOnKey(jsonCsvStateCensuspath, "State");

            Console.WriteLine(val);
            Console.WriteLine(lat);
        }
示例#4
0
        public static string SortCSVFileOnNumbersAndWriteInJsonAndReturnData(string filePath, string jsonFilepath, string key)
        {
            string        re = File.ReadAllText(filePath);
            StringBuilder sb = new StringBuilder();

            using (var p = ChoCSVReader.LoadText(re)
                           .WithFirstLineHeader()
                   )
            {
                using (var w = new ChoJSONWriter(sb))
                    w.Write(p);
            }
            File.WriteAllText(jsonFilepath, sb.ToString());
            JArray arr     = CSVOperations.SortJsonBasedOnKeyAndValueIsNumber(jsonFilepath, key);
            var    jsonArr = JsonConvert.SerializeObject(arr, Formatting.Indented);

            File.WriteAllText(jsonFilepath, jsonArr);

            return(CSVOperations.RetriveLastDataOnKey(jsonFilepath, key));
        }
示例#5
0
        /// <summary>
        ///sorting the state for population,density and area
        /// </summary>
        /// <param name="path"> State Code data path </param>
        /// <param name="jsonFilepath"> Delimiter </param>
        /// <param name="key"> Header </param>
        /// <returns> sorting the state for population,density and area </returns>
        public static string SortCSVInJsonAndReturnData(string path, string jsonFilepath, string key)
        {
            //create a object to read file
            string        csvfile = File.ReadAllText(path);
            StringBuilder json    = new StringBuilder();

            //read a csv file
            using (var p = ChoCSVReader.LoadText(csvfile)
                           .WithFirstLineHeader()
                   )
            {
                //write json file
                using (var w = new ChoJSONWriter(json))
                    w.Write(p);
            }
            File.WriteAllText(jsonFilepath, json.ToString());
            JArray arr = CSVOperations.SortJsonBasedOnKeyAndValueIsNumber(jsonFilepath, key);
            //convert into json format
            var jsonArr = JsonConvert.SerializeObject(arr, Formatting.Indented);

            File.WriteAllText(jsonFilepath, jsonArr);

            return(CSVOperations.RetriveLastDataOnKey(jsonFilepath, key));
        }