diff --git a/Model/ComunDef.cs b/Model/ComunDef.cs index 8106d64..1a96943 100644 --- a/Model/ComunDef.cs +++ b/Model/ComunDef.cs @@ -31,11 +31,5 @@ namespace OliviaAddInPro.Model public static string atr_pedes; // Ejecuta(ModosEjec modo) { - TareaRes res = null; + Respuesta res = new Respuesta { Value=false}; + Respuesta res2 = new Respuesta (){ Value = TiposEjecucion.FinEjecNOk }; res = Serv.Ejecuta(modo); - if (!res.Errores) + if (res.Value) { - var res1=LanzaSrv.ejec(this, modo, TipoTtoStr); - if (!res1.HasError) + res=LanzaSrv.ejec(this, modo, TipoTtoStr); + if (res.Value) { ProceSrv.ConfigConex(); - res1 = ProceSrv.start(LanzaSrv.str_cfg, ProgrSrc._ProgrSrc); - } - - if (res1.HasError) - { - res.Errores = true; - res.msg = ""; - res1.Error.ForEach(e=> res.msg+=e+".\n "); + res2 = ProceSrv.start(LanzaSrv.str_cfg, ProgrSrc._ProgrSrc); } } - return res; - } - public async void EjecutaAsync(ModosEjec modo, Action ffin) - { - await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => - { - var res = Ejecuta(modo); - ffin(res); - return res; - }); - + if (res.HasError) + { + res2.Error.AddRange(res.Error); + } + return res2; } } } diff --git a/Model/OliviaGlob.cs b/Model/OliviaGlob.cs index 66478d6..2201e37 100644 --- a/Model/OliviaGlob.cs +++ b/Model/OliviaGlob.cs @@ -12,7 +12,6 @@ using OliviaAddInPro.Helper; using System.Net; using System.Net.Sockets; using System.IO; -using System.Windows; namespace OliviaAddInPro.Model { @@ -307,36 +306,6 @@ namespace OliviaAddInPro.Model } } - - public static void finEjecuta(OliviaAddInPro.Model.ComunDef.TareaRes res) - { - progrDialog.Hide(); - - if (res.Errores) - { - HelperGlobal.ponMsg(res.msg); - } - else - { - HelperGlobal.ponMsg(Resource1.String_exito); - } - Application.Current.Dispatcher.Invoke(new Action(() => { finEjecuta2(); })); - //tiene que hacer delegate finEjecuta2() - } - - - public static void finEjecuta2() - { - //muestra la ventana - ShowHidePane(true); - - //importa resultados - - //borra los archivos que le toca borrar - //hay una funcion borrafiles en EjecServ, usar esa? - //pone modo config2 - } - /** * Inicializa los nombres por defecto de las variables, para debug por si no hay instalador */ diff --git a/Model/Recogida.cs b/Model/Recogida.cs index 2afbafb..02bf0b4 100644 --- a/Model/Recogida.cs +++ b/Model/Recogida.cs @@ -75,44 +75,27 @@ namespace OliviaAddInPro.Model { Serv = new RecogidaServ(this); LanzaSrv = new LanzaRecoSrv(); - ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog); - ProceSrv = new ProcesoEjecServ(); } - - public TareaRes Ejecuta(ModosEjec modo) + public override Respuesta Ejecuta(ModosEjec modo) { - TareaRes res = null; + Respuesta res = new Respuesta { Value = false }; + Respuesta res2 = new Respuesta() { Value = TiposEjecucion.FinEjecNOk }; res = Serv.Ejecuta(modo); - if (!res.Errores) + if (res.Value) { - var res1 = LanzaSrv.ejec(this, modo, TipoTtoStr); - if (!res1.HasError) + res = LanzaSrv.ejec(this, modo, TipoTtoStr); + if (res.Value) { ProceSrv.ConfigConex(); - res1 = ProceSrv.start(LanzaSrv.str_cfg, ProgrSrc._ProgrSrc); - } - - if (res1.HasError) - { - res.Errores = true; - res.msg = ""; - res1.Error.ForEach(e => res.msg += e + ".\n "); + res2 = ProceSrv.start(LanzaSrv.str_cfg, ProgrSrc._ProgrSrc); } } - return res; - - } - public async void EjecutaAsync(ModosEjec modo, Action ffin) - { - await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => - { - var res = Ejecuta(modo); - ffin(res); - return res; - - }); - + if (res.HasError) + { + res2.Error.AddRange(res.Error); + } + return res2; } } } diff --git a/Model/TratamientoComun.cs b/Model/TratamientoComun.cs index 0e40004..93e5e1d 100644 --- a/Model/TratamientoComun.cs +++ b/Model/TratamientoComun.cs @@ -7,6 +7,7 @@ using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Internal.Layouts.Utilities; using OliviaAddInPro.Helper; using OliviaAddInPro.Services; +using static OliviaAddInPro.Model.ComunDef; namespace OliviaAddInPro.Model { @@ -117,21 +118,55 @@ namespace OliviaAddInPro.Model private string err_str = string.Empty; public string ErrStr { - get { + get + { /*string val = string.Empty; val.CopyFrom(err_str); err_str = string.Empty; return val; */ return err_str; } - set { err_str = value;} + set { err_str = value; } } /** * Para la ventana de progreso */ - public MyCancelableProgressorSource ProgrSrc; + public MyCancelableProgressorSource ProgrSrc { get; set; } = null; public ProcesoEjecServ ProceSrv { get; set; } = null; + public FinProcServ FinProceSrv { get; set; } = null; + public TratamientoComun() + { + ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog); + ProceSrv = new ProcesoEjecServ(); + } + + public void ComienzaEjec(OliviaAddInPro.Services.ModosEjec modo) + { + //muestra progreso + OliviaGlob.progrDialog.Show(); + //oculta la ventana + OliviaGlob.ShowHidePane(false); + //comienza ejecución + Action> ac = FinProceSrv.finEjecuta; + EjecutaAsync(modo, ac); + } + public async void EjecutaAsync(ModosEjec modo, Action> ffin) + { + await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => + { + var res = Ejecuta(modo); + ffin(res); + return res; + }); + + } + public virtual Respuesta Ejecuta(ModosEjec modo) + { + Respuesta res = new Respuesta() { Value = TiposEjecucion.FinEjecNOk }; + res.Error.Add("No implementado"); + return res; + } } } diff --git a/OliviaAddInPro.csproj b/OliviaAddInPro.csproj index b10efd7..54aba14 100644 --- a/OliviaAddInPro.csproj +++ b/OliviaAddInPro.csproj @@ -151,7 +151,7 @@ - + diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index ee34d11..7ee19ab 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -332,45 +332,6 @@ namespace OliviaAddInPro.Services return false; } - - /** - * Borra los archivos exportados para el proceso - */ - public static void BorraFiles() - { - string[] list = null; - string capa_principal = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData); - string capa_principal_nw = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathNW); - - try - { - if (capa_principal == null) - return; - list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal + "*"); - if (list.Length > 0) - { - foreach (string f in list) - { - if (System.IO.Path.GetExtension(f) == ".lock") - continue; - System.IO.File.Delete(f); - } - } - if (capa_principal_nw == null) - return; - list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal_nw + "*"); - if (list.Length > 0) - { - foreach (string f in list) - { - System.IO.File.Delete(f); - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } + } } diff --git a/Services/FinProcServ.cs b/Services/FinProcServ.cs new file mode 100644 index 0000000..fc724f5 --- /dev/null +++ b/Services/FinProcServ.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using OliviaAddInPro.Model; +using OliviaAddInPro.Helper; +using System.Windows; + +namespace OliviaAddInPro.Services +{ + public class FinProcServ + { + public void finEjecuta(Respuesta res) + { + OliviaGlob.progrDialog.Hide(); + + //gestiona los flags, el estado de finok o finnok va en res.Vale + if (res.HasError) + { + HelperGlobal.ponMsg(res.Error.First()); + } + else + { + HelperGlobal.ponMsg(Resource1.String_exito); + } + Application.Current.Dispatcher.Invoke(new Action(() => { finEjecuta2(); })); + } + + + public void finEjecuta2() + { + //muestra la ventana + OliviaGlob.ShowHidePane(true); + + //importa resultados + + //borra los archivos que le toca borrar + //hay una funcion borrafiles en EjecServ, usar esa? + //pone modo config2 + } + + //se le llama cuando ha terminado el proceso de ejecución en Olivia Tasks + //puede haber ido bien, haberse cancelado, etc. En función de ello se realizan + //unas tareas u otras + public void FinProceso() + { + bool mal = true; + string err = ""; + + if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.FinEjecOk)) //ha terminado bien + { + if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecSecto)) //Ha terminado bien la sectorización + { + /*if (gdb.import_secto_ini()) + { + mal = false; + } + else + { + mal = true; + err = gdb.err_st; + }*/ + } + else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación + { + /*guarda_csv(); + if (gdb.import_planif()) + { + mal = false; + } + else + { + mal = true; + err = gdb.err_st; + }*/ + } + //actualiza los flags + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk); + OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2); + } + else if(OliviaGlob.HasFlagTipEjec(TiposEjecucion.FinEjecNOk)) //ha habido error + { + /*mal = true; + err = progr_eje.err_str;*/ + //actualiza los flags + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecNOk); + } + + if (mal) + { + HelperGlobal.ponMsg(err, System.Windows.MessageBoxImage.Error); + + } + + OliviaGlob.ShowHidePane(true); + + } + + /** + * Borra los archivos exportados para el proceso + */ + public static void BorraFiles() + { + string[] list = null; + string capa_principal = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData); + string capa_principal_nw = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathNW); + + try + { + if (capa_principal == null) + return; + list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal + "*"); + if (list.Length > 0) + { + foreach (string f in list) + { + if (System.IO.Path.GetExtension(f) == ".lock") + continue; + System.IO.File.Delete(f); + } + } + if (capa_principal_nw == null) + return; + list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal_nw + "*"); + if (list.Length > 0) + { + foreach (string f in list) + { + System.IO.File.Delete(f); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + } +} diff --git a/Services/ImportaResServ.cs b/Services/ImportaResServ.cs deleted file mode 100644 index fe85e5c..0000000 --- a/Services/ImportaResServ.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; -using OliviaAddInPro.Model; -using OliviaAddInPro.Helper; - -namespace OliviaAddInPro.Services -{ - class ImportaResServ - { - //se le llama cuando ha terminado el proceso de ejecución en Olivia Tasks - //puede haber ido bien, haberse cancelado, etc. En función de ello se realizan - //unas tareas u otras - public void FinProceso() - { - bool mal = true; - string err = ""; - - if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.FinEjecOk)) //ha terminado bien - { - if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecSecto)) //Ha terminado bien la sectorización - { - /*if (gdb.import_secto_ini()) - { - mal = false; - } - else - { - mal = true; - err = gdb.err_st; - }*/ - } - else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación - { - /*guarda_csv(); - if (gdb.import_planif()) - { - mal = false; - } - else - { - mal = true; - err = gdb.err_st; - }*/ - } - //actualiza los flags - OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk); - OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2); - } - else if(OliviaGlob.HasFlagTipEjec(TiposEjecucion.FinEjecNOk)) //ha habido error - { - /*mal = true; - err = progr_eje.err_str;*/ - //actualiza los flags - OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecNOk); - } - - if (mal) - { - HelperGlobal.ponMsg(err, System.Windows.MessageBoxImage.Error); - - } - - OliviaGlob.ShowHidePane(true); - - } - } -} diff --git a/Services/LimpiezaServ.cs b/Services/LimpiezaServ.cs index d0734b9..6df2098 100644 --- a/Services/LimpiezaServ.cs +++ b/Services/LimpiezaServ.cs @@ -27,13 +27,11 @@ namespace OliviaAddInPro.Services * Modo 0, sectorizar * Modo 1, planificar */ - public TareaRes Ejecuta(ModosEjec modo) + public Respuesta Ejecuta(ModosEjec modo) { - var res = new TareaRes() + var res = new Respuesta() { - Errores = false, - data = null, - msg = "" + Value = false }; MyCancelableProgressorSource cps = limp.ProgrSrc; @@ -43,8 +41,7 @@ namespace OliviaAddInPro.Services ErrStr = string.Empty; if (!PreparaConsulta(out nombFileAmbs)) { - res.msg= "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs; - res.Errores = true; + res.Error.Add("No se ha seleccionado una consulta válida" + limp.ConsultaAmbs); return res; } @@ -55,11 +52,10 @@ namespace OliviaAddInPro.Services //comienza ejecucion if(!ExportaEjec(modo, out msg)) { - res.Errores = true; - res.msg = msg; + res.Error.Add(msg); return res; } - + res.Value = true; return res; } diff --git a/Services/ProcesoEjecServ.cs b/Services/ProcesoEjecServ.cs index f6ca2f9..26d1da3 100644 --- a/Services/ProcesoEjecServ.cs +++ b/Services/ProcesoEjecServ.cs @@ -50,7 +50,7 @@ namespace OliviaAddInPro.Services { } - public Respuesta start(string cfg, CancelableProgressorSource cps) + public Respuesta start(string cfg, CancelableProgressorSource cps) { this.cps = cps; soc = new Cstr_socket(); @@ -63,7 +63,7 @@ namespace OliviaAddInPro.Services };*/ return run(); } - private Respuesta run() + private Respuesta run() { int nint = 0; int nint_max = 10; @@ -71,7 +71,7 @@ namespace OliviaAddInPro.Services bool first_send_cfg = true; bool fin = false; int lastprog = 0; - var res = new Respuesta() { Value = false }; + var res = new Respuesta() { Value = TiposEjecucion.FinEjecNOk }; try { @@ -130,7 +130,7 @@ namespace OliviaAddInPro.Services return res; } if (!res.HasError) - res.Value = true; + res.Value = TiposEjecucion.FinEjecOk; return res; } //funciones auxiliares---------------------------------------- diff --git a/Services/RecogidaServ.cs b/Services/RecogidaServ.cs index 39650bc..3cefd19 100644 --- a/Services/RecogidaServ.cs +++ b/Services/RecogidaServ.cs @@ -62,13 +62,11 @@ namespace OliviaAddInPro.Services * Modo 0, sectorizar * Modo 1, planificar */ - public TareaRes Ejecuta(ModosEjec modo) + public Respuesta Ejecuta(ModosEjec modo) { - var res = new TareaRes() + var res = new Respuesta() { - Errores = false, - data = null, - msg = "" + Value = false }; com = (TratamientoComun)reco; @@ -79,8 +77,7 @@ namespace OliviaAddInPro.Services if (!PreparaConsulta(out nombFileAmbs)) { - res.msg = "No se ha seleccionado una consulta válida" + reco.ConsultaAmbs; - res.Errores = true; + res.Error.Add("No se ha seleccionado una consulta válida" + reco.ConsultaAmbs); return res; } @@ -92,8 +89,7 @@ namespace OliviaAddInPro.Services //comienza ejecucion if (!ExportaEjec(modo, out msg)) { - res.Errores = true; - res.msg = msg; + res.Error.Add(msg); return res; } diff --git a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs index c44d4e6..70fd899 100644 --- a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs @@ -182,13 +182,7 @@ namespace OliviaAddInPro HelperGlobal.ponMsg(err); return; } - //muestra progreso - OliviaGlob.progrDialog.Show(); - //oculta la ventana - OliviaGlob.ShowHidePane(false); - //comienza ejecución - Action ac = OliviaGlob.finEjecuta; - OliviaGlob.Limp.EjecutaAsync(modo, ac); + OliviaGlob.Limp.ComienzaEjec(modo); } } } diff --git a/ViewModel/Recogida/PaneRecogidaViewModel.cs b/ViewModel/Recogida/PaneRecogidaViewModel.cs index 3c8de57..a4b927f 100644 --- a/ViewModel/Recogida/PaneRecogidaViewModel.cs +++ b/ViewModel/Recogida/PaneRecogidaViewModel.cs @@ -230,13 +230,7 @@ namespace OliviaAddInPro HelperGlobal.ponMsg(err); return; } - //muestra la ventana de progreso - OliviaGlob.progrDialog.Show(); - //oculta la ventana - OliviaGlob.ShowHidePane(false); - //comienza ejecución - Action ac = OliviaGlob.finEjecuta; - OliviaGlob.Reco.EjecutaAsync(modo, ac); + OliviaGlob.Reco.ComienzaEjec(modo); } } }