diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 664526c..ea92052 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -636,18 +636,18 @@ namespace OliviaAddInPro.Helper return res; } - public static async Task ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, ProgressorSource progrDialog = null) + public static bool ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath,out string msgOut, ProgressorSource progrDialog = null) { + msgOut = ""; if (!System.IO.Directory.Exists(outpath)) System.IO.Directory.CreateDirectory(outpath); ReiniciaOutStr(); System.Threading.CancellationTokenSource _cts= new System.Threading.CancellationTokenSource(); - var fin = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => - { - var progSrc = new CancelableProgressorSource(); - string[] args = { pathLayerIn, outpath }; - // execute the tool - IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", args, + + var progSrc = new CancelableProgressorSource(); + string[] args = { pathLayerIn, outpath }; + // execute the tool + IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", args, null, _cts.Token, (event_name, o) => // implement delegate and handle events @@ -662,7 +662,7 @@ namespace OliviaAddInPro.Helper case "OnProgressMessage": { string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o }); - progrDialog.Message = (string)o; + //progrDialog.Message = (string)o; Debug.WriteLine(msg); //System.Windows.MessageBox.Show(msg); //_cts.Cancel(); @@ -681,24 +681,15 @@ namespace OliviaAddInPro.Helper } }).Result; - //renombrado de ficheros: - if (!RenameSHP(outpath, pathLayerIn, nameShp)) - return null; - - return gpResult.ReturnValue; - })); - - fin.Wait(); - if (string.IsNullOrEmpty(fin.Result)) + //renombrado de ficheros: + if (!RenameSHP(outpath, pathLayerIn, nameShp)) { - OutStr = "Ha ocurrido un error en la herramienta de GeoProcesamiento"; + msgOut = "Error al exportar a shp."; return false; + } - else - { - OutStr = "Ok: " + fin.Result; - return true; - } + + return true; } } diff --git a/Model/Limpieza.cs b/Model/Limpieza.cs index 77157ff..24a7243 100644 --- a/Model/Limpieza.cs +++ b/Model/Limpieza.cs @@ -9,6 +9,7 @@ using System.Collections.ObjectModel; using ArcGIS.Core.CIM; using ArcGIS.Core.Data; using OliviaAddInPro.Services; +using static OliviaAddInPro.Model.LimpiezaDef; namespace OliviaAddInPro.Model { @@ -43,15 +44,17 @@ namespace OliviaAddInPro.Model public Limpieza() { Serv = new LimpiezaServ(this); - } - public void Ejecuta(ModosEjec modo) + } + + public TareaRes Ejecuta(ModosEjec modo) { - bool bien = true; + TareaRes res = null; if (modo == ModosEjec.Sectoriza) - bien = Serv.Sectoriza(); + res = Serv.Sectoriza(); else if (modo == ModosEjec.Planifica) - bien=Serv.Planifica(); - if(!bien) + res = Serv.Planifica(); + return res; + /*if(!res) { string msg; if (Serv.ErrStr.Length > 0) @@ -59,7 +62,19 @@ namespace OliviaAddInPro.Model else msg = "Han ocurrido errores al comenzar la ejeción."; HelperGlobal.ponMsg(msg); - } + }*/ + } + public async Task EjecutaAsync(ModosEjec modo, Action ffin) + { + var tarea = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => + { + var res = Ejecuta(modo); + ffin(res); + return res; + + })); + + return tarea; } } } diff --git a/Model/LimpiezaDef.cs b/Model/LimpiezaDef.cs index 398aa7c..05c4311 100644 --- a/Model/LimpiezaDef.cs +++ b/Model/LimpiezaDef.cs @@ -788,6 +788,12 @@ namespace OliviaAddInPro.Model LimpiezaDef.filtro_str[(int)LimpiezaDef.AmbitsTra.AmbPipi] = LimpiezaDef.Campos.consulta_entidad + " = '" + LimpiezaDef.Atributos.atr_pipi + "'"; LimpiezaDef.filtro_str[(int)LimpiezaDef.AmbitsTra.AmbSane] = LimpiezaDef.Campos.consulta_entidad + " = '" + LimpiezaDef.Atributos.atr_sane + "'"; } + public class TareaRes + { + public bool Errores { get; set; } + public object data { get; set; } + public string msg { get; set; } + } } } diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index aa6a104..99cd696 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -35,73 +35,48 @@ namespace OliviaAddInPro.Services * Modo 0, sectorizar * Modo 1, planificar */ - public bool ComienzaEjec(ModosEjec modo) + public bool ComienzaEjec(ModosEjec modo, out string ErrStr) { - using (OliviaGlob.progrDialog = new ProgressDialog("Exportando Datos", "Cancelar", 100, true)) + bool fue_mal = false; + ErrStr = string.Empty; + //Cuenta las filas que cumplen la consulta + int nelems = HelperGdb.GetNumElems(com.CapaElems, com.ConsultaAmbs); + if (nelems <= 0) + { + ErrStr = "No existen ámbitos que cumplan las condiciones introducidas para la exportación " + com.ConsultaAmbs; + fue_mal = true; + } + + //Obtiene la geometría que envuelve a los ámbitos + Geometry geom_export = null; + if (!fue_mal) + { + geom_export = GetGeomAmbitsExport(); + if (geom_export == null || geom_export.IsEmpty) + { + ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + ErrStr; + fue_mal = true; + } + } + + //crea el filtro de exportación + if (!fue_mal) { - var status = new ProgressorSource(OliviaGlob.progrDialog); - - OliviaGlob.progrDialog.Show(); - bool fue_mal = false; - status.Message = "Exportando Datos"; - status.Value = 0; - status.Status = "Exportando Datos"; - status.Max = 100; - //esconde el pane - OliviaGlob.ShowHidePane(false); - ErrStr = string.Empty; + //mira spatialreference de los datos de entrada + spatRef = geom_export.SpatialReference; + filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export); + fue_mal = filtroEspacial == null; + if(fue_mal) + ErrStr = "error al crear el filtro de exportacion"; - //Cuenta las filas que cumplen la consulta - int nelems = HelperGdb.GetNumElems(com.CapaElems, com.ConsultaAmbs); - if (nelems <= 0) - { - ErrStr = "No existen ámbitos que cumplan las condiciones introducidas para la exportación " + com.ConsultaAmbs; - fue_mal = true; - } - - //Obtiene la geometría que envuelve a los ámbitos - Geometry geom_export = null; - if (!fue_mal) - { - geom_export = GetGeomAmbitsExport(); - if (geom_export == null || geom_export.IsEmpty) - { - ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + ErrStr; - fue_mal = true; - } - - if (geom_export == null || geom_export.IsEmpty) - { - fue_mal = true; - } - } - - //crea el filtro de exportación - if (!fue_mal) - { - //mira spatialreference de los datos de entrada - spatRef = geom_export.SpatialReference; - filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export); - if (filtroEspacial == null) - { - fue_mal = true; - } - } - - if (!fue_mal) - { - Ejecuta(modo, status); - OliviaGlob.progrDialog.Hide(); - return true; - } - - OliviaGlob.progrDialog.Hide(); - //fue mal - //muestra pane - OliviaGlob.ShowHidePane(true); - - return false; } + + + if (!fue_mal) + fue_mal = Ejecuta(modo, out ErrStr); + + return fue_mal; + } @@ -203,20 +178,12 @@ namespace OliviaAddInPro.Services /** * Exporta y lanza proceso y ventana de proceso */ - public void Ejecuta(ModosEjec modo, ProgressorSource dlgProcess) + public bool Ejecuta(ModosEjec modo, out string msg) { - //lanza ventana de progreso - - + msg = ""; //exporta los datos de entrada - bool res=HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, dlgProcess).Result; - if(!res) - { - string msg = HelperGdb.OutStr; - if (!string.IsNullOrEmpty(msg)) - msg = "Han ocurrido errores al convertir a shape."; - HelperGlobal.ponMsg(msg); - } + return HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, out msg); + diff --git a/Services/LimpiezaServ.cs b/Services/LimpiezaServ.cs index 6d0c703..35dff16 100644 --- a/Services/LimpiezaServ.cs +++ b/Services/LimpiezaServ.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using static OliviaAddInPro.Model.LimpiezaDef; namespace OliviaAddInPro.Services { @@ -20,21 +21,31 @@ namespace OliviaAddInPro.Services { limp = _limp; } + /** * Acciones para comenzar ejecución * Modo 0, sectorizar * Modo 1, planificar */ - public bool Sectoriza() + public TareaRes Sectoriza() { + var res = new TareaRes() + { + Errores = false, + data = null, + msg = "" + }; + com = (TratamientoComun)limp; string nombFileAmbs = string.Empty; + //Prepara consulta ErrStr = string.Empty; if (!PreparaConsulta(out nombFileAmbs)) { - ErrStr = "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs; - return false; + res.msg= "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs; + res.Errores = true; + return res; } //Prepara nombre @@ -44,13 +55,16 @@ namespace OliviaAddInPro.Services //Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp limp.NombreShpExport = prefNameExport + "T" + limp.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp; + string msg = ""; //comienza ejecucion - if(!ComienzaEjec(ModosEjec.Sectoriza)) + if(!ComienzaEjec(ModosEjec.Sectoriza, out msg)) { - return false; + res.Errores = true; + res.msg = msg; + return res; } - return true; + return res; } @@ -65,25 +79,33 @@ namespace OliviaAddInPro.Services return true; } - public bool Planifica() + public TareaRes Planifica() { + TareaRes res = new TareaRes() + { + Errores = false, + msg = "", + data = null + }; //se asegura que tiene todo para planif - ErrStr = string.Empty; + //ErrStr = string.Empty; if (!CompruebaPlanif()) { - ErrStr = "En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, necesarias para planificar"; - return false; + res.msg = "En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, necesarias para planificar"; + res.Errores = true; + return res; } //Prepara consulta string nombFileAmbs = string.Empty; //Prepara consulta if (!PreparaConsulta(out nombFileAmbs)) { - ErrStr = "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs; - return false; + res.msg = "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs; + res.Errores = true; + return res; } - return true; + return res; } public string DameAmbsConsulta(out string ambs_file) diff --git a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs index 07079ad..d1a8ad3 100644 --- a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media.Imaging; using OliviaAddInPro.Helper; +using static OliviaAddInPro.Model.LimpiezaDef; namespace OliviaAddInPro { @@ -151,8 +152,17 @@ namespace OliviaAddInPro return; } - OliviaGlob.Limp.Ejecuta(modo); - + Action ac = finEjecuta; + var res = OliviaGlob.Limp.EjecutaAsync(modo, ac); + //res. + } + public void finEjecuta(TareaRes res) + { + if (res.Errores) + { + HelperGlobal.ponMsg(res.msg); + } + HelperGlobal.ponMsg("Proceso terminado"); } } }