Imports tsl5.Enumeraciones
Imports System.Runtime.Serialization
Imports System.Configuration
Imports System.Text.Json

Namespace Datos
    <DataContractAttribute(IsReference:=True)> _
    <Serializable()> Public Class BBDD
        Property Tipo As TipoBD
        Property Servidor As String
        Property DataBase As String
        Property Puerto As Integer
        Property Usuario As String
        Property Password As String
        Property Fichero As String
        Property SegundosTimeout As Integer = 300
        Property Pooling As Boolean
        Property SSL As Boolean
        Property FicheroCertificado As String
        Property PasswordCertificado As String
        Public Property id As String
        Public Shared Function ObtieneJSONBD(idBD As String, idUsuarioBD As String, idServidor As String, tipo As TipoBD) As String
            Dim bd As New tsl5.Datos.BBDD
            With bd
                .Usuario = ConfigurationManager.AppSettings(idUsuarioBD)
                If .Usuario = "" Then Throw New Exception("Usuario bd " & idUsuarioBD & " no encontrado en la configuracion")
                .DataBase = ConfigurationManager.AppSettings(idBD & "Esquema")
                .Password = ConfigurationManager.AppSettings(idBD & "Pass" & idUsuarioBD)
                .Servidor = ConfigurationManager.AppSettings(idBD & "Serv" & idServidor)
                .Tipo = tipo
            End With
            Dim options As New JsonSerializerOptions() With {.IncludeFields = True}
            Dim JSONString = JsonSerializer.Serialize(bd, options)
            Return JSONString
        End Function
    End Class
    <Serializable()> Public Class DatosConfiguracionServicio
        Property NombreServicio As String
        Property PuertoNR As Integer
        Property BasesDatos As New List(Of BBDD)
        Property Detener As Boolean
        Property Directorios As New Directorios
        Property Version As String
        Property NumeroBDConfiguracion As Integer
        Shared Function CargaConfiguracion(FicheroConfiguracion As String, DllProcesos As String) As DatosConfiguracionServicio
            Dim dcs As New DatosConfiguracionServicio
            dcs = tsl5.Utilidades.DeserializaFichero(FicheroConfiguracion, GetType(DatosConfiguracionServicio))
            If DllProcesos <> "" And IO.File.Exists(DllProcesos) Then
                Try
                    Dim ensamblado As System.Reflection.Assembly
                    ensamblado = System.Reflection.Assembly.LoadFrom(System.Windows.Forms.Application.StartupPath & "\" & DllProcesos)
                    dcs.Version = ensamblado.GetName.Version.ToString
                Catch
                End Try
            End If
            dcs.Directorios.DirectorioConfiguraciones = IO.Path.GetDirectoryName(FicheroConfiguracion)
            Return dcs
        End Function
    End Class
    <Serializable()> Public Class Directorios
        Property Temporal As String
        Property Flags As String
        Property Plantillas As String
        Property Logs As String
        Property Datos As String
        Property DatosLocales As String
        Property DirectorioConfiguraciones As String
    End Class
    <Serializable()> Public Class DatosConfiguracionCliente
        Property ServidorActivo As New Servidor
        Property ConstantesCliente As New ConstantesCliente
        Property NombreEjecutable As String
    End Class
    <Serializable()> Public Class ConstantesCliente
        Property NombreServicio As String
        Property RutaAplicacion As String
        Property RutaDatos As String
        Property RutaTmp As String
    End Class
    <Serializable()> Public Class DatosConfiguracionAplicacion
        Property Servidores As New List(Of Servidor)
        Property ConstantesCliente As New ConstantesCliente
    End Class
    <Serializable()> Public Class DatosSesionCliente
        Property IdSesion As Long
        Property idUsuario As Integer
        Property idGrupoMenu As Integer
        Property idGruboBD As Integer
    End Class

    <Serializable()> Public Class DatosConexionCliente
        Property BasesDatos As New List(Of BBDD)
        Property NumeroBDConfiguracion As Integer
        '   Property ServidorActualizador As New ServidorActualizacion
    End Class
    <Serializable()> Public Class DatosOperacion
        Property Usuario As String
        Property Password As String
        Property IdSesion As Long
        Property Operacion As Enumeraciones.TiposOperacionesEnum
        Property Datos As Object
    End Class
    '<Serializable()> Public Class Actualizador
    '    Property Nombre As String
    '    'Property Tipo As Enumeraciones.tipoAplicacionActualizableEnum
    '    Property ServidorLocal As New ServidorActualizacion
    '    Property ServidorRemoto As New ServidorActualizacion
    '    Property FicheroConfiguracionXML As String
    '    '    Property RutaEnsamblados As String
    '    Property RutaDatos As String
    'End Class
    '<Serializable()> Public Class ActualizadorPropio
    '    Property FicheroConfiguracionXML As String
    '    ' Property RutaEnsamblados As String
    '    Property RutaDatos As String
    '    Property RutaLogs As String
    'End Class

    '<Serializable()> Public Class Actualizacion
    '    Property Nombre As String
    '    Property Elementos As New List(Of ElementoActualizable)

    'End Class
    '<Serializable()> Public Class ElementoActualizable
    '    Property NombreFichero As String
    '    Property RutaFichero As String
    '    Property TipoFichero As Enumeraciones.tipoFicheroActualizableEnum
    '    Property FechaModificacion As DateTime
    '    Property Comparacion As Enumeraciones.ComparacionEnum
    'End Class
    <Serializable()> Public Class Servidor
        Property Servidor As String
        Property Puerto As Integer
        Property Localizacion As Enumeraciones.LocalizacionesEnum
    End Class

    '<Serializable()> Public Class ServidorActualizacion
    '    Property TipoServidorActualizacion As Enumeraciones.tiposServidoresActualizacionEnum
    '    Property Servidor As String
    '    Property Puerto As Integer
    '    Property SSL As Boolean
    '    Property Pasivo As Boolean
    '    Property Usuario As String
    '    Property Contraseña As String
    '    Property Directorio As String
    'End Class
    '<Serializable()> Public Class DatosActualizadorAuxiliar
    '    Property RutaEjecutable As String
    '    Property Actualizacion As Datos.Actualizacion
    '    Property ConfiguracionCliente As Datos.DatosConfiguracionCliente
    '    Property ConexionCliente As Datos.DatosConexionCliente
    'End Class
    '<Serializable()> Public Class DatosLogs
    '    Friend EmailDestinatarios As String
    '    Friend ServidorSMTP As String
    '    Friend Cuenta As String
    '    Friend Contraseña As String
    '    Friend Puerto As Integer
    '    Friend UsarSSL As Boolean
    'End Class
End Namespace
Namespace Enumeraciones
    Public Enum LocalizacionesEnum
        Local = 0
        Remoto = 1
    End Enum
    Public Enum TiposOperacionesEnum
        ObtieneFichero = 0
        ObtieneString = 1
    End Enum
    'Public Enum TiposServidoresActualizacionEnum
    '    Samba = 0
    '    FTP = 1
    'End Enum
    'Public Enum ComparacionEnum
    '    Sin_Cambios = 0
    '    Diferente = 1
    '    Nuevo = 2
    '    Inexistente = 3
    'End Enum
    'Public Enum TipoActualizacionEnum
    '    No_Actualizar = 0
    '    Actualizacion_Sin_Reinicio = 1
    '    Actualizacion_Con_Reinicio = 2
    '    Actualizacion_Mixta = 3
    'End Enum
    'Public Enum TipoFicheroActualizableEnum
    '    Ensamblado = 0
    '    Datos = 1
    'End Enum
    Public Enum TipoLog
        InicioServicio = 0
        Fallo = 1
        Advertencia = 2
        ErroresEnFtp = 3
        Otros = 4
        Informacion = 5
        Depuracion = 6
        FinServicio = 99
    End Enum
    <DataContractAttribute(IsReference:=True)> _
    <Serializable> _
    Public Enum TipoBD
        MYSQL
        LOCALDB
        SQLSERVER
        ORACLE
    End Enum
End Namespace
