using KGIS.Framework.AE; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Views; using Kingo.Plugin.MapView.Services; using Kingo.PluginServiceInterface; using System; using UIShell.OSGi; namespace Kingo.Plugin.MapView { public class Activator : IBundleActivator { IWorkCatalog _workCatalog = null; IAttrTableHelper _AttributeTable = null; IElementInfo _FeatureInfo = null; public static IBundleContext BundleContext { get; set; } public void Start(IBundleContext context) { try { BundleContext = context; //GrantAuthorizationAE.AELicense.AoInit(); if (!AELicense.AoInit()) { //MessageHelper.Show("ArcGIS授权服务未启动或已到期,请检查ArcGIS授权!"); //this.Close(); } //IWorkspaceAPI wsAPI = new WorkspaceAPI(@"C:\Users\admin\Desktop\湖北赤壁市XZQ\hb_1.gdb", KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile); //IFeatureClassAPI fcAPI = wsAPI.OpenFeatureClass("HB"); //ESRI.ArcGIS.Geodatabase.IFeature f = fcAPI.GetFeature(1); //ESRI.ArcGIS.Geometry.IGeometry geo = f.ShapeCopy; //ESRI.ArcGIS.Geometry.ISpatialReferenceFactory NewSpatialReference = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); //ESRI.ArcGIS.Geometry.ISpatialReference sp = NewSpatialReference.CreateGeographicCoordinateSystem(4490); //geo.Project(sp); //ESRI.ArcGIS.Geometry.IGeometryCollection geos = geo as ESRI.ArcGIS.Geometry.IGeometryCollection; //System.Collections.Generic.List geoList = FeatureAPI.DissolveGeometryByRing(geo); //string strRing = string.Empty; //foreach (var item in geoList) //{ // ESRI.ArcGIS.Geometry.IArea area = item as ESRI.ArcGIS.Geometry.IArea; // ESRI.ArcGIS.Geometry.IPointCollection ps = item as ESRI.ArcGIS.Geometry.IPointCollection; // for (int i = 0; i < ps.PointCount; i++) // { // //if (i % 4 == 0) // strRing += ps.Point[i].X + "," + ps.Point[i].Y + ";"; // } // strRing += "|"; //} //strRing = strRing.TrimEnd('|'); //Byte[] byt = AesEncrypt(strRing, "08716cf216e4445a8fd6cb50010eaa61"); //string strParm = Convert.ToBase64String(byt); IBaseMainView serviceInstance = new MainViewClass(context); context.AddService(serviceInstance); _workCatalog = new UCWorkspace(); if (Platform.Instance.SystemType != SystemTypeEnum.DTBJK && Platform.Instance.SystemType != SystemTypeEnum.YCLJK && Platform.Instance.SystemType != SystemTypeEnum.WYZS) context.AddService(_workCatalog);//单图斑建库不启动工作目录插件 _AttributeTable = new AttrTableHelper(); context.AddService(_AttributeTable); _FeatureInfo = new MapView.Views.AttributeEdit(); context.AddService(_FeatureInfo); } catch (Exception ex) { LogAPI.Debug("Kingo.Plugin.MapView.Start异常:" + ex.Message); LogAPI.Debug("Kingo.Plugin.MapView.Start异常:" + ex.StackTrace); } } /// /// AES 加密 /// /// 需要加密的字符串 /// 秘钥 /// public Byte[] AesEncrypt(string str, string strKey) { try { if (string.IsNullOrWhiteSpace(strKey)) throw new Exception("加密秘钥为空!"); byte[] Key = System.Text.Encoding.UTF8.GetBytes(strKey); if (Key.Length != 32) throw new Exception("秘钥长度不符合要求!"); if (string.IsNullOrEmpty(str)) return null; Byte[] toEncryptArray = System.Text.Encoding.UTF8.GetBytes(str); string strBase64 = Convert.ToBase64String(toEncryptArray); byte[] contentArray = System.Text.Encoding.UTF8.GetBytes(strBase64); #region 加密 System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged { Key = Key, Mode = System.Security.Cryptography.CipherMode.ECB, Padding = System.Security.Cryptography.PaddingMode.PKCS7 }; System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor(); Byte[] resultArray = cTransform.TransformFinalBlock(contentArray, 0, contentArray.Length); #endregion return resultArray; } catch (Exception ex) { throw ex; } } public void Stop(IBundleContext context) { IBaseMainView serviceInstance = context.GetFirstOrDefaultService(); if (serviceInstance != null) { context.RemoveService(serviceInstance); } _workCatalog = context.GetFirstOrDefaultService(); if (_workCatalog != null) { context.RemoveService(_workCatalog); } if (_FeatureInfo != null) context.RemoveService(_FeatureInfo); } } }