|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.esriSystem;
|
|
|
|
|
using KGIS.Framework.AE.GPHelper;
|
|
|
|
|
//using IDEParameter;
|
|
|
|
|
using KGIS.Framework.Utils;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace KGIS_DLTB
|
|
|
|
|
{
|
|
|
|
|
public class GPHelper
|
|
|
|
|
{
|
|
|
|
|
public static GPHelper Instance { get; } = new GPHelper();
|
|
|
|
|
public GPHelper() { }
|
|
|
|
|
public string ExeGPForProces(string args1, string args2, string args3, string args4, string args5)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(args1))
|
|
|
|
|
args1 = "null";
|
|
|
|
|
if (string.IsNullOrWhiteSpace(args2))
|
|
|
|
|
args2 = "null";
|
|
|
|
|
if (string.IsNullOrWhiteSpace(args3))
|
|
|
|
|
args3 = "null";
|
|
|
|
|
if (string.IsNullOrWhiteSpace(args4))
|
|
|
|
|
args4 = "null";
|
|
|
|
|
if (string.IsNullOrWhiteSpace(args5))
|
|
|
|
|
args5 = "null";
|
|
|
|
|
var psi = new ProcessStartInfo("GPHelper.exe", string.Format("{0} {1} {2} {3} {4}", args1, args2, args3, args4, args5));
|
|
|
|
|
psi.UseShellExecute = false;
|
|
|
|
|
psi.CreateNoWindow = true;
|
|
|
|
|
psi.RedirectStandardError = true;
|
|
|
|
|
psi.RedirectStandardInput = true;
|
|
|
|
|
psi.RedirectStandardOutput = true;
|
|
|
|
|
|
|
|
|
|
var pes = Process.Start(psi);
|
|
|
|
|
|
|
|
|
|
var sbuffer = new StringBuilder();
|
|
|
|
|
var sout = pes.StandardOutput;
|
|
|
|
|
while (!sout.EndOfStream)
|
|
|
|
|
{
|
|
|
|
|
var line = sout.ReadLine();
|
|
|
|
|
if (String.IsNullOrEmpty(line)) continue;
|
|
|
|
|
sbuffer.AppendLine(line);
|
|
|
|
|
}
|
|
|
|
|
pes.WaitForExit();
|
|
|
|
|
pes.Close();
|
|
|
|
|
String res = sbuffer.ToString();
|
|
|
|
|
sbuffer.Clear();
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
public string ExeGPForProces(string arg)
|
|
|
|
|
{
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(arg);
|
|
|
|
|
string strParm = Convert.ToBase64String(toEncryptArray);
|
|
|
|
|
//Console.WriteLine(strParm);
|
|
|
|
|
var psi = new ProcessStartInfo("GPHelper.exe", "GP调用");
|
|
|
|
|
psi.EnvironmentVariables["MY_ARGS"] = strParm;
|
|
|
|
|
psi.UseShellExecute = false;
|
|
|
|
|
psi.CreateNoWindow = true;
|
|
|
|
|
psi.RedirectStandardError = true;
|
|
|
|
|
psi.RedirectStandardInput = true;
|
|
|
|
|
psi.RedirectStandardOutput = true;
|
|
|
|
|
|
|
|
|
|
var pes = Process.Start(psi);
|
|
|
|
|
|
|
|
|
|
var sbuffer = new StringBuilder();
|
|
|
|
|
var sout = pes.StandardOutput;
|
|
|
|
|
while (!sout.EndOfStream)
|
|
|
|
|
{
|
|
|
|
|
result = sout.ReadLine();
|
|
|
|
|
if (String.IsNullOrEmpty(result)) continue;
|
|
|
|
|
sbuffer.AppendLine(result);
|
|
|
|
|
}
|
|
|
|
|
pes.WaitForExit();
|
|
|
|
|
pes.Close();
|
|
|
|
|
String res = sbuffer.ToString();
|
|
|
|
|
sbuffer.Clear();
|
|
|
|
|
//Console.WriteLine(res);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
public void ExeGPForProces(GPParamClass gPParam, ref IFeatureLayer result)
|
|
|
|
|
{
|
|
|
|
|
string outPath = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string strParm = SerializeAPI.SerializeToXML<GPParamClass>(gPParam);
|
|
|
|
|
//lock (outPath)
|
|
|
|
|
//{
|
|
|
|
|
outPath = ExeGPForProces(strParm);
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
//Console.WriteLine(outPath);
|
|
|
|
|
if (gPParam.GPType == EnumGPType.Default)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (outPath.ToLower() == "error")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(outPath))
|
|
|
|
|
outPath = gPParam.OutFeatureClassPath;
|
|
|
|
|
result = new FeatureLayer();
|
|
|
|
|
FileInfo file = new FileInfo(outPath.Replace("\r\n", ""));
|
|
|
|
|
string dbPath = file.DirectoryName;
|
|
|
|
|
string fcName = file.Name;
|
|
|
|
|
if (file.Name.ToLower().EndsWith(".gdb") && gPParam.FcName != null)
|
|
|
|
|
{
|
|
|
|
|
dbPath = file.FullName;
|
|
|
|
|
fcName = gPParam.FcName;
|
|
|
|
|
}
|
|
|
|
|
else if (fcName.ToLower().EndsWith(".shp"))
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.AE.IWorkspaceAPI wsAPI = new KGIS.Framework.AE.WorkspaceAPI(dbPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.ShapeFile);
|
|
|
|
|
KGIS.Framework.AE.IFeatureClassAPI fcAPI = wsAPI.OpenFeatureClass(fcName.Replace(".shp", ""));
|
|
|
|
|
result.FeatureClass = fcAPI.FeatureClass;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
KGIS.Framework.AE.IWorkspaceAPI wsAPI = new KGIS.Framework.AE.WorkspaceAPI(dbPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile);
|
|
|
|
|
KGIS.Framework.AE.IFeatureClassAPI fcAPI = wsAPI.OpenFeatureClass(fcName);
|
|
|
|
|
result.FeatureClass = fcAPI.FeatureClass;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Console.WriteLine("End:" + outPath);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(outPath);
|
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ExeGp(IVariantArray pParam)
|
|
|
|
|
{
|
|
|
|
|
string outPath = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string strParm = KGIS.Framework.AE.GeoDBAPI.SerialzedPersist(pParam);
|
|
|
|
|
outPath = ExeGPForProces(strParm);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(outPath);
|
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|