public static async Task RunTask(String url) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Method = "GET"; HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); string jsonString = ""; using (Stream stream = httpWebResponse.GetResponseStream()) { StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.UTF8); jsonString = streamReader.ReadToEnd(); } List <StudentNewModel> st = JsonConvert.DeserializeObject <List <StudentNewModel> >(jsonString); foreach (var stud in st) { Console.WriteLine("Hi:: " + stud.Name); } WordDocumentClass.CreateWordprocessingDocumentFromApi(Constants.Locations.StudentDocFileFromApi, st); }
static void Main(string[] args) { Models.ApiData.StudentController.CallApi(); List <string> directories = new List <string>(); directories = FTP.GetDirectory(Constants.FTP.BaseUrl); List <Student> students = new List <Student>(); //int processed = 0; foreach (var directory in directories) { //++processed; //if (processed == 3) break; Console.WriteLine("Directory: " + directory); Student student = new Student() { AbsoluteUrl = Constants.FTP.BaseUrl }; student.FromDirectory(directory); // Console.WriteLine(student); string infoFilePath = student.FullPathUrl + "/" + Constants.Locations.InfoFile; bool fileExists = FTP.FileExists(infoFilePath); if (fileExists == true) { //QUESTION 2 Console.WriteLine("Found info file: " + infoFilePath); string firstname = student.FirstName; //Console.WriteLine("Student name:" + firstname); if (student.StudentId == Constants.Student.StudentId) { //student.FirstName student.MyRecord = true; } else { student.MyRecord = false; } var infoBytes = FTP.DownloadFileBytes(infoFilePath); //CSV data string csv = Encoding.Default.GetString(infoBytes); string[] csv_content = csv.Split("\r\n", StringSplitOptions.RemoveEmptyEntries); if (csv_content.Length != 2) { Console.WriteLine("Error in CSV format."); } else { student.FromCSV(csv_content[1]); //Console.WriteLine("Extracting data from "+student.FirstName+ " directory: \n" + csv_content[1]); } } else { Console.WriteLine("Could not find info file:"); try { if (student.StudentId == Constants.Locations.MyID) { student.MyRecord = true; } else { student.MyRecord = false; } } catch (Exception ex) { } } //Console.WriteLine("Info File Path::: " + infoFilePath); string imageFilePath = student.FullPathUrl + "/" + Constants.Locations.ImageFile; bool imageFileExists = FTP.FileExists(imageFilePath); if (imageFileExists == true) { Console.WriteLine("Found image file: " + imageFilePath); if ((student.ImageData) == null || student.ImageData.Length < 2) { Console.WriteLine("No Imagedata:"); try { var ImageBytes = FTP.DownloadFileBytes(imageFilePath); string base64String = Convert.ToBase64String(ImageBytes); student.ImageData = base64String; } catch (Exception ex) { student.ImageData = "No data Found"; } } //Console.WriteLine("Image File Path::: " + imageFilePath); } else { //QUESTION 2 Console.WriteLine("Could not find image file:"); try { student.ImageData = "No data Found"; } catch (Exception ex) { } } students.Add(student); //} } //Console.WriteLine("Directory count: " + directories.Count); Console.WriteLine(Constants.Locations.StudentDocFile); Console.WriteLine(Constants.Locations.StudentExcelFile); SpreadSheetClass.CreateSpreadsheetWorkbook(Constants.Locations.StudentExcelFile, students); WordDocumentClass.CreateWordprocessingDocument(Constants.Locations.StudentDocFile, students); PresentationClass.CreatePresentation(Constants.Locations.StudentPPTFile); using (StreamWriter fs = new StreamWriter(Constants.Locations.StudentCSVFile)) { //int Age = 10; fs.WriteLine((nameof(Student.StudentId)) + ',' + (nameof(Student.FirstName)) + ',' + (nameof(Student.LastName)) + ',' + (nameof(Student.Age)) + ',' + (nameof(Student.DateOfBirth)) + ',' + (nameof(Student.MyRecord)) + ',' + (nameof(Student.ImageData))); foreach (var student in students) { fs.WriteLine(student.ToCSV()); Console.WriteLine("To CSV :: " + student.ToCSV()); Console.WriteLine("To String :: " + student.ToString()); } } String jsonconvert = ConvertCsvFileToJsonObject(Constants.Locations.StudentCSVFile); File.WriteAllText(Constants.Locations.StudentJSONFile, jsonconvert); //TEST CSV TO XML //START var lines = File.ReadAllLines(Constants.Locations.StudentCSVFile); string[] headers = lines[0].Split(',').Select(x => x.Trim('\"')).ToArray(); var xml = new XElement("root", lines.Where((line, index) => index > 0).Select(line => new XElement("row", line.Split(',').Select((column, index) => new XElement(headers[index], column))))); xml.Save(Constants.Locations.StudentXMLFile); //END AggregateFunctions(students); //FTP.UploadFile(Constants.Locations.StudentCSVFile, Constants.FTP.CSVUploadLocation); //FTP.UploadFile(Constants.Locations.StudentXMLFile, Constants.FTP.XMLUploadLocation); //FTP.UploadFile(Constants.Locations.StudentJSONFile, Constants.FTP.JSONUploadLocation); FTP.UploadFile(Constants.Locations.StudentCSVFile, Constants.FTP.CSVUploadLocation); FTP.UploadFile(Constants.Locations.StudentXMLFile, Constants.FTP.XMLUploadLocation); FTP.UploadFile(Constants.Locations.StudentJSONFile, Constants.FTP.JSONUploadLocation); FTP.UploadFile(Constants.Locations.StudentDocFile, Constants.FTP.DOCUploadLocation); FTP.UploadFile(Constants.Locations.StudentDocFileFromApi, Constants.FTP.APIdocUploadLocation); FTP.UploadFile(Constants.Locations.StudentExcelFile, Constants.FTP.EXCELUploadLocation); FTP.UploadFile(Constants.Locations.StudentPPTFile, Constants.FTP.PPTUploadLocation); return; }