forked from dpalat/EjemploDeManejoSyncFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Formulario.cs
279 lines (236 loc) · 11 KB
/
Formulario.cs
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Synchronization.Data;
namespace EjemploDeManejoSyncFramework
{
public partial class Formulario : Form
{
public delegate void Function();
private ManagerSyncFramework ManagerSync;
private ParametrosReplica parametrosReplica;
public Formulario()
{
InitializeComponent();
}
private void btnIniciar_Click(object sender, EventArgs e)
{
this.lstLogueo.Items.Clear();
this.lstLogueo.Refresh();
this.ManagerSync = new ManagerSyncFramework();
this.ManagerSync.onLoguearVisualmente += this.loguear;
this.ManagerSync.onProcesoFinalizado += this.procesoFinalizado;
this.parametrosReplica = new ParametrosReplica();
this.parametrosReplica.AprovisionarAmbitosEnServidorLocal = this.chkAprovisionarAmbitosEnServidorLocal.Checked;
this.parametrosReplica.AprovisionarAmbitosEnServidorRemoto = this.chkAprovisionarAmbitosEnServidorRemoto.Checked;
this.parametrosReplica.DesaprovisionarAmbitosEnServidorLocal = this.chkDesaprovisionarAmbitosEnServidorLocal.Checked;
this.parametrosReplica.DesaprovisionarAmbitosEnServidorRemoto = this.chkDesaprovisionarAmbitosEnServidorRemoto.Checked;
this.parametrosReplica.LimpiarServidorLocal = this.chkLimpiarServidorLocal.Checked;
this.parametrosReplica.LimpiarServidorRemoto = this.chkLimpiarServidorRemoto.Checked;
this.parametrosReplica.RealizarReplica = this.chkReplicar.Checked;
this.parametrosReplica.StringConnectionLocal = this.txtStringConnectionLocal.Text + ";Application Name=Manager de Sync Framework;";
this.parametrosReplica.StringConnectionRemoto = this.txtStringConnectionRemoto.Text + ";Application Name=Manager de Sync Framework;";
this.parametrosReplica.ListaDeTablas = this.ObtenerListaDeTablas( this.lctChkTablasLocalesAReplicar.CheckedItems );
this.parametrosReplica.SitioDeSubida = this.chkSitioLocalDeSubida.Checked;
this.parametrosReplica.tamañoDeCache = Convert.ToUInt32(this.txtTamañoCache.Text.ToString());
this.parametrosReplica.TamañoDeTransaccion = Convert.ToUInt32(this.txtTamañoTransaccion.Text.ToString());
this.parametrosReplica.TimeOut = Convert.ToInt32( this.txtTimeOut.Text.ToString());
this.parametrosReplica.prefijoMetadataSyncFramework = this.txtPrefijoMetadata.Text; // "Sql_Replica";
this.parametrosReplica.esquemaMetadataSyncFramework = this.txtEsquemaMetadata.Text; // "SyncZooLogic";
this.parametrosReplica.prefijoParaNombreDeAmbito = this.txtPrefijoAmbitos.Text; //"Novedades_[{0}].[{1}]"; //Novedades_[ZooLogic].[ADT_COMB]
this.parametrosReplica.esquemaQueSeReplica = this.txtEsquemaAReplicar.Text;
this.parametrosReplica.HilosParaAprovisionar = Convert.ToInt32( this.txtHilosAprovisionar.Text.ToString() );
this.parametrosReplica.HilosParaReplicar = Convert.ToInt32( this.txtHilosReplica.Text.ToString() );
this.parametrosReplica.ReplicarSoloAmbitosconCambios = this.chkSoloConCambios.Checked;
this.parametrosReplica.SuscribirseATodosLosEventosDeInformacion = this.chkSuscribirseATodos.Checked;
if (!this.chkSitioLocalDeSubida.Checked && !this.chkSitioLocalDeBajada.Checked)
{
System.Windows.Forms.MessageBox.Show("Debe indicar si el sitio es de subida o bajada.");
return;
}
try
{
this.activarBotones(false);
System.Threading.Thread nuevoHilo = new System.Threading.Thread(this.IniciarReplica);
nuevoHilo.Name = "Replicando manager de sincronización";
nuevoHilo.Start();
}
catch (Exception de)
{
this.loguear(de.ToString());
this.procesoFinalizado();
}
}
private void procesoFinalizado()
{
this.activarBotones(true);
this.loguear(string.Format( "-------Tiempo Total: {0}--------", this.ManagerSync.TiempoTotalTranscurrido) );
this.loguear("-------Proceso finalizado--------");
}
private void activarBotones( bool activados )
{
if (this.InvokeRequired)
{
this.Invoke(new Function(delegate() { this.activarBotones( activados ); }));
}
else
{
this.btnIniciar.Enabled = activados;
this.btnCargarTablas.Enabled = activados;
this.btnSeleccionarNinguno.Enabled = activados;
this.btnSeleccionarTodos.Enabled = activados;
this.chkSitioLocalDeBajada.Enabled = activados;
this.chkSitioLocalDeSubida.Enabled = activados;
}
}
private void IniciarReplica()
{
try
{
this.ManagerSync.IniciarReplica(this.parametrosReplica);
}
catch (Exception ed)
{
this.loguear("Full! Error en el proceso de replica: " + ed.ToString());
this.procesoFinalizado();
}
}
private List<string> ObtenerListaDeTablas(CheckedListBox.CheckedItemCollection objectCollection)
{
List<string> retorno = new List<string>();
foreach ( string item in objectCollection)
{
retorno.Add(item);
}
return retorno;
}
private void btnCargarTablas_Click(object sender, EventArgs e)
{
if (!(this.chkSitioLocalDeBajada.Checked || this.chkSitioLocalDeSubida.Checked))
{
MessageBox.Show("Se requiere setear el sentido de comunicación SUBIDA o BAJADA");
return;
}
try
{
string cadeDeConexion = this.txtStringConnectionLocal.Text;
if (this.chkSitioLocalDeBajada.Checked)
{
//La estructura sale del sitio que tiene los datos.
cadeDeConexion = this.txtStringConnectionRemoto.Text;
}
using (SqlConnection conexionLocalSql = new SqlConnection(cadeDeConexion))
{
conexionLocalSql.Open();
SqlCommand comando = new SqlCommand("Select TABLE_SCHEMA, TABLE_NAME From INFORMATION_SCHEMA.Tables" +
" where table_schema = '" + this.txtEsquemaAReplicar.Text + "' order by 1,2");
comando.Connection = conexionLocalSql;
SqlDataReader data = comando.ExecuteReader();
this.lctChkTablasLocalesAReplicar.Items.Clear();
while (data.Read())
{
this.lctChkTablasLocalesAReplicar.Items.Add(data[0] + "." + data[1]);
}
this.actulizarMensajesDeCantidadDeTablas( true );
}
}
catch (Exception dde)
{
this.loguear("Error al cargar las tablas: " + dde.ToString());
}
}
private void actulizarMensajesDeCantidadDeTablas( bool mostranMensajeDeCantidad )
{
this.actulizarMensajesDeCantidadDeTablas();
if ( mostranMensajeDeCantidad && this.lctChkTablasLocalesAReplicar.Items.Count < 1 )
{
string orgine = "local";
if (this.chkSitioLocalDeBajada.Checked)
{
orgine = "remoto";
}
MessageBox.Show("No se encontraron tablas del esquema " + this.txtEsquemaAReplicar.Text + " en el " + orgine);
}
}
private void actulizarMensajesDeCantidadDeTablas()
{
this.lblCantidadDeTablas.Text = this.lctChkTablasLocalesAReplicar.Items.Count.ToString();
this.lblCantidadSeleccionadas.Text = this.lctChkTablasLocalesAReplicar.CheckedItems.Count.ToString();
}
private void chkSitioLocalDeSubida_CheckedChanged(object sender, EventArgs e)
{
this.chkSitioLocalDeBajada.Checked = !this.chkSitioLocalDeSubida.Checked;
}
private void chkSitioLocalDeBajada_CheckedChanged(object sender, EventArgs e)
{
this.chkSitioLocalDeSubida.Checked = !this.chkSitioLocalDeBajada.Checked;
}
private void btnSeleccionarTodos_Click(object sender, EventArgs e)
{
for ( int i = 0; i < this.lctChkTablasLocalesAReplicar.Items.Count; i++)
this.lctChkTablasLocalesAReplicar.SetItemChecked( i, true );
this.actulizarMensajesDeCantidadDeTablas();
}
private void btnSeleccionarNinguno_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.lctChkTablasLocalesAReplicar.Items.Count; i++)
this.lctChkTablasLocalesAReplicar.SetItemChecked(i, false);
this.actulizarMensajesDeCantidadDeTablas();
}
private void lctChkTablasLocalesAReplicar_Click(object sender, EventArgs e)
{
this.actulizarMensajesDeCantidadDeTablas();
}
private void lctChkTablasLocalesAReplicar_SelectedValueChanged(object sender, EventArgs e)
{
this.actulizarMensajesDeCantidadDeTablas();
}
private void lctChkTablasLocalesAReplicar_ItemCheck(object sender, ItemCheckEventArgs e)
{
this.actulizarMensajesDeCantidadDeTablas();
}
private void lctChkTablasLocalesAReplicar_SelectedIndexChanged(object sender, EventArgs e)
{
this.actulizarMensajesDeCantidadDeTablas();
}
private void lctChkTablasLocalesAReplicar_Validated(object sender, EventArgs e)
{
this.actulizarMensajesDeCantidadDeTablas();
}
private void loguear( string renglon )
{
if (this.InvokeRequired)
{
this.Invoke(new Function(delegate() { this.loguear(renglon); }));
}
else
{
this.lstLogueo.Items.Add(renglon);
this.lstLogueo.Refresh();
this.lstLogueo.SelectedIndex = this.lstLogueo.Items.Count - 1;
this.lstLogueo.SelectedIndex = -1;
}
}
private void Formulario_Load(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
}
private void txtHilosReplica_TextChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void label17_Click(object sender, EventArgs e)
{
}
}
}