Пример #1
0
        public static string CreateJsonPerson(string fileName)
        {
            string[] allLines = File.ReadAllLines(fileName);

            string agent = "";

            Dictionary<string, List<Sale>> agentMap = new Dictionary<string, List<Sale>>();

            agent = System.IO.Path.GetFileNameWithoutExtension(fileName);
            agentMap[agent] = new List<Sale>();

            for (int i = 1; i < allLines.Length; i++)
            {
                string line = allLines[i];

                if (!line.Equals(",,,,,,"))
                {
                    Sale newSale = new Sale();
                    newSale.Create(line);
                    agentMap[agent].Add(newSale);
                }
            }

            string output = JsonConvert.SerializeObject(agentMap);

            return output;
        }
Пример #2
0
        //Creation of the json files from the csv files reading through by line turning them into a list of sales.
        public static string CreateJsonSales(string fileName)
        {
            string[] allLines = File.ReadAllLines(fileName);

            string region = "";

            Dictionary<string, List<Sale>> regionMap = new Dictionary<string, List<Sale>>();

            for (int i = 1; i < allLines.Length; i++)
            {
                string line = allLines[i];

                if (line.Contains(":"))
                {
                    //Sets lines with ":" to the key of the dictionary to define the list of sales by region.
                    region = line.Substring(0, line.IndexOf(':'));
                    regionMap[region] = new List<Sale>();

                }
                else
                {
                    //Checks for completely blank lines and skips over them.
                    if (!line.Equals(",,,,,,"))
                    {
                        Sale newSale = new Sale();
                        newSale.Create(line);
                        regionMap[region].Add(newSale);
                    }
                }
            }
            string output = JsonConvert.SerializeObject(regionMap);

            return output;
        }