ProcesoEjecServ programado, falta llamada y probar
parent
3672be10aa
commit
e1a471b647
|
|
@ -1,5 +1,6 @@
|
|||
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
||||
using OliviaAddIn;
|
||||
using OliviaAddInPro.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -42,12 +43,14 @@ namespace OliviaAddInPro.Services
|
|||
ActuN,
|
||||
}
|
||||
|
||||
public string Ip { get; set; }
|
||||
public int Puerto { get; set; }
|
||||
|
||||
public ProcesoEjecServ()
|
||||
{
|
||||
|
||||
}
|
||||
public void start(string cfg, CancelableProgressorSource cps)
|
||||
public Respuesta<bool> start(string cfg, CancelableProgressorSource cps)
|
||||
{
|
||||
this.cps = cps;
|
||||
soc = new Cstr_socket();
|
||||
|
|
@ -58,9 +61,9 @@ namespace OliviaAddInPro.Services
|
|||
{
|
||||
run();
|
||||
};*/
|
||||
run();
|
||||
return run();
|
||||
}
|
||||
private void run()
|
||||
private Respuesta<bool> run()
|
||||
{
|
||||
int nint = 0;
|
||||
int nint_max = 10;
|
||||
|
|
@ -68,7 +71,8 @@ namespace OliviaAddInPro.Services
|
|||
bool first_send_cfg = true;
|
||||
bool fin = false;
|
||||
int lastprog = 0;
|
||||
TiposActu pp;
|
||||
var res = new Respuesta<bool>() { Value = false };
|
||||
|
||||
try
|
||||
{
|
||||
do
|
||||
|
|
@ -82,8 +86,10 @@ namespace OliviaAddInPro.Services
|
|||
{
|
||||
if (nint >= nint_max)
|
||||
{
|
||||
err_str = "Error en la comunicación con OliviaTask";
|
||||
actualiza(TiposActu.ActuMal);
|
||||
res.Error.Add("Error en la comunicación con OliviaTask");
|
||||
var act = new Respuesta<TiposActu>() { Value = TiposActu.ActuMal };
|
||||
act.Error.AddRange(res.Error);
|
||||
actualiza(act);
|
||||
}
|
||||
else
|
||||
nint++;
|
||||
|
|
@ -92,7 +98,7 @@ namespace OliviaAddInPro.Services
|
|||
first_send_cfg = false;
|
||||
}
|
||||
|
||||
if (Interlocked.Equals(m_out, 1)) //mira a ver si ha cancelado el usuario
|
||||
if (cps.Progressor.CancellationToken.IsCancellationRequested) //mira a ver si ha cancelado el usuario
|
||||
{
|
||||
//se ha cancelado, lo envía al OliviaTask
|
||||
envia_cancel();
|
||||
|
|
@ -100,71 +106,333 @@ namespace OliviaAddInPro.Services
|
|||
sal = true;
|
||||
else
|
||||
{
|
||||
Interlocked.Exchange(ref m_out, (int)0);
|
||||
cancela_permu = false;
|
||||
}
|
||||
}
|
||||
else if (!first_send_cfg && ((Math.Abs(Environment.TickCount) - lastprog) >= m_tm_progr) && !fin) //en caso normal, todo va bien, pide el progreso y la tarea
|
||||
{
|
||||
//solo pide la programación cada m_tm_progr milis
|
||||
pp = pide_progr();
|
||||
if (pp > TiposActu.ActuFinOk)
|
||||
var pp = pide_progr();
|
||||
if (pp .Value> TiposActu.ActuFinOk)
|
||||
fin = true;
|
||||
actualiza(pp);
|
||||
lastprog = Environment.TickCount;
|
||||
}
|
||||
|
||||
} while (!sal);
|
||||
|
||||
//manda cerrar la ventana porque ha terminado
|
||||
cierra();
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
res.Error.Add(e.Message);
|
||||
//MessageBox.Show("Error durante el proceso.", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
return res;
|
||||
}
|
||||
if (!res.HasError)
|
||||
res.Value = true;
|
||||
return res;
|
||||
}
|
||||
//funciones auxiliares----------------------------------------
|
||||
private void cierra()
|
||||
private bool conecta()
|
||||
{
|
||||
|
||||
if (!conectado)
|
||||
{
|
||||
if (!soc.conecta(Ip, Puerto))
|
||||
{
|
||||
conectado = false;
|
||||
return false;
|
||||
}
|
||||
conectado = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Envía la información de la configuración por socket a OliviaTask
|
||||
*/
|
||||
public bool envia_cfg()
|
||||
{
|
||||
return false;
|
||||
string args;
|
||||
|
||||
try
|
||||
{
|
||||
if (!conecta())
|
||||
return false;
|
||||
|
||||
if (str_cfg == null || str_cfg.Length == 0)
|
||||
return false;
|
||||
|
||||
if (!soc.envia(str_cfg))
|
||||
{
|
||||
conectado = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
args = soc.recibe();
|
||||
if ((args.Length == 0) || (args != GeneralDef.SockConfOk))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pide por socket la información de sectorización a OliviaTask
|
||||
*/
|
||||
private bool pide_sect()
|
||||
{
|
||||
return false;
|
||||
//pide sectorización porque ya ha sido avisado de que ha terminado
|
||||
try
|
||||
{
|
||||
if (!conecta())
|
||||
return false;
|
||||
|
||||
//pide secto
|
||||
if (!soc.envia(GeneralDef.SockSect))
|
||||
{
|
||||
conectado = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
//recibe sectorización
|
||||
args = soc.recibe();
|
||||
if (args.Length == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pide por socket la información de progreso a OliviaTask
|
||||
* Devuelve 0 si ha ido mal, 1 si ha ido bien, 2 si ha recibido que hay que pedir sectorización
|
||||
*/
|
||||
private TiposActu pide_progr()
|
||||
private Respuesta<TiposActu> pide_progr()
|
||||
{
|
||||
return TiposActu.ActuMal;
|
||||
TiposActu tt;
|
||||
int i;
|
||||
var res = new Respuesta<TiposActu> { Value = TiposActu.ActuMal };
|
||||
//pide progreso y tarea por la que va
|
||||
try
|
||||
{
|
||||
if (!conecta())
|
||||
{
|
||||
res.Error.Add("Error en la comunicación con OliviaTask");
|
||||
return res;
|
||||
}
|
||||
|
||||
//pide progreso
|
||||
if (!soc.envia(GeneralDef.SockProgr))
|
||||
{
|
||||
conectado = false;
|
||||
res.Error.Add("Error en la comunicación con OliviaTask");
|
||||
return res;
|
||||
}
|
||||
|
||||
//recibe progreso
|
||||
args = soc.recibe();
|
||||
if (args.Length == 0)
|
||||
{
|
||||
res.Value = TiposActu.ActuNoActu;
|
||||
return res;
|
||||
}
|
||||
|
||||
//comprueba progreso
|
||||
try
|
||||
{
|
||||
progr = Convert.ToInt32(args);
|
||||
if (progr < 0 || progr > GeneralDef.ProgrMax)
|
||||
{
|
||||
res.Value = TiposActu.ActuNoActu;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
res.Value = TiposActu.ActuNoActu;
|
||||
return res;
|
||||
}
|
||||
|
||||
//pide tarea
|
||||
if (!soc.envia(GeneralDef.SockTarea))
|
||||
{
|
||||
res.Error.Add( "");
|
||||
return res;
|
||||
}
|
||||
|
||||
//recibe tarea
|
||||
args = soc.recibe();
|
||||
if (args.Length == 0)
|
||||
{
|
||||
res.Error.Add("Error recibe tarea mal");
|
||||
return res;
|
||||
}
|
||||
if (args == "0") //se ha mezclado el progreso, vuelve a recibir la tarea
|
||||
args = soc.recibe();
|
||||
if (args.Length == 0)
|
||||
{
|
||||
res.Error.Add("Error recibe tarea mal");
|
||||
return res;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
tt = TiposActu.ActuBien;
|
||||
//comprueba tarea
|
||||
if (args.StartsWith(GeneralDef.SockSectFin))
|
||||
{
|
||||
i = GeneralDef.SockSectFin.Length;
|
||||
tt = TiposActu.ActuSect;
|
||||
}
|
||||
else if (args.StartsWith(GeneralDef.SockPlanFin))
|
||||
{
|
||||
i = GeneralDef.SockPlanFin.Length;
|
||||
tt = TiposActu.ActuPlan;
|
||||
}
|
||||
else if (args.StartsWith(GeneralDef.SockFinOk))
|
||||
{
|
||||
i = GeneralDef.SockFinOk.Length;
|
||||
tt = TiposActu.ActuFinOk;
|
||||
}
|
||||
else if (args.StartsWith(GeneralDef.SockFinNOk))
|
||||
{
|
||||
i = GeneralDef.SockFinNOk.Length;
|
||||
tt = TiposActu.ActuFinNOk;
|
||||
}
|
||||
else if (args.Contains("permutaciones"))
|
||||
{
|
||||
tt = TiposActu.ActuPermu;
|
||||
}
|
||||
else if (args.Contains("multitask"))
|
||||
{
|
||||
tt = TiposActu.ActuMulti;
|
||||
}
|
||||
modo_fin = (int)tt;
|
||||
|
||||
tarea = args.Substring(i);
|
||||
res.Value = tt;
|
||||
return res;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
res.Error.Add("Error al preguntar por el progreso.");
|
||||
return res;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Envía a OliviaTask la orden de cancelar el proceso
|
||||
*/
|
||||
private bool envia_cancel()
|
||||
private Respuesta<bool> envia_cancel()
|
||||
{
|
||||
return false;
|
||||
var res = new Respuesta<bool> { Value = false };
|
||||
try
|
||||
{
|
||||
if (!conectado)
|
||||
return res;
|
||||
|
||||
//envía cancel
|
||||
if (!soc.envia(GeneralDef.SockCanc))
|
||||
return res;
|
||||
|
||||
//recibe respuesta
|
||||
args = soc.recibe();
|
||||
if (args.Length == 0)
|
||||
return res;
|
||||
|
||||
//comprueba que ok
|
||||
if (args != GeneralDef.SockCancOk)
|
||||
return res;
|
||||
res.Value = true;
|
||||
return res;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
res.Error.Add("Error al cancelar el progreso.");
|
||||
res.Value = false;
|
||||
//MessageBox.Show("Error al cancelar el progreso.", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Actualiza la barra de progreso
|
||||
* bool fallo_soc : indica si ha habido fallo en el socket
|
||||
*/
|
||||
private void actualiza(TiposActu actu)
|
||||
private void actualiza(Respuesta<TiposActu> actu)
|
||||
{
|
||||
try
|
||||
{
|
||||
permu = false;
|
||||
//actualiza la barra de tarea y el texto
|
||||
switch (actu.Value)
|
||||
{
|
||||
case TiposActu.ActuBien:
|
||||
{
|
||||
pon_progr(progr);
|
||||
pon_texto(tarea);
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuMal:
|
||||
{
|
||||
if (actu.HasError)
|
||||
pon_texto(actu.Error.FirstOrDefault());
|
||||
else
|
||||
pon_texto(tarea);
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuFinOk:
|
||||
{
|
||||
pon_progr(100);
|
||||
pon_texto("Finalizado proceso con éxito");
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuFinNOk:
|
||||
{
|
||||
pon_progr(100);
|
||||
err_str = "Finalizado proceso con fallos\n" + tarea;
|
||||
pon_texto(err_str);
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuSect:
|
||||
{
|
||||
pon_progr(100);
|
||||
pon_texto("Finalizada sectorización\n" + tarea);
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuPlan:
|
||||
{
|
||||
pon_progr(100);
|
||||
pon_texto("Finalizada planificación\n" + tarea);
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuPermu:
|
||||
{
|
||||
permu = true;
|
||||
pon_texto(tarea);
|
||||
//pon_estilo(ProgressBarStyle.Marquee);
|
||||
break;
|
||||
}
|
||||
case TiposActu.ActuMulti:
|
||||
{
|
||||
pon_texto(tarea);
|
||||
//pon_estilo(ProgressBarStyle.Marquee);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if (actu != TiposActu.ActuPermu && actu != TiposActu.ActuMulti)
|
||||
pon_estilo(ProgressBarStyle.Continuous);*/
|
||||
pon_barstate(actu.Value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//MessageBox.Show("Error al actualizar el progreso.", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Para poder actualizar el texto de la ventana de progreso hay que llamar a invoke
|
||||
|
|
@ -172,6 +440,7 @@ namespace OliviaAddInPro.Services
|
|||
*/
|
||||
private void pon_texto(String txt)
|
||||
{
|
||||
cps.Message = txt;
|
||||
}
|
||||
/*
|
||||
* Para poder actualizar la barra de progreso hay que llamar a invoke
|
||||
|
|
@ -180,6 +449,7 @@ namespace OliviaAddInPro.Services
|
|||
*/
|
||||
private void pon_estilo()
|
||||
{
|
||||
//cps.Status
|
||||
}
|
||||
/*
|
||||
* Para poder actualizar la barra de progreso hay que llamar a invoke
|
||||
|
|
@ -188,6 +458,18 @@ namespace OliviaAddInPro.Services
|
|||
*/
|
||||
private void pon_barstate(TiposActu actu)
|
||||
{
|
||||
int col = 1;
|
||||
|
||||
|
||||
if ((actu == TiposActu.ActuMal) || (actu == TiposActu.ActuFinNOk))
|
||||
cps.Status = "Proceso Finalizado con errores.";
|
||||
else if(actu == TiposActu.ActuFinOk)
|
||||
cps.Status = "Proceso Finalizado.";
|
||||
|
||||
if (actu > TiposActu.ActuFinOk)
|
||||
cps.Status = "Calculando...";
|
||||
if ((actu == TiposActu.ActuPermu) && !cancela)
|
||||
cps.Status = "Calculando Permutaciones..."; ;
|
||||
}
|
||||
/*
|
||||
* Para poder actualizar la barra de progreso hay que llamar a invoke
|
||||
|
|
@ -196,6 +478,7 @@ namespace OliviaAddInPro.Services
|
|||
*/
|
||||
private void pon_progr(int pro)
|
||||
{
|
||||
cps.Value = (uint)pro;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue