Avanzo como puedo en la importación

Elena/develop
Elena 2022-05-26 08:57:31 +02:00
parent d267229f9e
commit 9e8f4e6d25
9 changed files with 210 additions and 61 deletions

View File

@ -120,7 +120,19 @@ namespace OliviaAddInPro.Helper
{ {
if (fc == null) if (fc == null)
return null; return null;
ArcGIS.Core.Geometry.SpatialReference spatref = fc.GetDefinition().GetSpatialReference(); ArcGIS.Core.Geometry.SpatialReference spatref = null;
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
try
{
spatref = fc.GetDefinition().GetSpatialReference();
}
catch
{
}
});
task.Wait();
return spatref; return spatref;
} }
@ -131,21 +143,38 @@ namespace OliviaAddInPro.Helper
{ {
if (gdbName == null || string.IsNullOrEmpty(dataset)) if (gdbName == null || string.IsNullOrEmpty(dataset))
return null; return null;
Geodatabase gdb = null;
FeatureClassDefinition fcdef = null;
try try
{ {
Geodatabase gdb = GetGdb(gdbName).Result; gdb = GetGdb(gdbName).Result;
if (gdb == null) if (gdb == null)
return null; return null;
FeatureClassDefinition fcdef = gdb.GetDefinition<FeatureClassDefinition>(dataset); ArcGIS.Core.Geometry.SpatialReference spatref = null;
ArcGIS.Core.Geometry.SpatialReference spatref = fcdef.GetSpatialReference(); var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
Free(gdb); {
Free(fcdef); try
{
fcdef = gdb.GetDefinition<FeatureClassDefinition>(dataset);
spatref = fcdef.GetSpatialReference();
}
catch
{
}
});
task.Wait();
return spatref; return spatref;
} }
catch catch
{ {
return null; return null;
} }
finally
{
Free(gdb);
Free(fcdef);
}
} }
//Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass //Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass
@ -316,11 +345,11 @@ namespace OliviaAddInPro.Helper
} }
//Abre una feature class cuando es un shapefile //Abre una feature class cuando es un shapefile
public static async Task<FeatureClass> GetFtClassFromShp(string pathShp) public static Task<FeatureClass> GetFtClassFromShp(string pathShp)
{ {
FeatureClass ftclss = null; FeatureClass ftclss = null;
ReiniciaOutStr(); ReiniciaOutStr();
return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<FeatureClass>)(() => return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<FeatureClass>)(() =>
{ {
if (!string.IsNullOrEmpty(pathShp) && pathShp.Contains(SHP_EXT)) if (!string.IsNullOrEmpty(pathShp) && pathShp.Contains(SHP_EXT))
{ {
@ -1272,7 +1301,7 @@ namespace OliviaAddInPro.Helper
string message = String.Empty; string message = String.Empty;
bool deletionResult = false; bool deletionResult = false;
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{ {
EditOperation editOperation = new EditOperation(); EditOperation editOperation = new EditOperation();
@ -1309,6 +1338,7 @@ namespace OliviaAddInPro.Helper
} }
}); });
task.Wait();
if (!string.IsNullOrEmpty(message)) if (!string.IsNullOrEmpty(message))
{ {
@ -1506,6 +1536,8 @@ namespace OliviaAddInPro.Helper
}; };
if (!string.IsNullOrEmpty(initloc_)) if (!string.IsNullOrEmpty(initloc_))
dlg.InitialLocation = initloc_; dlg.InitialLocation = initloc_;
else
dlg.AlwaysUseInitialLocation = false;
if (!string.IsNullOrEmpty(filt_)) if (!string.IsNullOrEmpty(filt_))
dlg.Filter = filt_; dlg.Filter = filt_;
if (!string.IsNullOrEmpty(ext_)) if (!string.IsNullOrEmpty(ext_))
@ -1524,18 +1556,22 @@ namespace OliviaAddInPro.Helper
/** /**
* Comprueva si una GDB contiene un Dataset * Comprueva si una GDB contiene un Dataset
*/ */
public static bool CheckDataset(Geodatabase gdb, string datasetName) public static Task<bool> CheckDataset(Geodatabase gdb, string datasetName)
{ {
try
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<bool>)(() =>
{ {
FeatureClass ftclss = gdb.OpenDataset<FeatureClass>(datasetName); try
ftclss.Dispose(); {
return true; FeatureClass ftclss = gdb.OpenDataset<FeatureClass>(datasetName);
} ftclss.Dispose();
catch return true;
{ }
return false; catch
} {
return false;
}
}));
} }
/** /**
@ -1558,7 +1594,7 @@ namespace OliviaAddInPro.Helper
return res; return res;
} }
//comprueba si extiste ya el dataset //comprueba si extiste ya el dataset
if(CheckDataset(gdb,datasetName)) if(CheckDataset(gdb,datasetName).Result)
{ {
//comprueba si tiene la misma referencia espacial //comprueba si tiene la misma referencia espacial
featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName); featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName);
@ -1575,24 +1611,45 @@ namespace OliviaAddInPro.Helper
} }
} }
//no existe, lo crea //no existe, lo crea
SchemaBuilder schemaBuilder = new SchemaBuilder(gdb); var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<Respuesta<bool>>)(() =>
// Create a FeatureDataset {
FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(datasetName, spatref); Respuesta<bool> res2 = new Respuesta<bool> { Value = false };
schemaBuilder.Create(featureDatasetDescription); SchemaBuilder schemaBuilder = null;
try
// Build status {
bool buildStatus = schemaBuilder.Build(); schemaBuilder = new SchemaBuilder(gdb);
if(buildStatus)//ha ido bien // Create a FeatureDataset
FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(datasetName, spatref);
schemaBuilder.Create(featureDatasetDescription);
// Build status
res2.Value = schemaBuilder.Build();
if (!res2.Value && schemaBuilder.ErrorMessages.Count > 0)
res2.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
return res2;
}
catch
{
if (schemaBuilder != null && schemaBuilder.ErrorMessages.Count > 0)
res2.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
else
res2.Error.Add("Error 1 al crear Dataset.");
return res2;
}
}));
task.Wait();
if(task.Result.Value)//ha ido bien
{ {
if (string.IsNullOrEmpty(datasetNameOut)) if (string.IsNullOrEmpty(datasetNameOut))
res.Value = 0; res.Value = 0;
else else
res.Value = 2;//avisa res.Value = 2;//avisa
//actualiza la gdb
Refresh(gdbPath);
} }
else// Build errors else// Build errors
{ {
res.Value = 1; res.Value = 1;
res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); res.Error.Add(task.Result.Error.FirstOrDefault());
} }
return res; return res;
} }
@ -1621,6 +1678,7 @@ namespace OliviaAddInPro.Helper
FeatureClass fc = GetFtClassFromShp(nom_shp).Result; FeatureClass fc = GetFtClassFromShp(nom_shp).Result;
if (fc == null) if (fc == null)
return res; return res;
try try
{ {
ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc); ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc);
@ -1642,6 +1700,8 @@ namespace OliviaAddInPro.Helper
return res; return res;
} }
res.Value = true; res.Value = true;
//actualiza la gdb
Refresh(System.IO.Path.GetDirectoryName(Gdb_dataset));
return res; return res;
} }
catch (Exception ex) catch (Exception ex)
@ -1667,23 +1727,77 @@ namespace OliviaAddInPro.Helper
Geodatabase gdb = GetGdb(gdbPath).Result; Geodatabase gdb = GetGdb(gdbPath).Result;
if (gdb == null) if (gdb == null)
return res; return res;
// Create a FeatureClassDescription object
FeatureClassDescription featureClassDescription = new FeatureClassDescription(ftclss.GetDefinition()); var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<Respuesta<bool>>)(() =>
// Create a SchemaBuilder object {
SchemaBuilder schemaBuilder = new SchemaBuilder(gdb); Respuesta<bool> resp = new Respuesta<bool> { Value = false };
// Add the deletion fo the feature class to our list of DDL tasks SchemaBuilder schemaBuilder = null;
schemaBuilder.Delete(featureClassDescription); try
// Execute the DDL {
bool success = schemaBuilder.Build(); // Create a FeatureClassDescription object
if (success) FeatureClassDescription featureClassDescription = new FeatureClassDescription(ftclss.GetDefinition());
// Create a SchemaBuilder object
schemaBuilder = new SchemaBuilder(gdb);
// Add the deletion fo the feature class to our list of DDL tasks
schemaBuilder.Delete(featureClassDescription);
// Execute the DDL
resp.Value = schemaBuilder.Build();
if(!resp.Value && schemaBuilder.ErrorMessages.Count>0)
resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
return resp;
}
catch
{
resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
return resp;
}
}));
if (task.Result.Value)
res.Value = true; res.Value = true;
else else
{ {
res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); res.Error.Add(task.Result.Error.FirstOrDefault());
} }
Free(gdb); Free(gdb);
Free(ftclss); Free(ftclss);
return res; return res;
} }
/**
* Refresca la gdb después de añadir dataset y featureclass
*/
public static void Refresh(string gdbPath)
{
Item gdb=null;
try
{
gdb = ItemFactory.Instance.Create(gdbPath);
if (gdb == null)
return;
var contentItem = gdb;
//Check if the MCT is required for Refresh()
if (contentItem.IsMainThreadRequired)
{
//QueuedTask.Run must be used if item.IsMainThreadRequired
//returns true
QueuedTask.Run(() => contentItem.Refresh());
}
else
{
//if item.IsMainThreadRequired returns false, any
//thread can be used to invoke Refresh(), though
//BackgroundTask is preferred.
contentItem.Refresh();
//Or, via BackgroundTask
ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
}
}
catch
{
}
}
} }
} }

View File

@ -154,6 +154,7 @@ namespace OliviaAddInPro.Model
//comienza ejecución //comienza ejecución
Action<Respuesta<TiposEjecucion>, TratamientoComun> ac = FinProceSrv.finEjecuta; Action<Respuesta<TiposEjecucion>, TratamientoComun> ac = FinProceSrv.finEjecuta;
//pone los flags //pone los flags
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.Config);
if (modo == ModosEjec.Sectoriza) if (modo == ModosEjec.Sectoriza)
OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecSecto); OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecSecto);
else if (modo == ModosEjec.Planifica || modo == ModosEjec.SoloPlanifica) else if (modo == ModosEjec.Planifica || modo == ModosEjec.SoloPlanifica)

View File

@ -441,15 +441,28 @@ namespace OliviaAddInPro.Services
//pregunta a ver si se quiere ese nombre u otro //pregunta a ver si se quiere ese nombre u otro
bool replace = false; bool replace = false;
string dataset = tratamiento; string dataset = tratamiento;
bool sal = true;
string ambitos_aux = HelperGdb.SaveFileDlg("Guardar Feature Class como...", GdbFileName + "\\" + tratamiento + "\\" + ambitos, null, null, string ambitos_aux;
new ArcGIS.Desktop.Core.BrowseProjectFilter()); //repite por si se ha equivocado hasta que elige el nombre de clase
do
{
sal = true;
ambitos_aux = HelperGdb.SaveFileDlg("Guardar Feature Class como...", GdbFileName + "\\" + tratamiento, null, null,
ArcGIS.Desktop.Core.BrowseProjectFilter.GetFilter("esri_browseDialogFilters_featureClasses_all"));
if (string.IsNullOrEmpty(ambitos_aux))
sal = HelperGlobal.ponMsg("¿Desea cancelar el proceso de imporación?",
MessageBoxImage.Question, "OLIVIA", MessageBoxButton.YesNo);
} while (!sal);
if (!string.IsNullOrEmpty(ambitos_aux)) if (!string.IsNullOrEmpty(ambitos_aux))
{ {
//sustituye los ámbitos por los elegidos //sustituye los ámbitos por los elegidos
ambitos = System.IO.Path.GetFileNameWithoutExtension(ambitos_aux); ambitos = System.IO.Path.GetFileNameWithoutExtension(ambitos_aux);
replace = System.IO.File.Exists(ambitos_aux); replace = System.IO.File.Exists(ambitos_aux);
dataset = System.IO.Path.GetDirectoryName(ambitos_aux) ; dataset = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetDirectoryName(ambitos_aux)) ;
}
else {
res.Error.Add("Se ha cancelado la importación de resultados. Se cancela la elección de nombre de la Feature Class.");
return res;
} }
//comprueba si la proyección es la misma la del dataset que la que llega //comprueba si la proyección es la misma la del dataset que la que llega
if (!dataset.Equals(tratamiento)) if (!dataset.Equals(tratamiento))
@ -540,7 +553,7 @@ namespace OliviaAddInPro.Services
break; break;
} }
} }
resp2 = HelperGdb.ImportShp(noms_shp[i], GdbFileName + "\\" + dataset, noms_gdb[i]); resp2 = HelperGdb.ImportShp(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]);
if (!resp2.Value) if (!resp2.Value)
{ {
err_st = "Error al importar la capa " + noms_gdb[i]; err_st = "Error al importar la capa " + noms_gdb[i];

View File

@ -61,16 +61,17 @@ namespace OliviaAddInPro.Services
BorraFiles(); BorraFiles();
HelperGlobal.ponMsg(msg); HelperGlobal.ponMsg(msg);
//Application.Current.Dispatcher.Invoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>(((p, v)) => { finEjecuta2(p, v); }));*/ //Application.Current.Dispatcher.Invoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>(((p, v)) => { finEjecuta2(p, v); }));*/
Application.Current.Dispatcher.Invoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>((p, v) => finEjecuta2(p, v)),res,inst); Application.Current.Dispatcher.BeginInvoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>((p, v) => finEjecuta2(p, v)),res,inst);
//borra los archivos que le toca borrar //borra los archivos que le toca borrar
BorraFiles(); //BorraFiles();
} }
public void finEjecuta2(Respuesta<TiposEjecucion> res, TratamientoComun inst) public void finEjecuta2(Respuesta<TiposEjecucion> res, TratamientoComun inst)
{ {
String msg = string.Empty; String msg = string.Empty;
String msg_err = "Errores en el proceso de importación de resultados"; String msg_err = "Errores en el proceso de importación de resultados";
bool mal = false;
try try
{ {
@ -89,7 +90,10 @@ namespace OliviaAddInPro.Services
//importa resultados //importa resultados
var resp = IniImport(); var resp = IniImport();
if (resp.HasError) if (resp.HasError)
{
msg = resp.Error.First(); msg = resp.Error.First();
mal = true;
}
else else
{ {
string GdbFileName = resp.Value; string GdbFileName = resp.Value;
@ -114,9 +118,12 @@ namespace OliviaAddInPro.Services
if (string.IsNullOrEmpty(resp2.Value)) if (string.IsNullOrEmpty(resp2.Value))
{ {
if (resp2.HasError) if (resp2.HasError)
{
msg = resp2.Error.First(); msg = resp2.Error.First();
}
else else
msg = msg_err; msg = msg_err;
mal = true;
} }
else else
{ {
@ -130,12 +137,29 @@ namespace OliviaAddInPro.Services
catch(Exception ex) catch(Exception ex)
{ {
msg = msg_err + ": "+msg+": "+ex.Message; msg = msg_err + ": "+msg+": "+ex.Message;
mal = true;
} }
if (mal)
{
//reinicia flags
if(OliviaGlob.IsLimp())
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Limp);
else if(OliviaGlob.IsReco())
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Reco);
}
HelperGlobal.ponMsg(msg); HelperGlobal.ponMsg(msg);
OliviaGlob.progrDialog.Hide(); OliviaGlob.progrDialog.Hide();
//muestra la ventana //muestra la ventana
OliviaGlob.ShowHidePane(true); OliviaGlob.ShowHidePane(true);
/*var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
//borra los archivos que le toca borrar
BorraFiles();
});
task.Wait();*/
//borra los archivos que le toca borrar
BorraFiles();
} }
/** /**
@ -237,7 +261,7 @@ namespace OliviaAddInPro.Services
if (string.IsNullOrEmpty(GdbFileName) || !Directory.Exists(GdbFileName)) if (string.IsNullOrEmpty(GdbFileName) || !Directory.Exists(GdbFileName))
{ {
res.Error.Add("Se ha cancelado la importación de resultados."); res.Error.Add("Se ha cancelado la importación de resultados. Se cancela la elección de GDB.");
return res; return res;
} }
res.Value = GdbFileName; res.Value = GdbFileName;

View File

@ -28,8 +28,6 @@ namespace OliviaAddInPro.Services.LanzaSrv
return res; return res;
} }
OliviaGlob.TipoEjec = TiposEjecucion.Limp;//OliviaDef.GeneralDef.TiposOliv.OlivLimp;
//configura el string de opciones //configura el string de opciones
if (!configura_ops_geo(limp, modo)) if (!configura_ops_geo(limp, modo))
{ {

View File

@ -26,8 +26,6 @@ namespace OliviaAddInPro.Services.LanzaSrv
return res; return res;
} }
//OliviaGlob.tip_oliv = OliviaDef.GeneralDef.TiposOliv.OlivResi;
OliviaGlob.TipoEjec = TiposEjecucion.Reco;//OliviaDef.GeneralDef.TiposOliv.OlivResi;
/*if (!OliviaGlob.gdb_reco.exporta(reco, modo == (int)Ejecuta.ModosEjec.Planif)) /*if (!OliviaGlob.gdb_reco.exporta(reco, modo == (int)Ejecuta.ModosEjec.Planif))
{ {
err_str = OliviaGlob.gdb_reco.err_st; err_str = OliviaGlob.gdb_reco.err_st;

View File

@ -63,11 +63,11 @@ namespace OliviaAddInPro
//The parameter passed to this method will be true if the Dockpane is being opened and it is false when you close the dockpane //The parameter passed to this method will be true if the Dockpane is being opened and it is false when you close the dockpane
protected override void OnShow(bool isVisible) protected override void OnShow(bool isVisible)
{ {
if (isVisible == false && !firstTimeShow && !hideTemp) /*if (isVisible == false && !firstTimeShow && !hideTemp)
{ {
//avisa de cerrar la ventana //avisa de cerrar la ventana
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Ninguno); OliviaGlob.SetFlagTipEjec(TiposEjecucion.Ninguno);
} }*/
if (firstTimeShow) if (firstTimeShow)
firstTimeShow = false; firstTimeShow = false;
} }

View File

@ -210,6 +210,7 @@ namespace OliviaAddInPro
CapaElems = string.Empty; CapaElems = string.Empty;
OpsAmbs.Clear(); OpsAmbs.Clear();
Ambitos.Clear(); Ambitos.Clear();
TipoTto = -1;
VisTextAnchoVia = System.Windows.Visibility.Hidden; VisTextAnchoVia = System.Windows.Visibility.Hidden;
OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config); //lo reinicia, por si estaba después de planificar OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config); //lo reinicia, por si estaba después de planificar
if (string.IsNullOrEmpty(capa)) if (string.IsNullOrEmpty(capa))

View File

@ -61,11 +61,11 @@ namespace OliviaAddInPro
//also false the first time //also false the first time
protected override void OnShow(bool isVisible) protected override void OnShow(bool isVisible)
{ {
if (isVisible == false && !firstTimeShow && !hideTemp) /* if (isVisible == false && !firstTimeShow && !hideTemp)
{ {
//avisa de cerrar la ventana //avisa de cerrar la ventana
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Ninguno); OliviaGlob.SetFlagTipEjec(TiposEjecucion.Ninguno);
} }*/
if (firstTimeShow) if (firstTimeShow)
firstTimeShow = false; firstTimeShow = false;
} }