-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclsConfiguration.cls
More file actions
254 lines (210 loc) · 9.27 KB
/
Copy pathclsConfiguration.cls
File metadata and controls
254 lines (210 loc) · 9.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsConfiguration"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'TODO Migrar de Registry a archivo JSON para configuración (NO PRIORITARIO)
'TODO Implementar importar/exportar configuración (NO PRIORITARIO)
'@Folder "2-Servicios.Configuracion"
'@IgnoreModule ProcedureNotUsed
Option Explicit
Private mRutaOportunidades As String
Private mRutaPlantillas As String
Private mRutaOfergas As String
Private mRutaGasVBNet As String
Private mRutaExcelCalcTempl As String
Private mArrComprImgs As Variant
Private mArrComprDrawPIDs As Variant
Private mSAM As Integer
Public Property Get RutaOportunidades() As String
RutaOportunidades = mRutaOportunidades
End Property
Public Property Let RutaOportunidades(newRuta As String)
mRutaOportunidades = newRuta
GuardarRuta CFG_RUTA_OPORTUNIDADES, newRuta
End Property
Public Property Get RutaPlantillas() As String
RutaPlantillas = mRutaPlantillas
End Property
Public Property Let RutaPlantillas(newRuta As String)
mRutaPlantillas = newRuta
GuardarRuta CFG_RUTA_PLANTILLAS, newRuta
End Property
Public Property Get RutaOfergas() As String
RutaOfergas = mRutaOfergas
End Property
Public Property Let RutaOfergas(newRuta As String)
mRutaOfergas = newRuta
GuardarRuta CFG_RUTA_OFERGAS, newRuta
End Property
Public Property Get RutaGasVBNet() As String
RutaGasVBNet = mRutaGasVBNet
End Property
Public Property Let RutaGasVBNet(newRuta As String)
mRutaGasVBNet = newRuta
GuardarRuta CFG_RUTA_GAS_VBNET, newRuta
End Property
Public Property Get RutaExcelCalcTempl() As String
RutaExcelCalcTempl = mRutaExcelCalcTempl
End Property
Public Property Let RutaExcelCalcTempl(newRuta As String)
mRutaExcelCalcTempl = newRuta
GuardarRuta CFG_RUTA_PLCALCS, newRuta
End Property
Public Property Get ListComprImgs() As Variant
ListComprImgs = mArrComprImgs
End Property
Public Property Let ListComprImgs(arrRutas As Variant)
mArrComprImgs = arrRutas
GuardarListaCarpetas arrRutas, CFG_RUTA_COMPRIMGS
End Property
Public Property Get ListComprDrawPIDs() As Variant
ListComprDrawPIDs = mArrComprDrawPIDs
End Property
Public Property Let ListComprDrawPIDs(arrRutas As Variant)
mArrComprDrawPIDs = arrRutas
GuardarListaCarpetas arrRutas, CFG_RUTA_COMPRDRAWPID
End Property
Public Property Get SAM() As Integer
SAM = mSAM
End Property
Public Property Let SAM(newSAM As Integer)
mSAM = newSAM
GuardarSAM newSAM
End Property
Private Sub Class_Initialize()
LogInfo "clsConfiguration", "[Class_Initialize]"
CargarConfiguracionDesdeRegistro
End Sub
Private Sub Class_Terminate()
LogInfo "clsConfiguration", "[Class_Terminate]"
End Sub
Private Sub CargarConfiguracionDesdeRegistro()
On Error GoTo ErrHandler
' Cargar cada ruta desde el registro y mostrarla
LogInfo "clsConfiguration", "[CargarConfiguracionDesdeRegistro] - inicializacion de todas las rutas desde registro o valores por defecto"
mRutaOportunidades = ObtenerRuta(CFG_RUTA_OPORTUNIDADES, CFG_RUTA_OPORTUNIDADES_DEFAULT)
mRutaPlantillas = ObtenerRuta(CFG_RUTA_PLANTILLAS, CFG_RUTA_PLANTILLAS_DEFAULT)
mRutaOfergas = ObtenerRuta(CFG_RUTA_OFERGAS, CFG_RUTA_OFERGAS_DEFAULT)
mRutaGasVBNet = ObtenerRuta(CFG_RUTA_GAS_VBNET, CFG_RUTA_GAS_VBNET_DEFAULT)
mRutaExcelCalcTempl = ObtenerRuta(CFG_RUTA_PLCALCS, CFG_RUTA_PLCALCS_DEFAULT)
mArrComprImgs = ObtenerListaCarpetas(CFG_RUTA_COMPRIMGS, CFG_RUTA_COMPRIMGS_DEFAULT)
mArrComprDrawPIDs = ObtenerListaCarpetas(CFG_RUTA_COMPRDRAWPID, CFG_RUTA_COMPRDRAWPID_DEFAULT)
mSAM = ObtenerSAM()
Exit Sub
ErrHandler:
Err.Raise Err.Number, "clsConfiguration.CargarConfiguracionDesdeRegistro", _
"Error en la carga de configuración desde registro: " & Err.Description
End Sub
'@Description: Devuelve diccionario de carpetas a monitorear (cacheado)
'@Note: La cache se invalida automaticamente cuando cambian las rutas
'
'TODO: revisar el uso de esta función: Buscar otra forma de que el folder watcher tenga conocimiento de qué carpetas son supervisadas;
' posiblemente presentando de otra manera el formulario de configuración de carpetas, y creando en él opciones para su selección...
'TODO: Considerar refactorizar a una estructura mas clara:
' - Crear clase clsFolderWatchConfig con propiedades: TipoCarpeta, Ruta, EsMonitoreable
' - Exponer como Collection tipada en lugar de Dictionary
' - Permitir habilitar/deshabilitar monitoreo por carpeta desde UI
Public Property Get oDicFoldersToWatch() As Object
Set oDicFoldersToWatch = CreateObject("scripting.dictionary")
oDicFoldersToWatch.Add CFG_RUTA_OPORTUNIDADES, RutaOportunidades
oDicFoldersToWatch.Add CFG_RUTA_PLANTILLAS, RutaPlantillas
oDicFoldersToWatch.Add CFG_RUTA_OFERGAS, RutaOfergas
oDicFoldersToWatch.Add CFG_RUTA_GAS_VBNET, RutaGasVBNet
oDicFoldersToWatch.Add CFG_RUTA_PLCALCS, RutaExcelCalcTempl
End Property
'-------------------------------------------
' PERSISTENCIA (Registro de Windows)
'-------------------------------------------
Private Sub GuardarSAM(SAM As Integer)
CreateObject("WScript.Shell").RegWrite CFG_PATH_SAM, CStr(SAM), "REG_SZ"
LogDebug "clsConfiguration", "[GuardarSAM] - S.A.M. guardado en registro"
End Sub
Private Function ObtenerSAM() As Integer
Dim valorLeido As Variant
On Error Resume Next
valorLeido = CreateObject("WScript.Shell").RegRead(CFG_PATH_SAM)
Dim errNum As Long: errNum = Err.Number
On Error GoTo 0
' Verificar si hubo error o valor invalido
If errNum <> 0 Or IsEmpty(valorLeido) Or Not IsNumeric(valorLeido) Then
LogWarning "clsConfiguration", "[ObtenerSAM] - no existente en registro o invalido, establecido valor por defecto"
ObtenerSAM = CFG_SAM
GuardarSAM CFG_SAM
ElseIf CInt(valorLeido) = 0 Then
LogWarning "clsConfiguration", "[ObtenerSAM] Valor cero en registro, usando valor por defecto"
ObtenerSAM = CFG_SAM
GuardarSAM CFG_SAM
Else
ObtenerSAM = CInt(valorLeido)
LogDebug "clsConfiguration", "[ObtenerSAM] Leido del registro: " & ObtenerSAM
End If
End Function
' Guardar una ruta en el registro
Private Sub GuardarRuta(nombreConfig As Variant, ruta As String)
'SaveSetting APP_NAME & "\" & CFG_SECTION_RUTAS, nombreConfig, "", ruta
CreateObject("WScript.Shell").RegWrite CFG_PATH_SECTION_RUTAS & nombreConfig & "\", ruta, "REG_SZ"
LogDebug "clsConfiguration", "[GuardarRuta] - ruta guardada en registro"
End Sub
' Recuperar una ruta del registro
Private Function ObtenerRuta(nombreConfig As Variant, strDefault As String) As String
'ObtenerRuta = GetSetting(APP_NAME & "\" & CFG_SECTION_RUTAS, nombreConfig, "", "")
On Error Resume Next
ObtenerRuta = CreateObject("WScript.Shell").RegRead(CFG_PATH_SECTION_RUTAS & nombreConfig & "\")
If ObtenerRuta = "" Or Not RutaExiste(ObtenerRuta) Then
ObtenerRuta = strDefault
GuardarRuta nombreConfig, ObtenerRuta
LogWarning "clsConfiguration", "[ObtenerRuta] - ruta no existente en registro o invalida, establecido valor por defecto"
Else
LogDebug "clsConfiguration", "[ObtenerRuta] - ruta leida del registro"
End If
On Error GoTo 0
End Function
' Guarda la lista de Carpetas
Private Sub GuardarListaCarpetas(ByVal carpetas As Variant, nombreConfig As String)
Dim lista As String
Dim key As Variant
If UBound(carpetas) < 0 Then
Stop
BorrarListaCarpetas nombreConfig
Exit Sub
End If
For Each key In carpetas
If lista <> "" Then lista = lista & "|"
lista = lista & key
Next key
On Error Resume Next
GuardarRuta nombreConfig, lista
If Err.Number <> 0 Then
LogError "clsConfiguration", "[GuardarListaCarpetas] - No se pudo guardar lista en registro", , Err.Description
Else
LogDebug "clsConfiguration", "[GuardarListaCarpetas] - Lista de carpetas guardada en registro."
End If
On Error GoTo 0
End Sub
' Obtiene la lista de Carpetas
Private Function ObtenerListaCarpetas(nombreConfig As String, strDefault As String) As Variant
On Error Resume Next
ObtenerListaCarpetas = Split(CreateObject("WScript.Shell").RegRead(CFG_PATH_SECTION_RUTAS & nombreConfig & "\"), "|")
If Err.Number <> 0 Then
LogWarning "clsConfiguration", "[ObtenerListaCarpetas] - No se encontró lista guardada en registro."
ObtenerListaCarpetas = Split(strDefault, "|")
Call GuardarListaCarpetas(ObtenerListaCarpetas, nombreConfig)
Else
LogDebug "clsConfiguration", "[ObtenerListaCarpetas] - Lista de carpetas leida desde registro."
End If
On Error GoTo 0
End Function
' Borra la lista guardada
Private Sub BorrarListaCarpetas(nombreConfig As String)
On Error Resume Next
CreateObject("WScript.Shell").RegDelete CFG_PATH_SECTION_RUTAS & nombreConfig & "\"
If Err.Number = 0 Then
LogInfo "clsConfiguration", "[BorrarListaCarpetas] - Lista de carpetas eliminada del registro."
End If
On Error GoTo 0
End Sub