年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.0 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.Utils;
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace Kingo.Plugin.AttributeMaintain.Helper
{
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);
//int imdexs = strParm.Length / 2;
var psi = new ProcessStartInfo("GPHelper.exe", "GP调用");
psi.EnvironmentVariables["MY_ARGS"] = strParm;//为了处理ProcessStartInfo第二个参数值过长(8191字符) 注:当前KEY值暂且不唯一。
//psi.EnvironmentVariables["MY_ARGS2"] = strParm.Substring(imdexs);
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)
{
if (gPParam.GPType == EnumGPType.Default)
return;
//Console.WriteLine(outPath);
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);
}
}
}
}