年度变更建库软件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.

327 lines
17 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using IDGForNDBG;
using KGIS.Framework.ThreadManager;
using KGIS.Framework.Utils;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Xml.Linq;
namespace IDEForNDBG
{
class Program
{
[STAThread]
static void Main(string[] args)
{
try
{
if (IsAdministrator())
{
Console.WriteLine("True_任务执行开始......");
}
else
{
Console.WriteLine("False");
}
if (!KGIS.Framework.AE.AELicense.AoInit())
{
return;
}
//象山
//args = new string[] { "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iZ2IyMzEyIj8+PElER1BhcmFtZXRlciB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4bWxuczp4c2Q9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hIj48QWxsb3dVbmlvbj5mYWxzZTwvQWxsb3dVbmlvbj48QXV0b0NhbGNHREtDU1g+ZmFsc2U8L0F1dG9DYWxjR0RLQ1NYPjxBdXRvU2V0R0RMWD5mYWxzZTwvQXV0b1NldEdETFg+PEFsbG93UERGWj5mYWxzZTwvQWxsb3dQREZaPjxTdHJQcm9qSW5mbz5EOlzmtYvor5Vc5bm05bqm5Y+Y5pu05bu65bqTXOixoeWxseWOvygzMzAyMjUpXOW3peeoi+ebruW9lVwxLTI5LTFcMS0yOS0xLktCRzwvU3RyUHJvakluZm8+PEV4ZURMVEI+ZmFsc2U8L0V4ZURMVEI+PEV4ZUdEREI+ZmFsc2U8L0V4ZUdEREI+PEV4ZUNKRENRPmZhbHNlPC9FeGVDSkRDUT48RXhlWFpRPmZhbHNlPC9FeGVYWlE+PEV4ZUNaQz50cn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93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hIj48QWxsb3dVbmlvbj5mYWxzZTwvQWxsb3dVbmlvbj48QXV0b0NhbGNHREtDU1g+ZmFsc2U8L0F1dG9DYWxjR0RLQ1NYPjxBdXRvU2V0R0RMWD5mYWxzZTwvQXV0b1NldEdETFg+PEFsbG93UERGWj5mYWxzZTwvQWxsb3dQREZaPjxTdHJQcm9qSW5mbz5EOlzlt6XkvZxc5bel5L2c55uu5b2VXOW7uumYs+WMuigzNTA3MDMpXOW3peeoi+ebruW9lVzlu7rpmLMyXOW7uumYszIuS0JHPC9TdHJQcm9qSW5mbz48RXhlRExUQj5mYWxzZTwvRXhlRExUQj48RXhlR0REQj5mYWxzZTwvRXhlR0REQj48RXhlQ0pEQ1E+dHJ1ZTwvRXhlQ0pEQ1E+PEV4ZVhaUT5mYWxzZTwvRXhlWFpRPjxFeGVDWkM+ZmFsc2U8L0V4ZUNaQz48RXhlWkxIWj5mYWxzZTwvRXhlWkxIWj48L0lER1BhcmFtZXRlcj4=" };
if (args.Length == 1)
{
Exe(args[0]);
}
else
{
string[] s = new string[1];
s[0] = "";
Test();
}
//Console.WriteLine(DateTime.Now.ToString());
//Console.WriteLine(GetTime(s_dt));
//Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
public static bool IsAdministrator()
{
WindowsIdentity current = WindowsIdentity.GetCurrent();
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
static void Exe(string pParm)
{
try
{
DateTime s_dt = DateTime.Now;
//string strParm = args[0];
byte[] base64ToByte = Convert.FromBase64String(pParm);
string strParm = Encoding.UTF8.GetString(base64ToByte);
IDGParameter gPParamClass = SerializeAPI.DeserializeToObject<IDGParameter>(strParm);
if (gPParamClass == null)
{
return;
}
if (!string.IsNullOrWhiteSpace(gPParamClass.StrProjInfo) && File.Exists(gPParamClass.StrProjInfo))
{
gPParamClass.PrjInfo = ProjectInfo.OpenProject(gPParamClass.StrProjInfo);
if (gPParamClass.PrjInfo == null)
{
Console.WriteLine("Err:获取工程信息失败!");
}
}
Dictionary<string, decimal> _kcxsDic = new Dictionary<string, decimal>();//《字符串-数字》字典集合
string strPath = SysAppPath.GetBGGDLXConfigPath();//获取配置文件路径
XDocument xDoc = XDocument.Load(strPath);
foreach (XElement xElement in xDoc.Descendants("Item"))
{
string gdlx = xElement.Attributes("GDLX").Single().Value;
string gdpdjb = xElement.Attributes("GDPDJB").Single().Value;
string strKcdlxs = xElement.Attributes("KCDLXS").Single().Value;
decimal kcdlxs = Convert.ToDecimal(xElement.Attributes("KCDLXS").Single().Value == "" ? "0" : xElement.Attributes("KCDLXS").Single().Value);
string key = string.Format("{0}-{1}", gdlx, gdpdjb);
_kcxsDic.Add(key, kcdlxs);
}
gPParamClass.KCXSDic = _kcxsDic;
if (gPParamClass.PrjInfo.ListZLXXInfo == null)
gPParamClass.PrjInfo.ListZLXXInfo = new System.Collections.ObjectModel.ObservableCollection<Kingo.PluginServiceInterface.ZLXXInfo>();
string zldatabase = gPParamClass.PrjInfo.ZLDatabase;
if (gPParamClass.ExeDLTB)
{
IDGForNDBG.DLTB_IDGForThreadHelper helper = new IDGForNDBG.DLTB_IDGForThreadHelper();
Console.WriteLine("Msg:正在执行地类图斑数据提取");
helper.ExecuteForThread(gPParamClass);
gPParamClass.PrjInfo.ZLDatabase = zldatabase;
}
Console.WriteLine("Msg:正在单独图层提取");
Kingo.ThreadManager.ThreadManager2 threadPool = new Kingo.ThreadManager.ThreadManager2();
if (gPParamClass.ExeGDDB)
{
GDDB_IDGHelper helper = new GDDB_IDGHelper();
//helper.Execute(gPParamClass);
Kingo.ThreadManager.TaskInfo taskInfo = new Kingo.ThreadManager.TaskInfo();
taskInfo.Parameter = new Kingo.ThreadManager.TaskParameter();
taskInfo.Parameter.Data = gPParamClass;
taskInfo.ExeFun = new Kingo.ThreadManager.TaskCallback(helper.ExeGDDB);
//taskInfo.ExeComplatFun = new Kingo.ThreadManager.TaskCallback();
threadPool.AddTask(taskInfo);
}
//gPParamClass.ExeCJDCQ = false;
if (gPParamClass.ExeCJDCQ)
{
CJDCQ_IDGHelper xzq = new CJDCQ_IDGHelper();
//xzq.Execute(gPParamClass);
Kingo.ThreadManager.TaskInfo taskInfo = new Kingo.ThreadManager.TaskInfo();
taskInfo.Parameter = new Kingo.ThreadManager.TaskParameter();
taskInfo.Parameter.Data = gPParamClass;
taskInfo.ExeFun = new Kingo.ThreadManager.TaskCallback(xzq.ExeCJDCQ);
//taskInfo.ExeComplatFun = new Kingo.ThreadManager.TaskCallback();
threadPool.AddTask(taskInfo);
}
if (gPParamClass.ExeXZQ)
{
XZQ_IDGHelper xzq = new XZQ_IDGHelper();
//xzq.Execute(gPParamClass);
Kingo.ThreadManager.TaskInfo taskInfo = new Kingo.ThreadManager.TaskInfo();
taskInfo.Parameter = new Kingo.ThreadManager.TaskParameter();
taskInfo.Parameter.Data = gPParamClass;
taskInfo.ExeFun = new Kingo.ThreadManager.TaskCallback(xzq.ExeXZQ);
//taskInfo.ExeComplatFun = new Kingo.ThreadManager.TaskCallback();
threadPool.AddTask(taskInfo);
}
if (gPParamClass.ExeCZC)
{
CZC_IDGHelper helper = new CZC_IDGHelper();
//helper.Execute(gPParamClass);
Kingo.ThreadManager.TaskInfo taskInfo = new Kingo.ThreadManager.TaskInfo();
taskInfo.Parameter = new Kingo.ThreadManager.TaskParameter();
taskInfo.Parameter.Data = gPParamClass;
taskInfo.ExeFun = new Kingo.ThreadManager.TaskCallback(helper.ExtractExe);
//taskInfo.ExeComplatFun = new Kingo.ThreadManager.TaskCallback();
threadPool.AddTask(taskInfo);
}
threadPool.ExeTask();
//while (ThreadManager.Instance.ActiveCount > 0) { }
if (gPParamClass.ExeZLHZ)
{
//Console.WriteLine("Msg:正在进行增量汇总");
ZLHZHelper helper = new ZLHZHelper();
helper.Execute(gPParamClass);
}
while (ThreadManager.Instance.ActiveCount > 0) { }
Console.Clear();
Console.WriteLine("执行完成,耗时:" + GetTime(s_dt) + "秒");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static void Test()
{
while (true)
{
string fun = Console.ReadLine();
if (fun.ToLower() == "test2")
{
Test2();
}
else if (fun.ToLower() == "test3")
{
Test3();
}
else if (fun.ToLower() == "test4")
{
Test4();
}
else if (fun.ToLower() == "ext")
{
break;
}
}
}
static void Test3()
{
DateTime s_dt = DateTime.Now;
Console.WriteLine(s_dt.ToString());
List<string> columns = new List<string>() { "XZQDM", "MSSM" };//, "XZQTZLX", "HDMC"
string[] parms = new string[5];
string args1 = @"D:\测试\年度变更建库\莱芜区(370116)\工程目录\莱芜1102\NMDB.gdb\DLTB_NMK";
string args2 = @"aa";
string args3 = @"D:\测试\年度变更建库\莱芜区(370116)\工程目录\莱芜1102\NMDB.gdb\XZQ";
string args4 = string.Join(";", columns);
string args5 = "Dissolve";
string r = GPHelper.Instance.ExeGPForProces(args1, args2, args3, args4, args5);
Console.WriteLine(r);
Console.WriteLine("执行完成,耗时:" + GetTime(s_dt) + "秒");
}
static void Test4()
{
DateTime s_dt = DateTime.Now;
Console.WriteLine(s_dt.ToString());
//KGIS.Framework.AE.Instance.GeoprocessorHelper helper = new KGIS.Framework.AE.Instance.GeoprocessorHelper();
List<string> columns = new List<string>() { "XZQDM", "MSSM" };//, "XZQTZLX", "HDMC"
KGIS.Framework.AE.GPHelper.GPParamClass gPParamClass = new KGIS.Framework.AE.GPHelper.GPParamClass();
gPParamClass.FirstFeatureClassPath = @"D:\测试\年度变更建库\莱芜区(370116)\工程目录\莱芜1102\NMDB.gdb\DLTB_NMK";
gPParamClass.OutFeatureClassPath = @"D:\测试\年度变更建库\莱芜区(370116)\工程目录\莱芜1102\NMDB.gdb\XZQ";
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.ListDissolveFiledName = columns;
IFeatureLayer TempGXLayer = null;
KGIS.Framework.AE.GPHelper.GeoprocessorHelper.DissolveAnalysis(gPParamClass, ref TempGXLayer);
//while (Marshal.ReleaseComObject(TempGXLayer.FeatureClass) > 0) { }
while (Marshal.ReleaseComObject(TempGXLayer) > 0) { }
Console.WriteLine(gPParamClass.OutFeatureClassPath);
Console.WriteLine("执行完成,耗时:" + GetTime(s_dt) + "秒");
}
static void Test2()
{
DateTime s_dt = DateTime.Now;
Console.WriteLine(s_dt.ToString());
IDGParameter parm = new IDGParameter();
//parm.BgDbPath = @"D:\测试\工程\章丘区(370114)\工程目录\2022-11-3-1\BGDB.gdb";
//parm.JcDbPath = @"D:\测试\工程\章丘区(370114)\年初数据\370114章丘区.gdb";
//parm.ZLDbPath = @"D:\测试\工程\章丘区(370114)\工程目录\2022-11-3-1\ZLDB.gdb";
//parm.NmDbPath = @"D:\测试\工程\章丘区(370114)\工程目录\2022-11-3-1\NMDB.gdb";
//parm.XZQDM = "370114";
//parm.ProjDir = @"D:\测试\工程\章丘区(370114)\工程目录\2022-11-3-1";
parm.PrjInfo = new Kingo.PluginServiceInterface.ProjectInfo();
parm.ExeDLTB = true;
parm.ExeGDDB = false;
parm.ExeCJDCQ = true;
parm.ExeXZQ = false;
parm.ExeZLHZ = true;
parm.ExeCZC = false;
Dictionary<string, decimal> _kcxsDic = new Dictionary<string, decimal>();//《字符串-数字》字典集合
string strPath = SysAppPath.GetBGGDLXConfigPath();//获取配置文件路径
XDocument xDoc = XDocument.Load(strPath);
foreach (XElement xElement in xDoc.Descendants("Item"))
{
string gdlx = xElement.Attributes("GDLX").Single().Value;
string gdpdjb = xElement.Attributes("GDPDJB").Single().Value;
string strKcdlxs = xElement.Attributes("KCDLXS").Single().Value;
decimal kcdlxs = Convert.ToDecimal(xElement.Attributes("KCDLXS").Single().Value == "" ? "0" : xElement.Attributes("KCDLXS").Single().Value);
string key = string.Format("{0}-{1}", gdlx, gdpdjb);
_kcxsDic.Add(key, kcdlxs);
}
parm.KCXSDic = _kcxsDic;
parm.PrjInfo.ListZLXXInfo = new System.Collections.ObjectModel.ObservableCollection<Kingo.PluginServiceInterface.ZLXXInfo>();
parm.PrjInfo.ListZLXXInfo.Add(new Kingo.PluginServiceInterface.ZLXXInfo() { BGQDM = "370114110", BGQMC = "刁镇", BGHDM = "370114016", BGHMC = "刁镇街道" });
parm.PrjInfo.ListZLXXInfo.Add(new Kingo.PluginServiceInterface.ZLXXInfo() { BGQDM = "370114118", BGQMC = "黄河镇", BGHDM = "370114017", BGHMC = "黄河街道" });
if (parm.ExeDLTB)
{
IDGForNDBG.DLTB_IDGHelper helper = new IDGForNDBG.DLTB_IDGHelper();
Console.WriteLine("Msg:正在执行地类图斑数据提取");
helper.Execute(parm);
}
Console.WriteLine("Msg:正在单独图层提取");
if (parm.ExeGDDB)
{
GDDB_IDGHelper helper = new GDDB_IDGHelper();
helper.Execute(parm);
}
if (parm.ExeCJDCQ)
{
CJDCQ_IDGHelper xzq = new CJDCQ_IDGHelper();
xzq.Execute(parm);
}
if (parm.ExeXZQ)
{
XZQ_IDGHelper xzq = new XZQ_IDGHelper();
xzq.Execute(parm);
}
if (parm.ExeCZC)
{
CZC_IDGHelper helper = new CZC_IDGHelper();
helper.Execute(parm);
}
while (ThreadManager.Instance.ActiveCount > 0) { }
Console.WriteLine("Msg:正在进行增量汇总");
if (parm.ExeZLHZ)
{
ZLHZHelper helper = new ZLHZHelper();
helper.Execute(parm);
}
while (ThreadManager.Instance.ActiveCount > 0) { }
Console.WriteLine("执行完成,耗时:" + GetTime(s_dt) + "秒");
}
public static string GetTime(DateTime timeA)
{
//timeA 表示需要计算
DateTime timeB = DateTime.Now; //获取当前时间
TimeSpan ts = timeB - timeA; //计算时间差
string time = ts.TotalSeconds.ToString(); //将时间差转换为秒
return time;
}
}
}