Example #1
0
        // Specify what you want to happen when the Elapsed event is
        // raised.
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            var timer = source as System.Timers.Timer;

            timer.Stop();
            CsvToJson csvToJson = new CsvToJson();

            csvToJson.CvsToJson();
            timer.Start();

            Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
        }
Example #2
0
        static void SaveFiles(List <Student> students, string fileName)
        {
            // 1. Save CSV file
            string studentCSVPath = $"{Constants.Locations.DataFolder}\\{fileName}.csv";

            //Establish a file stream to collect data from the response. this point is local disk.
            using (StreamWriter fs = new StreamWriter(studentCSVPath))
            {
                int headerNum = 0;
                foreach (var student in students)
                {
                    if (headerNum == 0)
                    {
                        fs.Write(student.HeaderRow + "\r\n");
                        headerNum++;
                    }
                    else
                    {
                        fs.Write(student.ToCSV() + "\r\n");
                    }
                }
            }

            // 2. Save JSON file, which is converted from CSV file
            string studentJSONPath = $"{Constants.Locations.DataFolder}\\{fileName}.json";
            string analyticsData   = CsvToJson.ReadFile(studentCSVPath);

            using (StreamWriter fs = new StreamWriter(studentJSONPath))
            {
                fs.Write(analyticsData);
            }

            // 3. Save XML file, which is converted from CSV file
            string    studentXMLPath = $"{Constants.Locations.DataFolder}\\{fileName}.xml";
            string    csv            = File.ReadAllText(studentCSVPath);
            XDocument doc            = CsvToXml.ConvertCsvToXML(csv, new[] { "," });

            doc.Save(studentXMLPath);

            // 4. Upload the files to My FTP
            foreach (var student in students)
            {
                if (student.MyRecord)
                {
                    FTPApp.UploadFile(studentCSVPath, student.FullPathUrl + "/students.csv");
                    FTPApp.UploadFile(studentJSONPath, student.FullPathUrl + "/students.json");
                    FTPApp.UploadFile(studentXMLPath, student.FullPathUrl + "/students.xml");
                }
            }
        }
Example #3
0
        public async Task <IActionResult> ImportTransactions()
        {
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                try
                {
                    string csv = await reader.ReadToEndAsync();

                    elasticService.ImportDocument <Edge>(CsvToJson.Convert(csv));
                    return(Ok());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(BadRequest(e.Message));
                }
            }
        }