diff --git a/Button/ButtonLimp.cs b/Button/ButtonLimp.cs index 9dce555..96e4373 100644 --- a/Button/ButtonLimp.cs +++ b/Button/ButtonLimp.cs @@ -31,9 +31,9 @@ namespace OliviaAddInPro { ///Comprueba que existe la red navegable configurada - if (HelperGdb.GetGdb(OliviaGlob.Paths.PathGdbNw).Result == null) + if (!OliviaGlob.CompruebaNwYCampos()) { - HelperGlobal.ponMsg("No encuentra Gdb de red navegable, cambie Configuración: " + HelperGdb.OutStr, + HelperGlobal.ponMsg("No se encuentra red navegable, cambie Configuración: " + HelperGdb.OutStr, System.Windows.MessageBoxImage.Warning); } else @@ -45,6 +45,10 @@ namespace OliviaAddInPro DockpaneLimpiezaViewModel.Show(); } } + else if(OliviaGlob.IsProps()) + { + HelperGlobal.ponMsg(Resource1.String_estaenprops, System.Windows.MessageBoxImage.Warning); + } else { HelperGlobal.ponMsg(Resource1.String_existe_ejec, System.Windows.MessageBoxImage.Warning); diff --git a/Button/ButtonRec.cs b/Button/ButtonRec.cs index af25b78..d038386 100644 --- a/Button/ButtonRec.cs +++ b/Button/ButtonRec.cs @@ -28,9 +28,9 @@ namespace OliviaAddInPro if (OliviaGlob.TipoEjec==TiposEjecucion.Ninguno) { ///Comprueba que existe la red navegable configurada - if (HelperGdb.GetGdb(OliviaGlob.Paths.PathGdbNw).Result == null) + if (!OliviaGlob.CompruebaNwYCampos()) { - HelperGlobal.ponMsg("No encuentra Gdb de red navegable, cambie Configuración: " + HelperGdb.OutStr, + HelperGlobal.ponMsg("No se encuentra red navegable, cambie Configuración: " + HelperGdb.OutStr, System.Windows.MessageBoxImage.Warning); } else @@ -42,6 +42,10 @@ namespace OliviaAddInPro DockpaneRecogidaViewModel.Show(); } } + else if (OliviaGlob.IsProps()) + { + HelperGlobal.ponMsg(Resource1.String_estaenprops, System.Windows.MessageBoxImage.Warning); + } else { HelperGlobal.ponMsg(Resource1.String_existe_ejec, System.Windows.MessageBoxImage.Warning); diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 4048112..0eb5818 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -186,6 +186,8 @@ namespace OliviaAddInPro.Helper //y si no tiene devuelve vacío public static string GetPathGdb(string path) { + if (path == null) + return string.Empty; string pathGdb = string.Empty; int i = 0; if(path.Contains(GDB_EXT)) @@ -202,6 +204,8 @@ namespace OliviaAddInPro.Helper public static Task GetGdb(string pathGdb) { Geodatabase fileGeodatabase = null; + if (string.IsNullOrEmpty(pathGdb)) + return null; ReiniciaOutStr(); return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { @@ -228,6 +232,8 @@ namespace OliviaAddInPro.Helper public static FeatureClass GetFtClass(string pathFtClss) { FeatureClass ftclss = null; + if (string.IsNullOrEmpty(pathFtClss)) + return null; Geodatabase gdb = GetGdb(pathFtClss).Result; ReiniciaOutStr(); if (gdb != null) @@ -247,6 +253,8 @@ namespace OliviaAddInPro.Helper public static Task GetFtClass(string nameFtclss, Geodatabase gdb) { FeatureClass ftclss = null; + if (string.IsNullOrEmpty(nameFtclss)) + return null; ReiniciaOutStr(); return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { @@ -270,7 +278,7 @@ namespace OliviaAddInPro.Helper ReiniciaOutStr(); return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { - if (pathShp.Contains(SHP_EXT)) + if (!string.IsNullOrEmpty(pathShp) && pathShp.Contains(SHP_EXT)) { try { @@ -419,6 +427,35 @@ namespace OliviaAddInPro.Helper return true; } + /* + * Lee la capa que se ha seleccionzdo de recogida y se comprueba que contiene los campos necesarios + * Devuelve 0 si va todo bien, -1 si da error, y num>0 con los campos que no encuentra + */ + public static int CheckFileds(string pathCapa, string[] camps) + { + int i; + + if (string.IsNullOrEmpty(pathCapa)) + { + OutStr = "No se encuentra la capa"; + return -1; + } + OutStr = "No se encuentran el/los campo/s: "; + int mal = 0; + for (i = 0; i < camps.Length; i++) + { + if (!CheckField(pathCapa, camps[i])) + { + OutStr = OutStr + camps[i] + " "; + mal++; + } + } + if (mal == 0) + OutStr = ""; + return mal; + } + + //Devuelve comilla simple si el campo es de texto, o nada si es númerico //var whereClause = $"{SelectedField} = {Quote(f)}{FieldValue}{Quote(f)}"; public static string Quote(ArcGIS.Core.Data.Field f) diff --git a/Model/OliviaGlob.cs b/Model/OliviaGlob.cs index 5717e2f..3b6c24f 100644 --- a/Model/OliviaGlob.cs +++ b/Model/OliviaGlob.cs @@ -9,6 +9,10 @@ using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Framework.Threading.Tasks; using OliviaAddInPro.Helper; +using System.Net; +using System.Net.Sockets; +using System.IO; + namespace OliviaAddInPro.Model { [Flags] @@ -110,6 +114,17 @@ namespace OliviaAddInPro.Model limp = new Limpieza(); reco = new Recogida(); SpatRef = ArcGIS.Core.Geometry.SpatialReferenceBuilder.CreateSpatialReference(GeneralDef.SpatRefDef); + + Respuesta resp = coge_ip(); + if (!resp.Value && resp.HasError) + { + HelperGlobal.ponMsg(resp.Error.First()); + } + /*resp = comprueba_dlls(); + if (!resp.Value && resp.HasError) + { + HelperGlobal.ponMsg(resp.Error.First()); + }*/ } public static bool IsLimp() @@ -189,12 +204,111 @@ namespace OliviaAddInPro.Model } } + /** + * Comprueba que está configurada la red navegable e incluye los campos necesarios + */ + public static bool CompruebaNwYCampos() + { + ArcGIS.Core.Data.FeatureClass ft = HelperGdb.GetFtClass(OliviaGlob.Paths.PathGdbNw); + if (ft == null) + return false; + + int NCAMPS = 4; + string[] camps; + camps = new string[NCAMPS]; + camps[0] = ComunDef.CamposNW.cons_onew; + camps[1] = ComunDef.CamposNW.cons_kph; + camps[2] = ComunDef.CamposNW.cons_name; + camps[3] = ComunDef.CamposNW.cons_fow; + return HelperGdb.CheckFileds(OliviaGlob.Paths.PathGdbNw, camps) == 0; + } + /** + * Devuelve una lista de las ips locales + */ + public static string[] dame_local_ips() + { + IPHostEntry host; + List host_str = new List(); + + if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) + { + return null; + } + + host = Dns.GetHostEntry(Dns.GetHostName()); + foreach (var ip in host.AddressList) + { + if (ip.AddressFamily == AddressFamily.InterNetwork) + { + host_str.Add(ip.ToString()); + } + } + return host_str.ToArray(); + } + + /** + * Coge la ip local para la comunicación con OliviaTask + */ + static Respuesta coge_ip() + { + Respuesta resp = new Respuesta(); + try + { + string[] ips = OliviaGlob.dame_local_ips(); + if (ips != null && ips.Length > 0) + Conexion.Ip = ips[0]; + else + Conexion.Ip = "127.0.0.1"; + resp.Value = true; + return resp; + } + catch (Exception) + { + resp.Error.Add("Error al leer IP local"); + resp.Value = false; + return resp; + } + } + + /** + * La primera vez copia las dlls necesarias en el directorio del arcmap + */ + static Respuesta comprueba_dlls() + { + Respuesta resp = new Respuesta(); + string path_dll_dest = null, dll = null; + try + { + //comprueba utiles.dll + dll = "utiles.dll"; + + //path_dll_dest = Path.Combine(System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), dll); + path_dll_dest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dll); + if (!File.Exists(path_dll_dest)) + { + resp.Error.Add("No se encuentran las librerías necesarias, compruebe la instalación"); + resp.Value = false; + return resp; + } + resp.Value = true; + return resp; + } + catch (Exception) + { + resp.Error.Add("Error al comprobar las dll"); + resp.Value = false; + return resp; + } + } + /** * Inicializa los nombres por defecto de las variables, para debug por si no hay instalador */ public static void IniDefault() { + var c = ConfigServ.Serv.Leer(); + Paths.PathCfg = ""; Paths.PathWork = c.path_work; Paths.PathExeOlivia = c.path_exe; Paths.DirData = c.path_data; @@ -209,7 +323,7 @@ namespace OliviaAddInPro.Model Paths.PathSimbVSM = c.PathSimbVSM; Paths.PathSimbESRI = c.PathSimbESRI; Conexion.Puerto = c.Puerto; - Conexion.Ip = c.Ip; + //Conexion.Ip = c.Ip; //la lee en el momento Conexion.TiempoOutSocket = c.TiempoOutSocket; /////////////////////////////////////// diff --git a/Resource1.Designer.cs b/Resource1.Designer.cs index eb4aae1..96e1f13 100644 --- a/Resource1.Designer.cs +++ b/Resource1.Designer.cs @@ -96,6 +96,15 @@ namespace OliviaAddInPro { } } + /// + /// Busca una cadena traducida similar a Se debe cerrar la configuración antes de comenzar una ejecución.. + /// + internal static string String_estaenprops { + get { + return ResourceManager.GetString("String_estaenprops", resourceCulture); + } + } + /// /// Busca una cadena traducida similar a Ya existe una ejecución en marcha. /// @@ -105,6 +114,15 @@ namespace OliviaAddInPro { } } + /// + /// Busca una cadena traducida similar a La ejecución ha finalizado con éxito.. + /// + internal static string String_exito { + get { + return ResourceManager.GetString("String_exito", resourceCulture); + } + } + /// /// Busca una cadena traducida similar a OLIVIA | Configuración. /// diff --git a/Resource1.resx b/Resource1.resx index 81f44f0..2197e61 100644 --- a/Resource1.resx +++ b/Resource1.resx @@ -129,9 +129,15 @@ No se ha encontrado ningún elemento en la tabla que cumpla con los criterios seleccionados. + + Se debe cerrar la configuración antes de comenzar una ejecución. + Ya existe una ejecución en marcha + + La ejecución ha finalizado con éxito. + OLIVIA | Configuración diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index 0b6f0b7..ee34d11 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -37,7 +37,7 @@ namespace OliviaAddInPro.Services * Modo 0, sectorizar * Modo 1, planificar */ - public bool LanzaEjec(ModosEjec modo, out string ErrStr) + public bool ExportaEjec(ModosEjec modo, out string ErrStr) { ErrStr = string.Empty; try @@ -204,8 +204,7 @@ namespace OliviaAddInPro.Services //Prepara nombre de exportación com.NombreShpExportNw = prefNameExportNw + fechaHora + extShp; //exporta los datos de entrada - string capaNw =System.IO.Path.Combine(OliviaGlob.Paths.PathGdbNw, OliviaGlob.Capas.ftclass_ejes); - if (!HelperGdb.ExportShp2(capaNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, com.ProgrSrc._ProgrSrc,40)) + if (!HelperGdb.ExportShp2(OliviaGlob.Paths.PathGdbNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, com.ProgrSrc._ProgrSrc,40)) { ErrStr = "Error al exportar la red navegable: " + HelperGdb.OutStr; return false; @@ -220,7 +219,7 @@ namespace OliviaAddInPro.Services } catch (Exception ex) { - ErrStr = "Errores al comenzar la ejecución: " + ex.Message; + ErrStr = "Errores al exportar para comenzar la ejecución: " + ex.Message; return false; } return true; @@ -259,7 +258,7 @@ namespace OliviaAddInPro.Services } } //comprueba que, en el caso de ejes de vía, hayan metido polígono de exportación - if ((geomAux == null) && (com.CapaElems == OliviaGlob.Capas.ftclass_ejes)) + if ((geomAux == null) && (com.CapaElems == OliviaGlob.Paths.PathGdbNw)) { ErrStr = "Al emplear ejes de calle como ámbitos es necesario indicar polígono de exportación"; return null; @@ -307,35 +306,7 @@ namespace OliviaAddInPro.Services str += "_R" + com.TextGeomRestr; return str; - } - - /* - * Lee la capa que se ha seleccionzdo de recogida y se comprueba que contiene los campos necesarios - * Devuelve 0 si va todo bien, -1 si da error, y num>0 con los campos que no encuentra - */ - public int CompruebaCampos(string pathCapa, string[] camps) - { - int i; - - if (string.IsNullOrEmpty(pathCapa)) - { - ErrStr = "No se encuentra la capa"; - return -1; - } - ErrStr = "No se encuentran el/los campo/s: "; - int mal = 0; - for (i = 0; i < camps.Length; i++) - { - if (!HelperGdb.CheckField(pathCapa, camps[i])) - { - ErrStr = ErrStr + camps[i] + " "; - mal++; - } - } - if(mal==0) - ErrStr = ""; - return mal; - } + } public bool ComprCamposPlanif(string pathCapa) { @@ -344,7 +315,7 @@ namespace OliviaAddInPro.Services camps = new string[NCAMPS]; camps[0] = LimpiezaDef.Campos.consulta_sector; camps[1] = LimpiezaDef.Campos.consulta_secuen; - return CompruebaCampos(pathCapa, camps) == 0; + return HelperGdb.CheckFileds(pathCapa, camps) == 0; } /** diff --git a/Services/LanzaSrv/LanzaLimpSrv.cs b/Services/LanzaSrv/LanzaLimpSrv.cs index 51aafcf..b63d09d 100644 --- a/Services/LanzaSrv/LanzaLimpSrv.cs +++ b/Services/LanzaSrv/LanzaLimpSrv.cs @@ -29,14 +29,7 @@ namespace OliviaAddInPro.Services.LanzaSrv } OliviaGlob.TipoEjec = TiposEjecucion.Limp;//OliviaDef.GeneralDef.TiposOliv.OlivLimp; - /* - if (!OliviaGlob.gdb_limp.exporta(limp, modo == (int)Ejecuta.ModosEjec.Planif)) - { - res.Error.Add(OliviaGlob.gdb_limp.err_st; - res.Value = false; - return res; - } - */ + //configura el string de opciones if (!configura_ops_geo(limp, modo)) { @@ -45,8 +38,6 @@ namespace OliviaAddInPro.Services.LanzaSrv return res; } - //this.limp = limp; - //Llama al ejecuta del padre return base.ejec(NombreTratamiento); diff --git a/Services/LimpiezaServ.cs b/Services/LimpiezaServ.cs index d870753..d0734b9 100644 --- a/Services/LimpiezaServ.cs +++ b/Services/LimpiezaServ.cs @@ -53,7 +53,7 @@ namespace OliviaAddInPro.Services string msg = ""; //comienza ejecucion - if(!LanzaEjec(modo, out msg)) + if(!ExportaEjec(modo, out msg)) { res.Errores = true; res.msg = msg; @@ -154,7 +154,7 @@ namespace OliviaAddInPro.Services camps[2] = LimpiezaDef.Campos.consulta_observ; camps[3] = LimpiezaDef.Campos.consulta_anch_tip; camps[4] = LimpiezaDef.Campos.consulta_tipolo; - return CompruebaCampos(pathCapa, camps)==0; + return HelperGdb.CheckFileds(pathCapa, camps)==0; } /** * Lee la gdb y devuelve el array de ámbitos en función de si hay en la gdb o no diff --git a/Services/RecogidaServ.cs b/Services/RecogidaServ.cs index acb3d37..042adc6 100644 --- a/Services/RecogidaServ.cs +++ b/Services/RecogidaServ.cs @@ -36,7 +36,7 @@ namespace OliviaAddInPro.Services camps[3] = RecogidaDef.campos_def.cons_lateral; camps[4] = RecogidaDef.campos_def.cons_uds; camps[5] = RecogidaDef.campos_def.cons_kgrec; - int compCamp = CompruebaCampos(pathCapa, camps); + int compCamp = HelperGdb.CheckFileds(pathCapa, camps); if (compCamp == 0) return 0; else if (compCamp == 1 && ErrStr.Contains(RecogidaDef.campos_def.cons_kgrec)) @@ -89,7 +89,7 @@ namespace OliviaAddInPro.Services string msg = ""; //comienza ejecucion - if (!LanzaEjec(modo, out msg)) + if (!ExportaEjec(modo, out msg)) { res.Errores = true; res.msg = msg; diff --git a/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs index 0065dfc..d8d79df 100644 --- a/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs @@ -338,13 +338,13 @@ namespace OliviaAddInPro //permite visualizar los elementos del ancho de vía que se activará cuando se seleccione la opción genérica de ejes de calle siempre y cuando el tiempo de tratamiento sea en ml/h if (UdsTTto != (int)GeneralDef.OlvTiposTto.OlvTipTtoM2h_eje) { - VisTextAnchoVia = System.Windows.Visibility.Visible; + VisTextAnchoVia = System.Windows.Visibility.Visible; } } else { - VisTextAnchoVia = System.Windows.Visibility.Hidden; - } + VisTextAnchoVia = System.Windows.Visibility.Hidden; + } /*if (((TipoTto == (int)LimpiezaDef.TiposTto.TtoBaldMecCalz) && (SelOpAmb >= 2)) || ((TipoTto == (int)LimpiezaDef.TiposTto.TtoCaidaHoja) && (SelOpAmb >= 2))) EnableListBoxAmb = false; //si uno de los ámbitos es "eje de calle" no se puede combinar con los demás ámbitos diff --git a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs index 342117b..24df67f 100644 --- a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs @@ -79,6 +79,11 @@ namespace OliviaAddInPro return false; } limp.CapaElems = _subPanel1ViewModel.CapaElems; + //pone que la capa de elementos es la red navegable, que es la que va a exportar + if (_subPanel1ViewModel.SelOpAmb == 1) + { + limp.CapaElems = OliviaGlob.Paths.PathGdbNw; + } //lee el tipo tto if (_subPanel1ViewModel.TipoTto == (int)LimpiezaDef.TiposTto.TtoNoDef) @@ -149,7 +154,7 @@ namespace OliviaAddInPro err_str = "El formato introducido para el ancho de la vía no es válido."; return false; } - } + } //lee las propiedades comunes a recogida if (!LeeComun(limp,out err_str)) @@ -184,13 +189,5 @@ namespace OliviaAddInPro Action ac = finEjecuta; OliviaGlob.Limp.EjecutaAsync(modo, ac); } - public void finEjecuta(TareaRes res) - { - OliviaGlob.progrDialog.Hide(); - if (res.Errores) - { - HelperGlobal.ponMsg(res.msg); - } - } } } diff --git a/ViewModel/PanelViewModelBase.cs b/ViewModel/PanelViewModelBase.cs index 7f3d1e0..901addb 100644 --- a/ViewModel/PanelViewModelBase.cs +++ b/ViewModel/PanelViewModelBase.cs @@ -125,6 +125,19 @@ namespace OliviaAddInPro return true; } + + public void finEjecuta(OliviaAddInPro.Model.ComunDef.TareaRes res) + { + OliviaGlob.progrDialog.Hide(); + if (res.Errores) + { + HelperGlobal.ponMsg(res.msg); + } + else + { + HelperGlobal.ponMsg(Resource1.String_exito); + } + } } //****************************************************** diff --git a/ViewModel/Recogida/PaneRecogidaViewModel.cs b/ViewModel/Recogida/PaneRecogidaViewModel.cs index a7cac08..70671d9 100644 --- a/ViewModel/Recogida/PaneRecogidaViewModel.cs +++ b/ViewModel/Recogida/PaneRecogidaViewModel.cs @@ -233,15 +233,6 @@ namespace OliviaAddInPro Action ac = finEjecuta; OliviaGlob.Reco.EjecutaAsync(modo, ac); - - } - public void finEjecuta(TareaRes res) - { - OliviaGlob.progrDialog.Hide(); - if (res.Errores) - { - HelperGlobal.ponMsg(res.msg); - } } } }