/// <summary>
 /// constructor estatico
 /// </summary>
 static Clinica()
 {
     turnos                   = new List <Turno>();
     pacientes                = CargarListasPaciente(LeerPacientesXML(), ClinicaDAO.SeleccionarPacientes());
     archivo                  = new ArchivoTexto();
     especialistas            = CargarListaEspecialista(LeerEspecialistasXML(), ClinicaDAO.SeleccionarEspecialistas());
     observacionesDeConsultas = new List <string>();
     orandoms                 = new Random();
 }
Exemple #2
0
 public T Leer(string path)
 {
     try
     {
         if (this.tipo == IArchivos <T> .ETipoArchivo.XML)
         {
             if (Path.GetExtension(path) == ".xml")
             {
                 using (XmlTextReader xmlTextReader = new XmlTextReader(path))
                 {
                     XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                     return((T)xmlSerializer.Deserialize(xmlTextReader));
                 }
             }
             else
             {
                 throw new ExtensionInvalidaException("Extension Invalida para XML");
             }
         }
         else
         {
             if (Path.GetExtension(path) == ".json")
             {
                 ArchivoTexto archivoTexto = new ArchivoTexto();
                 string       texto        = archivoTexto.Leer(path);
                 return(JsonSerializer.Deserialize <T>(texto));
             }
             else
             {
                 throw new ExtensionInvalidaException("Extension Invalida para JSON");
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #3
0
 public void Escribir(T dato, string path)
 {
     try
     {
         if (this.tipo == IArchivos <T> .ETipoArchivo.XML)
         {
             if (Path.GetExtension(path) == ".xml")
             {
                 using (XmlTextWriter xmlTextWriter = new XmlTextWriter(path, Encoding.UTF8))
                 {
                     xmlTextWriter.Formatting = Formatting.Indented;
                     XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                     xmlSerializer.Serialize(xmlTextWriter, dato);
                 }
             }
             else
             {
                 throw new ExtensionInvalidaException("Extension Invalida para XML");
             }
         }
         else
         {
             if (Path.GetExtension(path) == ".json")
             {
                 ArchivoTexto archivoTexto = new ArchivoTexto();
                 archivoTexto.Escribir(JsonSerializer.Serialize(dato, typeof(T)), path);
             }
             else
             {
                 throw new ExtensionInvalidaException("Extension Invalida para JSON");
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 /// <summary>
 /// Constructor que recibe un mensaje con el error y la innerExcepcion
 /// y utiliza el metodo Guarda para guardar en un archivo de texto los errores.
 /// </summary>
 /// <param name="mensaje"></param>
 /// <param name="innerException"></param>
 public ClinicaException(string mensaje, Exception innerException) : base(mensaje, innerException)
 {
     ArchivoTexto.Guardar(this);
 }