/// <summary> /// Is reading from csv format file and giving result with object. /// </summary> /// <returns></returns> public IEnumerable <DataModel> Read() { using (FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (StreamReader reader = new StreamReader(stream)) { List <string> listOfDivied; string line = ""; DataModel dataModel; Project[] project; string currentline = string.Empty; bool isWrong = false;// while ((line = reader.ReadLine()) != null) { dataModel = new DataModel(); listOfDivied = new List <string>(); try { foreach (string item in line.Split(';')) { listOfDivied.Add(item); } project = new Project[listOfDivied.Count - 6]; dataModel.TeamID = long.Parse(listOfDivied[0]); dataModel.TeamName = listOfDivied[1]; dataModel.MemberID = long.Parse(listOfDivied[2]); dataModel.PassportNumber = listOfDivied[3]; dataModel.MemberName = listOfDivied[4]; dataModel.MemberSurname = listOfDivied[5]; for (int i = 0; i < 6; i++) { listOfDivied.RemoveAt(0); } int index = 0; while (listOfDivied.Count > 0) { string[] projectsMemeber = listOfDivied[0].Split(','); project[index] = new Project() { ProjectID = long.Parse(projectsMemeber[0]), ProjectName = projectsMemeber[1], ProjectCreatedDate = DateTime.Parse((projectsMemeber[2])), ProjectDueDate = DateTime.Parse((projectsMemeber[3])), ProjectDescription = projectsMemeber[4] }; index++; listOfDivied.RemoveAt(0); } dataModel.Projects = project; } catch { isWrong = true; WrongData wrongData = new WrongData(this.fileName); LogManager.DoLogging(LogType.WrongData, null, "Finde wrog data and wrote ot wrong directory."); wrongData.WrongDataFromCSV(line); } if (!isWrong) { yield return(dataModel); } else { isWrong = false; continue; } } } } }
/// <summary> /// Is reading from XML format file and giving result with object. /// </summary> /// <returns></returns> public IEnumerable <DataModel> Read() { bool isWrong = false;// DataModel dataModel; XmlNode tempNode = default(XmlNode); XmlDocument document = new XmlDocument(); document.Load(path); XmlNode root = document.DocumentElement; foreach (XmlNode node in root.ChildNodes) { dataModel = new DataModel(); if (node.Name == "Member") { tempNode = node; try { #region Read current Data foreach (XmlNode nodeMemeber in node.ChildNodes) { switch (nodeMemeber.Name) { case "TeamID": { dataModel.TeamID = long.Parse(nodeMemeber.InnerText); break; } case "TeamName": { dataModel.TeamName = nodeMemeber.InnerText; break; } case "PassportNumber": //changed { dataModel.PassportNumber = nodeMemeber.InnerText; break; } case "MemberID": { dataModel.MemberID = long.Parse(nodeMemeber.InnerText); break; } case "MemberName": { dataModel.MemberName = nodeMemeber.InnerText; break; } case "MemberSurname": { dataModel.MemberSurname = nodeMemeber.InnerText; break; } case "Projects": { dataModel.Projects = GetProjects(root, GetProjctsId(nodeMemeber)); break; } } } #endregion } catch { isWrong = true; WrongData wrongData = new WrongData(this.fileName); wrongData.WrongDataFromXml(GetWrongDataMembers(tempNode), ReadWrongData(tempNode, root)); LogManager.DoLogging(LogType.WrongData, null, "Finde wrog data and wrote ot wrong directory."); } if (!isWrong) { yield return(dataModel); } else { isWrong = false; continue; } } } }