Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
        }