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.
311 lines
13 KiB
311 lines
13 KiB
using KGIS.Framework.Core.Services; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Platform.Interface; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo; |
|
using Kingo.Core.Authorize; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Configuration; |
|
using System.Diagnostics; |
|
using System.Linq; |
|
using System.Management; |
|
using System.Reflection; |
|
using System.Runtime.InteropServices; |
|
using System.ServiceProcess; |
|
using System.Threading; |
|
using System.Windows.Forms; |
|
using UIShell.OSGi; |
|
|
|
namespace KIngo.DataProcessing |
|
{ |
|
static class Program |
|
{ |
|
internal delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); |
|
|
|
[DllImport("user32.dll", EntryPoint = "FindWindow")] |
|
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); |
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] |
|
private static extern int ShowWindow(IntPtr hwnd, int nCmdShow); |
|
|
|
[DllImport("User32.dll", CharSet = CharSet.Auto)] |
|
internal static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam); |
|
|
|
[DllImport("User32.dll", CharSet = CharSet.Auto)] |
|
internal static extern int GetWindowThreadProcessId(IntPtr hWnd, out IntPtr lpdwProcessId); |
|
|
|
[DllImport("User32.dll", CharSet = CharSet.Auto)] |
|
internal static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); |
|
|
|
[DllImport("USER32.DLL")] |
|
public static extern bool SetForegroundWindow(IntPtr hWnd); |
|
public static bool v = false; |
|
/// <summary> |
|
/// 应用程序的主入口点。 |
|
/// </summary> |
|
[STAThread] |
|
static void Main() |
|
{ |
|
Application.EnableVisualStyles(); |
|
Application.SetCompatibleTextRenderingDefault(false); |
|
GdalConfiguration.ConfigureGdal(); |
|
GdalConfiguration.ConfigureOgr(); |
|
//Application.Run(platform.Instance); |
|
Platform.Instance.SystemType = SystemTypeEnum.TBBG; |
|
Mutex instance = new Mutex(true, $"{Platform.Instance.SystemType}_30", out bool createdNew); |
|
if (createdNew) |
|
{ |
|
} |
|
else |
|
{ |
|
//MessageHelper.ShowTips("已经打开该应用程序,请先关闭!"); |
|
Process curr = Process.GetCurrentProcess(); |
|
|
|
List<Process> process = Process.GetProcessesByName(curr.ProcessName).ToList();//. |
|
//Where(p => p.Id != curr.Id && p.GetCommandLine().Contains($"{Platform.Instance.SystemType}_30")).ToList(); |
|
|
|
if (process != null && process.Count > 0) |
|
{ |
|
foreach (Process item in process) |
|
{ |
|
//IntPtr mainPtr = GetProcessHandle(item.Id); |
|
//ShowWindow(mainPtr, 3); |
|
ShowWindow(item.MainWindowHandle, 1); |
|
SetForegroundWindow(item.MainWindowHandle); |
|
break; |
|
} |
|
} |
|
Application.Exit(); |
|
return; |
|
} |
|
try |
|
{ |
|
ServiceController sc = new ServiceController("ArcGIS License Manager"); |
|
if (!KGIS.Framework.AE.AELicense.AoInit(true) || sc.Status == ServiceControllerStatus.Stopped) |
|
{ |
|
MessageHelper.Show("ArcGIS授权服务未启动或已到期,请检查ArcGIS授权!"); |
|
return; |
|
} |
|
} |
|
catch (Exception EX) |
|
{ |
|
MessageHelper.Show("ArcGIS授权服务未启动或已到期,请检查ArcGIS授权!"); |
|
LogAPI.Debug(EX.Message); |
|
return; |
|
} |
|
using (var bundleRuntime = new BundleRuntime()) |
|
{ |
|
#region |
|
int loadedBundleCount = 0; |
|
Action<bool> action = null; |
|
IAsyncResult asyncResult = null; |
|
IPluginStart startPlugin = null; |
|
List<IBundle> bundles = new List<IBundle>(); |
|
//插件状态发生改变事件,用来加载启动插件的进度 |
|
EventHandler<BundleStateChangedEventArgs> bundleStateChangeEventHandler = (sender, e) => |
|
{ |
|
if (e.CurrentState != BundleState.Starting || e.Bundle.Name == "SystemBundle") |
|
return; |
|
if (startPlugin == null) |
|
startPlugin = bundleRuntime.GetFirstOrDefaultService<IPluginStart>(); |
|
string[] Name_ID = e.Bundle.Name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); |
|
if (startPlugin != null) |
|
{ |
|
startPlugin.SetTitle(ConfigurationManager.AppSettings.Get("APPName")); |
|
startPlugin.SetSystemType(SystemTypeEnum.TBBG.ToString()); |
|
if (Name_ID.Length == 2) |
|
{ |
|
if (!Name_ID[1].Contains(SystemTypeEnum.TBBG.ToString())) |
|
{ |
|
bundles.Add(e.Bundle); |
|
//e.Bundle.Stop(BundleStopOptions.Transient); |
|
} |
|
} |
|
//} |
|
|
|
if (!startPlugin.IsShow) |
|
{ |
|
action = (ar) => |
|
{ |
|
if (ar) |
|
{ |
|
startPlugin.ShowDialog(); |
|
} |
|
else |
|
{ |
|
} |
|
//isWelcomeShow = true; |
|
}; |
|
asyncResult = action.BeginInvoke(true, null, null); |
|
//等待启动界面打开 |
|
while (!startPlugin.IsShow) |
|
{ |
|
Thread.Sleep(50); |
|
} |
|
loadedBundleCount++; |
|
startPlugin.SetPercent(loadedBundleCount, bundleRuntime.Framework.Bundles.Count - 1, Name_ID[0]); |
|
} |
|
else |
|
{ |
|
loadedBundleCount++; |
|
startPlugin.SetPercent(loadedBundleCount, bundleRuntime.Framework.Bundles.Count - 1, Name_ID[0]); |
|
} |
|
} |
|
else |
|
{ |
|
LogAPI.Debug("000000"); |
|
} |
|
//e.Bundle.BundleID |
|
}; |
|
#if DEBUG |
|
Validity(bundleRuntime); |
|
#else |
|
Validity(bundleRuntime); |
|
#endif |
|
if (!v) |
|
return; |
|
|
|
//注册插件状态事件 |
|
bundleRuntime.Framework.EventManager.AddBundleEventListener(bundleStateChangeEventHandler, true); |
|
//开始启动插件 |
|
bundleRuntime.Start(); |
|
//取消插件状态的事件 |
|
bundleRuntime.Framework.EventManager.RemoveBundleEventListener(bundleStateChangeEventHandler, true); |
|
#endregion |
|
|
|
foreach (IBundle item in bundles) |
|
{ |
|
LogAPI.Debug("Del:" + item.Name); |
|
item.Stop(BundleStopOptions.Transient); |
|
} |
|
|
|
var platform = bundleRuntime.GetFirstOrDefaultService<IPlatformService>(); |
|
if (platform != null) |
|
{ |
|
//platform.InitService(); |
|
Platform.Instance.Open(); |
|
platform.InitUI(null); |
|
if (startPlugin != null) |
|
startPlugin.CloseForm(); |
|
ExtensionShowWindow.MainWinForm = platform.Instance; |
|
Platform.Instance.OutputMsg("系统初始化完成。"); |
|
Platform.Instance.UpdateStateBar("系统初始化完成"); |
|
|
|
//if (Platform.Instance.MapsService != null) |
|
//{ |
|
//} |
|
//else |
|
//{ |
|
// LogAPI.Debug("软件启动失败,可能的原因:"); |
|
// LogAPI.Debug("ArcGIS授权服务未启动或已到期,请检查ArcGIS授权!"); |
|
//} |
|
//GdalConfiguration.ConfigureGdal(); |
|
//GdalConfiguration.ConfigureOgr(); |
|
Application.Run(platform.Instance); |
|
RunIDService.Dispose(); |
|
} |
|
else |
|
{ |
|
LogAPI.Debug("IPlatformService接口获取失败!"); |
|
} |
|
} |
|
} |
|
private static void Validity(object obj) |
|
{ |
|
try |
|
{ |
|
//判断授权方式 |
|
var type = ConfigurationManager.AppSettings.Get("LicenseType"); |
|
if (type == "F")//本地授权 |
|
{ |
|
Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute)); |
|
string guid = ((GuidAttribute)guid_attr).Value; |
|
try |
|
{ |
|
string[] licpath = System.IO.Directory.GetFiles(System.Environment.CurrentDirectory, "*.lic", System.IO.SearchOption.TopDirectoryOnly); |
|
if (licpath.Length == 0) |
|
{ |
|
MessageHelper.ShowError("授权校验失败!"); |
|
} |
|
|
|
if (licpath.Length == 0 || !RunIDService2.Instance.Verify(AuthorizeType.多合一授权, "BGDCPRO", "300", "3x", "", "10eaa61")) |
|
{ |
|
KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(obj, "BGDCPRO", "300", "3x"); |
|
lic.Code = "10eaa61"; |
|
int num = -1; |
|
//lic.DocValidity = Validity; |
|
DialogResult dialog = lic.ShowDialog(); |
|
if (dialog != DialogResult.Yes && dialog != DialogResult.OK) |
|
{ |
|
v = false; |
|
return; |
|
} |
|
} |
|
else |
|
{ |
|
v = true; |
|
return; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.Show(ex.Message); |
|
LogAPI.Debug(ex); |
|
KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(obj, "BGDCPRO", "300", "3x"); |
|
lic.Code = "10eaa61"; |
|
int num = -1; |
|
//lic.DocValidity = Validity; |
|
DialogResult dialog = lic.ShowDialog(); |
|
if (dialog != DialogResult.Yes || dialog != DialogResult.OK) |
|
{ |
|
v = false; |
|
return; |
|
} |
|
} |
|
} |
|
else if (type == "D") |
|
{ |
|
if (!RunIDService2.Instance.Verify("BGDCPRO", "300", "3x")) |
|
{ |
|
KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(obj, "BGDCPRO", "300", "3x"); |
|
|
|
DialogResult dialog = lic.ShowDialog(); |
|
if (dialog != DialogResult.Yes && dialog != DialogResult.OK) |
|
{ |
|
v = false; |
|
return; |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(obj, "BGDCPRO", "300", "3x"); |
|
int num = -1; |
|
lic.DocValidity = Validity; |
|
DialogResult dialog = lic.ShowDialog(); |
|
if (dialog != DialogResult.Yes || dialog != DialogResult.OK) |
|
{ |
|
v = false; |
|
return; |
|
} |
|
} |
|
v = true; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
private static string GetCommandLine(this Process process) |
|
{ |
|
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id)) |
|
using (ManagementObjectCollection objects = searcher.Get()) |
|
{ |
|
return objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString(); |
|
} |
|
|
|
} |
|
} |
|
}
|
|
|