Ordenación Tareas asincronas limpieza
parent
b0e389aada
commit
1e77fc2ac5
|
|
@ -636,18 +636,18 @@ namespace OliviaAddInPro.Helper
|
|||
return res;
|
||||
}
|
||||
|
||||
public static async Task<bool> 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<string>)(() =>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TareaRes> EjecutaAsync(ModosEjec modo, Action<TareaRes> ffin)
|
||||
{
|
||||
var tarea = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<TareaRes>)(() =>
|
||||
{
|
||||
var res = Ejecuta(modo);
|
||||
ffin(res);
|
||||
return res;
|
||||
|
||||
}));
|
||||
|
||||
return tarea;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<TareaRes> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue