Example #1
0
        public IHandleFile GetFileType(string szType)
        {
            IHandleFile oHandle = null;

            switch (szType)
            {
            case "CSV":  oHandle = new FileCSV(); break;
            }

            return(oHandle);
        }
        public void Write_A_Student_in_CSVFile()
        {
            // managing the information in a CSV file
            IFileFactory fileFactory   = new FileFactory();
            IHandleFile  handleFile    = fileFactory.GetFileType("CSV");
            string       szPath        = "inputTest.csv";
            Student      oInputStudent = HelpfulData.CreateOneStudent(DateTime.Now);

            handleFile.Path = szPath;
            handleFile.Write(oInputStudent);
            IEnumerable <Student> oStudents = handleFile.Read(szPath);

            Student oOutputStudent = null;

            foreach (var i in oStudents)
            {
                oOutputStudent = i;
            }

            Assert.AreEqual(oOutputStudent.TimeStamp.ToLongDateString(), oInputStudent.TimeStamp.ToLongDateString());
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Load Operation - Enter a File Path (e.g Input.csv):");
            string szLine = Console.ReadLine();

            IFileFactory fileFactory = new FileFactory();
            IHandleFile  handleFile  = fileFactory.GetFileType("CSV");

            IStudentRepository oRepo    = null;
            IStudentManager    oManager = null;

            try
            {
                handleFile.Path = szLine;
                oRepo           = new StudentRepository(handleFile.Read());
                oManager        = new StudentManager(oRepo, handleFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot load the CSV file");
            }

            if (oManager != null)
            {
                Console.WriteLine("Search Operation - Enter a command (e.g name=ana type=kinder");
                szLine = Console.ReadLine();
                Print(oManager.Search(szLine));
            }


            Console.WriteLine("Create Operation - Enter file path (e.g create.csv");
            szLine = Console.ReadLine();
            oManager.Save(handleFile.Read(szLine));
            oManager.Sync();
            Print(oRepo.GetContext());


            Console.Read();
        }
Example #4
0
 public StudentManager(IStudentRepository oRepository, IHandleFile oHandleFile)
 {
     _oRepository = oRepository;
     _oHandleFile = oHandleFile;
 }