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

225 lines
9.9 KiB

4 months ago
using KGIS.Framework.Core.Services;
using KGIS.Framework.Platform.Interface;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Core.Authorize;
using Kingo.PlatformPlugin.Services;
using Kingo.PluginServiceInterface;
using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using UIShell.OSGi;
namespace Kingo.PlatformPlugin
{
public class Activator : IBundleActivator
{
private IPlatformService _platformService;
private IOutPutMsg _outputMsg;
private IDockViewService dockViewService;
public void Start(IBundleContext context)
{
try
{
#if DEBUG
_platformService = new PlatformService(context as IBundleContext);
(context as IBundleContext).AddService(_platformService);
dockViewService = new DockViewService();
(context as IBundleContext).AddService(dockViewService);
#else
VerifyLic(context);
#endif
//RunIDService2.Instance.Verify(AuthorizeType.多合一授权, "BGDCPRO", "300", "3x");
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
//System.Threading.Thread.Sleep(5000);
}
//public bool Verify(AuthorizeType authorizeType, string productid, string exeVersion, string authorizefileveesion)
//{
// //var jqm = HardwareIDHelper.GetHardwareID2();
// string[] licpath = System.IO.Directory.GetFiles(System.Environment.CurrentDirectory, "*.lic", System.IO.SearchOption.TopDirectoryOnly);
// if (licpath.Length == 0) return false;
// foreach (var item in licpath)
// {
// AuthorizeHelper authorizeHelper = new AuthorizeHelper(authorizeType, productid, exeVersion, authorizefileveesion, item);
// authorizeHelper.SetCipherTextTime += (text) =>
// {
// Console.WriteLine(text);//此处处理三方验证
// };
// var state = authorizeHelper.Authorize();
// if (state)
// {
// //return state;
// var code = authorizeHelper.GetAreaCode();
// var codeinfo = authorizeHelper.GetAreaInfo();
// var modelid = authorizeHelper.GetAuthorizeModelInfo();
// var exptime = authorizeHelper.GetExpirationTime();
// var lasttime = authorizeHelper.GetLastUpdateTime();
// var lasttimetxt = authorizeHelper.GetLastUpdateTimeCiphertext();
// var up = authorizeHelper.UpdateLastUpDateTime();
// }
// }
// return false;
//}
private bool ValidityVerification(IBundleContext context)
{
try
{
AuthorizeHelper authorizeHelper = new AuthorizeHelper(AuthorizeType., "BGDCPRO", "300", "3x", "");
var type = ConfigurationManager.AppSettings.Get("LicenseType");
Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
string guid = ((GuidAttribute)guid_attr).Value;
var state = authorizeHelper.Authorize();// ("MobileDataMake", "2x", GetVersion(Assembly.GetExecutingAssembly().Location));
if (state)
{
_platformService = new PlatformService(context as IBundleContext);
(context as IBundleContext).AddService(_platformService);
dockViewService = new DockViewService();
(context as IBundleContext).AddService(dockViewService);
}
else
{
LogAPI.Debug("软件授权校验未通过");
throw new Exception("授权失败");
}
return true;
}
catch (Exception ex)
{
if (ex.Message == "Dongle initialization error")
{
MessageHelper.Show("未读取到加密狗数据:" + ex.Message);
return false;
}
else
{
MessageHelper.Show("未读取到加密狗数据:" + ex.Message);
throw ex;
}
}
}
private string GetVersion(string fileName)
{
FileVersionInfo file1 = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName);
return String.Format("{0}{1}{2}", file1.ProductMajorPart, file1.ProductMinorPart, file1.ProductBuildPart);
}
private void VerifyLic(object context)
{
try
{
Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
string guid = ((GuidAttribute)guid_attr).Value;
var type = ConfigurationManager.AppSettings.Get("LicenseType"); _platformService = new PlatformService(context as IBundleContext);
//if (!RunIDService2.Instance.Models.Contains(guid))
//{
// throw new Exception(string.Format("【{0}】插件未授权,加载失败", context.Bundle.Name));
//}
(context as IBundleContext).AddService(_platformService);
dockViewService = new DockViewService();
(context as IBundleContext).AddService(dockViewService);
////判断授权方式
//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(context);
// lic.DocValidity += VerifyLic;
// DialogResult dialog = lic.ShowDialog();
// }
// else
// {
// _platformService = new PlatformService(context as IBundleContext);
// (context as IBundleContext).AddService(_platformService);
// dockViewService = new DockViewService();
// (context as IBundleContext).AddService(dockViewService);
// return;
// }
// }
// catch (Exception ex)
// {
// MessageHelper.Show(ex.Message);
// LogAPI.Debug(ex);
// KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(context);
// lic.DocValidity += VerifyLic;
// DialogResult dialog = lic.ShowDialog();
// }
//}
//else if (type == "D")
//{
// if (!RunIDService2.Instance.Verify("BGDCPRO", "300", "3x"))
// {
// KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(context);
// lic.DocValidity = (o) =>
// {
// _platformService = new PlatformService(context as IBundleContext);
// (context as IBundleContext).AddService(_platformService);
// dockViewService = new DockViewService();
// (context as IBundleContext).AddService(dockViewService);
// };
// DialogResult dialog = lic.ShowDialog();
// }
// else
// {
// _platformService = new PlatformService(context as IBundleContext);
// (context as IBundleContext).AddService(_platformService);
// dockViewService = new DockViewService();
// (context as IBundleContext).AddService(dockViewService);
// }
//}
//else
//{
// KGIS.PlatformPlugin.Views.License.LicenseView lic = new KGIS.PlatformPlugin.Views.License.LicenseView(context);
// lic.DocValidity += VerifyLic;
// DialogResult dialog = lic.ShowDialog();
//}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
public void Stop(IBundleContext context)
{
if (null != _platformService)
{
context.RemoveService<IPlatformService>(_platformService);
_platformService = null;
}
if (null != _outputMsg)
{
context.RemoveService<IOutPutMsg>(_outputMsg);
_outputMsg = null;
}
}
}
}