예제 #1
0
        /// <summary>
        /// Adds a student information to a file
        /// </summary>
        /// <param name="student"></param>
        /// <returns></returns>
        public Student Add(Student student, Common.Models.EnumTypeFactory enumType)
        {
            bool  FileExistsInDirectory;
            Utils utilsFactory = new Utils();
            IAbstractFileFactory fileFactory = utilsFactory.DetectFactory(enumType);
            var file = fileFactory.CreateFile();

            //Separar en clases
            FileExistsInDirectory = file.CheckFileExists();
            if (FileExistsInDirectory == false)
            {
                file.CreateFile();
            }
            file.WriteToFile(student);
            return(student);
        }
예제 #2
0
        /// <summary>
        /// Returns a factory depending on the type passed
        /// </summary>
        /// <param name="factory"></param>
        /// <returns></returns>
        public IAbstractFileFactory DetectFactory(Common.Models.EnumTypeFactory enumType)
        {
            IAbstractFileFactory fileFactory;

            switch (enumType)
            {
            case Common.Models.EnumTypeFactory.TXT:
                fileFactory = new TextFactory();
                break;

            case Common.Models.EnumTypeFactory.XML:
                fileFactory = new XmlFactory();
                break;

            case Common.Models.EnumTypeFactory.JSON:
                fileFactory = new JsonFactory();
                break;

            default:
                throw new NotImplementedException();
            }
            return(fileFactory);
        }