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.

281 lines
13 KiB

1 month 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+PElER1BhcmFtZXRlciB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4bWxuczp4c2Q9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hIj48QWxsb3dVbmlvbj50cnVlPC9BbGxvd1VuaW9uPjxBdXRvQ2FsY0dES0NTWD50cnVlPC9BdXRvQ2FsY0dES0NTWD48QXV0b1NldEdETFg+dHJ1ZTwvQXV0b1NldEdETFg+PEFsbG93UERGWj50cnVlPC9BbGxvd1BERlo+PFN0clByb2pJbmZvPkU6XDIwMjMxMjIwXOaWsOW7uuaWh+S7tuWkuVxUZW1wXDIyMDgyMVwyMjA4MjEuS0JHPC9TdHJQcm9qSW5mbz48RXhlRExUQj50cnVlPC9FeGVETFRCPjxFeGVHRERCPmZhbHNlPC9FeGVHRERCPjxFeGVDSkRDUT5mYWxzZTwvRXhlQ0pEQ1E+PEV4ZVhaUT5mYWxzZTwvRXhlWFpRPjxFeGVDWkM+ZmFsc2U8L0V4ZUNaQz48RXhlWkxIWj50cnVlPC9FeGVaTEhaPjwvSURHUGFyYW1ldGVyPg==" };
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;
}
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);
threadPool.AddTask(taskInfo);
}
threadPool.ExeTask();
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;
}
}
}