static void Main(string[] args) { //blad string path = args.Length > 0 ? args[0] : "data.csv"; string path2 = args.Length > 1 ? args[1] : "result.xml"; string path3 = args.Length > 2 ? args[2] : "xml"; error_file = new StreamWriter("log.txt", true); error_file.WriteLine("log"); if (!System.IO.Directory.Exists(path)) { log($"Directory\"{path}\"doesn't exists' "); error_file.Flush(); error_file.Close(); } var students = new HashSet <Student>(new StudentComparer()); var file = new FileInfo("/Users/koval/dane.csv"); using (var stream = new StreamReader(file.OpenRead())) { string line = null; while ((line = stream.ReadLine()) != null) { string[] student = line.Split(','); var st = new Student { fname = student[0], lname = student[1], studies = new Studies { name = student[2], mode = student[3] }, indexNumber = int.Parse(student[4]), birthdate = student[5], email = student[6], mothersName = student[7], fatherName = student[8] }; students.Add(st); } } var uczelnia = new Uczelnia { author = "Anastasiia Koval", studenci = students }; FileStream writer = new FileStream(path2, FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(Uczelnia)); serializer.Serialize(writer, uczelnia); Console.WriteLine(); }
static void Main(string[] args) { //arrlist = list //set = hashset //map = dictionary string fileStart = CheckArgument1(args); string fileResult = CheckArgument2(args); string fileExtension = CheckArgument3(args); string fileLogs = "data/łog.txt"; StreamWriter streamWriter = new StreamWriter(fileLogs); FileInfo file = new FileInfo(fileStart); List <Student> studentList = new List <Student>(); Dictionary <string, int> stundetMap = new Dictionary <string, int>(); try { using (StreamReader stream = new StreamReader(file.OpenRead())) { string line = ""; while ((line = stream.ReadLine()) != null) { Console.WriteLine(line); string[] student = line.Split(","); Console.WriteLine(line); if (checkData(student)) { var kierunek = new Kierunek { nazwa = student[2], tryb = student[3], }; Student student1 = new Student { Imie = student[0], Nazwisko = student[1], Index = int.Parse(student[4]), Kierunek = kierunek, DataUrodzenia = student[5], Email = student[6], Ojciec = student[8], Matka = student[7] }; studentList.Add(student1); if (stundetMap.ContainsKey(kierunek.nazwa)) { stundetMap[kierunek.nazwa]++; } else { stundetMap.Add(kierunek.nazwa, 1); } } else { streamWriter.WriteLine("Zle podane dane : " + line); } } } }catch (FileNotFoundException) { Console.WriteLine("Plik nazwa nie istnieje"); streamWriter.WriteLine("Plik nazwa nie istnieje"); return; }catch (ArgumentException) { Console.WriteLine("Podana ścieżka jest niepoprawna"); streamWriter.WriteLine("Podana ścieżka jest niepoprawna"); return; }catch (Exception e3) { Console.WriteLine(e3.Message); streamWriter.WriteLine(e3.Message); return; } streamWriter.Flush(); streamWriter.Close(); ActiveStudies activeSt = new ActiveStudies() { activeStudies = new List <ActiveStudie>() }; foreach (KeyValuePair <string, int> entry in stundetMap) { activeSt.activeStudies.Add(new ActiveStudie { name = entry.Key, number = entry.Value }); } Students students = new Students { Student = studentList.Distinct(new EqualityComp()).ToList <Student>() }; Uczelnia uczelnia = new Uczelnia { data = "14.03.2020", autor = "Alvan Maksym", student = students, activeStudies = activeSt, }; FileStream writer = new FileStream(fileExtension, FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(Uczelnia)); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add("", ""); serializer.Serialize(writer, uczelnia, namespaces); }