diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 5596b61..43ac48c 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -21,6 +21,7 @@ using OliviaAddInPro.Model; using System.IO; using System.Diagnostics; using OliviaAddInPro.View; +using OliviaAddInPro.Model.contract; namespace OliviaAddInPro.Helper { @@ -830,7 +831,7 @@ namespace OliviaAddInPro.Helper return res; } - public static bool ExportShp2(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, CancelableProgressorSource cps, int incmax=100) + public static bool ExportShp2(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, IprocessManager cps, int incmax=100) { if (!System.IO.Directory.Exists(outpath)) System.IO.Directory.CreateDirectory(outpath); @@ -872,9 +873,9 @@ namespace OliviaAddInPro.Helper ///Exporta string[] args = { pathLayerIn, outpath, nameShp, whereClause }; // execute the tool - uint valini = cps.Value; + double valini = cps.GetProgress(); ; IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, - null, cps.CancellationTokenSource.Token, + null, null, (event_name, o) => // implement delegate and handle events { @@ -899,7 +900,7 @@ namespace OliviaAddInPro.Helper var av = (int)o; if (av > 0) { - cps.Value += (uint)((float)av/100*Math.Min(incmax, cps.Max-valini)); + cps.SetProgress( cps.GetProgress()+ ((double)av/100*Math.Min(incmax, 100-valini))); } // if ((int)o < 0) //System.Windows.MessageBox.Show(msg2); @@ -911,7 +912,7 @@ namespace OliviaAddInPro.Helper if (gpResult.IsCanceled) { - cps.CancellationTokenSource.Cancel(); + cps.Setcancelled(); return false; } if(gpResult.IsFailed) diff --git a/Helper/HelperGlobal.cs b/Helper/HelperGlobal.cs index 910bfa5..b27f0d0 100644 --- a/Helper/HelperGlobal.cs +++ b/Helper/HelperGlobal.cs @@ -9,6 +9,7 @@ using ArcGIS.Desktop.Framework.Dialogs; using System.Windows; using System.IO; using ArcGIS.Desktop.Framework.Threading.Tasks; +using OliviaAddInPro.Model.contract; namespace OliviaAddInPro.Helper { @@ -85,22 +86,23 @@ namespace OliviaAddInPro.Helper public class MyCancelableProgressorSource { - public CancelableProgressorSource _ProgrSrc; - public MyCancelableProgressorSource(ProgressDialog prodlg) + public IprocessManager _ProgrSrc; + public MyCancelableProgressorSource(IprocessManager prodlg) { - _ProgrSrc = new CancelableProgressorSource(prodlg); - _ProgrSrc.Max = 100; + _ProgrSrc = prodlg; } public void Init(string stat) { - _ProgrSrc.Value = 0; - _ProgrSrc.Status = stat; + _ProgrSrc.SetProgress(0); + _ProgrSrc.SetProceso(stat); } public void IncMessage(uint inc, string mes) { - if ((_ProgrSrc.Value + inc) < _ProgrSrc.Max) - _ProgrSrc.Value += inc; - _ProgrSrc.Message = mes; + var prog = _ProgrSrc.GetProgress() + inc; + if (prog > 100) + prog = 100; + _ProgrSrc.SetProgress(prog); + _ProgrSrc.SetEstado(mes); } } diff --git a/Model/Limpieza.cs b/Model/Limpieza.cs index e20b7ec..4121545 100644 --- a/Model/Limpieza.cs +++ b/Model/Limpieza.cs @@ -47,6 +47,8 @@ namespace OliviaAddInPro.Model { Serv = new LimpiezaServ(this); LanzaSrv = new LanzaLimpSrv(); + ProceSrv = new ProcesoEjecServ(); + ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel()); } public override Respuesta Ejecuta(ModosEjec modo) diff --git a/Model/OliviaGlob.cs b/Model/OliviaGlob.cs index 2201e37..4884114 100644 --- a/Model/OliviaGlob.cs +++ b/Model/OliviaGlob.cs @@ -34,6 +34,7 @@ namespace OliviaAddInPro.Model //ya al menos una primera vez //se pone este estado cuando ha terminado ya la primera vez } + static class OliviaGlob { /** @@ -101,7 +102,7 @@ namespace OliviaAddInPro.Model } public static EjecServ Serv { get; } = new EjecServ(); public static SpatialReference SpatRef { get; set; } = null; - public static ProgressDialog progrDialog { get; set; } = null; + public static MarchandoUnaDe progrDialog { get; set; } = null; #endregion Properties public static void Inicia() @@ -110,7 +111,7 @@ namespace OliviaAddInPro.Model IniDefault(); LimpiezaDef.iniciaLimpDef(); RecogidaDef.iniciaRecoDef(); - progrDialog = new ProgressDialog("Procesando", Resource1.String_cancel_progreso, 100, false); + progrDialog = new MarchandoUnaDe(); limp = new Limpieza(); reco = new Recogida(); SpatRef = ArcGIS.Core.Geometry.SpatialReferenceBuilder.CreateSpatialReference(GeneralDef.SpatRefDef); diff --git a/Model/contract/IprocessManager.cs b/Model/contract/IprocessManager.cs new file mode 100644 index 0000000..6d7b9f9 --- /dev/null +++ b/Model/contract/IprocessManager.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OliviaAddInPro.Model.contract +{ + public interface IprocessManager + { + void SetProceso(string proceso); + void SetEstado(string estado);//estado del proceso + void SetProgress(double progresPorcent); + double GetProgress(); + bool Getcancelled(); + void Setcancelled(); + } +} diff --git a/OliviaAddInPro.csproj b/OliviaAddInPro.csproj index 54aba14..afe5a47 100644 --- a/OliviaAddInPro.csproj +++ b/OliviaAddInPro.csproj @@ -140,6 +140,7 @@ + @@ -158,6 +159,7 @@ + @@ -168,6 +170,9 @@ + + MarchandoUnaDe.xaml + PropertyGridFilePickerLine.xaml @@ -241,6 +246,10 @@ + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index 7ee19ab..824193c 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -93,7 +93,7 @@ namespace OliviaAddInPro.Services ErrStr = "Error al exportar los ámbitos: " + HelperGdb.OutStr; return false; } - if (com.ProgrSrc._ProgrSrc.CancellationTokenSource.IsCancellationRequested) + if (com.ProgrSrc._ProgrSrc.Getcancelled()) { ErrStr = Resource1.String_cancel_progreso; return false; @@ -211,7 +211,7 @@ namespace OliviaAddInPro.Services } //guarda los nombres del shape OliviaGlob.Paths.PathNW = OliviaGlob.Paths.DirData + com.NombreShpExportNw; - if (com.ProgrSrc._ProgrSrc.CancellationTokenSource.IsCancellationRequested) + if (com.ProgrSrc._ProgrSrc.Getcancelled()) { ErrStr = Resource1.String_cancel_progreso; return false; diff --git a/Services/ProcesoEjecServ.cs b/Services/ProcesoEjecServ.cs index 3e98bcd..2667ee0 100644 --- a/Services/ProcesoEjecServ.cs +++ b/Services/ProcesoEjecServ.cs @@ -1,6 +1,7 @@ using ArcGIS.Desktop.Framework.Threading.Tasks; using OliviaAddIn; using OliviaAddInPro.Model; +using OliviaAddInPro.Model.contract; using System; using System.Collections.Generic; using System.Linq; @@ -28,7 +29,7 @@ namespace OliviaAddInPro.Services string tarea = ""; public string err_str = ""; double x, y; - CancelableProgressorSource cps; + IprocessManager cps; enum TiposActu { ActuMal, @@ -50,7 +51,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(); @@ -102,7 +103,7 @@ namespace OliviaAddInPro.Services } } - if (cps.Progressor.CancellationToken.IsCancellationRequested) //mira a ver si ha cancelado el usuario + if (cps.Getcancelled()) //mira a ver si ha cancelado el usuario { //se ha cancelado, lo envía al OliviaTask envia_cancel(); @@ -454,7 +455,7 @@ namespace OliviaAddInPro.Services */ private void pon_texto(String txt) { - cps.Message = txt; + cps.SetEstado(txt); } /* * Para poder actualizar la barra de progreso hay que llamar a invoke @@ -476,14 +477,14 @@ namespace OliviaAddInPro.Services if ((actu == TiposActu.ActuMal) || (actu == TiposActu.ActuFinNOk)) - cps.Status = "Proceso Finalizado con errores."; + cps.SetProceso("Proceso Finalizado con errores."); else if(actu == TiposActu.ActuFinOk) - cps.Status = "Proceso Finalizado."; + cps.SetProceso("Proceso Finalizado."); if (actu > TiposActu.ActuFinOk) - cps.Status = "Calculando..."; + cps.SetEstado("Calculando..."); if ((actu == TiposActu.ActuPermu) && !cancela) - cps.Status = "Calculando Permutaciones..."; ; + cps.SetEstado("Calculando Permutaciones..."); } /* * Para poder actualizar la barra de progreso hay que llamar a invoke @@ -492,8 +493,8 @@ namespace OliviaAddInPro.Services */ private void pon_progr(int pro) { - cps.Value = (uint)pro; - } + cps.SetProgress( pro); + } //configura los parámetros de la conexión public void ConfigConex() diff --git a/View/Comun/MarchandoUnaDe.xaml b/View/Comun/MarchandoUnaDe.xaml new file mode 100644 index 0000000..c84525b --- /dev/null +++ b/View/Comun/MarchandoUnaDe.xaml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/View/Comun/MarchandoUnaDe.xaml.cs b/View/Comun/MarchandoUnaDe.xaml.cs new file mode 100644 index 0000000..3734e07 --- /dev/null +++ b/View/Comun/MarchandoUnaDe.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace OliviaAddInPro +{ + /// + /// Lógica de interacción para MarchandoUnaDe.xaml + /// + public partial class MarchandoUnaDe : Window + { + public MarchandoUnaDe() + { + InitializeComponent(); + DataContext = new MarchandoUnaDeViewModel(); + } + + public MarchandoUnaDeViewModel GetViewModel() + { + if (DataContext is MarchandoUnaDeViewModel m) + return m; + return null; + } + } +} diff --git a/ViewModel/Comun/MarchandoUnaDeViewModel.cs b/ViewModel/Comun/MarchandoUnaDeViewModel.cs new file mode 100644 index 0000000..088624c --- /dev/null +++ b/ViewModel/Comun/MarchandoUnaDeViewModel.cs @@ -0,0 +1,65 @@ +using ArcGIS.Desktop.Framework.Contracts; +using OliviaAddInPro.Model.contract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OliviaAddInPro +{ + public class MarchandoUnaDeViewModel : PropertyChangedBase, IprocessManager + { + + private string textProceso; + public string TextProceso + { + get { return textProceso; } + set { base.SetProperty(ref textProceso, value, () => TextProceso); } + } + + private string textEstado; + public string TextEstado + { + get { return textEstado; } + set { base.SetProperty(ref textEstado, value, () => TextEstado); } + } + private double progreso; + + public double Progreso + { + get { return progreso; } + set { base.SetProperty(ref progreso, value, () => Progreso); } + } + + void IprocessManager.SetProceso(string proceso) + { + TextProceso = proceso; + } + + void IprocessManager.SetEstado(string estado) + { + TextEstado = estado; + } + + void IprocessManager.SetProgress(double progresPorcent) + { + Progreso = progresPorcent; + } + + double IprocessManager.GetProgress() + { + return Progreso; + } + + bool IprocessManager.Getcancelled() + { + return false; + } + + void IprocessManager.Setcancelled() + { + + } + } +} diff --git a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs index 70fd899..1070f90 100644 --- a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs @@ -10,13 +10,14 @@ using OliviaAddInPro.Helper; using static OliviaAddInPro.Model.ComunDef; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Framework.Contracts; + namespace OliviaAddInPro { class PaneLimpiezaViewModel : PanelViewModelBase { private PaneLimpiezaSub1ViewModel _subPanel1ViewModel; - Limpieza limp; - + Limpieza limp; + public MarchandoUnaDe marchando; public PaneLimpiezaViewModel() { _subPanel1ViewModel = new PaneLimpiezaSub1ViewModel(); @@ -176,13 +177,24 @@ namespace OliviaAddInPro public void Ejecuta(OliviaAddInPro.Services.ModosEjec modo) { string err = ""; - //comprueba datos de la ventana + //marchando + + + OliviaGlob.Limp.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel()); + OliviaGlob.progrDialog.Show(); + + //oculta la ventana + OliviaGlob.ShowHidePane(false); + if (!Lee(out err)) { HelperGlobal.ponMsg(err); return; } - OliviaGlob.Limp.ComienzaEjec(modo); + + Action ac = OliviaGlob.finEjecuta; + OliviaGlob.Limp.EjecutaAsync(modo, ac); + } } }