ESRILicenseManager.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //== ====================================================================
  2. //
  3. // 成都同飞科技地下管网GIS系统
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: GNetworkProcessTool
  7. // 类 名: LicenseManager
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2017/4/11 9:51:22
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System;
  15. using System.Collections.Generic;
  16. //using System.Linq;
  17. //using System.Text;
  18. //using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using ESRI.ArcGIS;
  21. using ESRI.ArcGIS.esriSystem;
  22. namespace GNetworkProcessTool
  23. {
  24. /// <summary>
  25. /// AO权限管理类
  26. /// </summary>
  27. public class ESRILicenseManager
  28. {
  29. /// <summary>
  30. /// AO授权接口
  31. /// </summary>
  32. private static IAoInitialize _aoInitialize;
  33. /// <summary>
  34. /// 初始化授权
  35. /// </summary>
  36. public static void InitializeLicense()
  37. {
  38. if (!RuntimeManager.Bind(ProductCode.Engine))
  39. {
  40. if (!RuntimeManager.Bind(ProductCode.Desktop))
  41. {
  42. MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
  43. return;
  44. }
  45. }
  46. bool __bHasAvailableProsuct = false;
  47. #region -------- ArcGIS平台运行授权可用性检测 --------
  48. ESRILicenseManager._aoInitialize = new AoInitializeClass();
  49. List<esriLicenseProductCode> __lstCheckingProduct = new List<esriLicenseProductCode>();
  50. __lstCheckingProduct.Add(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
  51. //__lstCheckingProduct.Add(esriLicenseProductCode.esriLicenseProductCodeBasic);
  52. __lstCheckingProduct.Add(esriLicenseProductCode.esriLicenseProductCodeEngine);
  53. __lstCheckingProduct.Add(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
  54. __lstCheckingProduct.Add(esriLicenseProductCode.esriLicenseProductCodeStandard);
  55. foreach (var __productItem in __lstCheckingProduct)
  56. {
  57. esriLicenseStatus __licStatus = _aoInitialize.IsProductCodeAvailable(__productItem);
  58. if (__licStatus == esriLicenseStatus.esriLicenseAvailable)
  59. {
  60. __bHasAvailableProsuct = true;
  61. break;
  62. }
  63. }
  64. #endregion
  65. __lstCheckingProduct.Clear();
  66. if (!__bHasAvailableProsuct)
  67. {
  68. throw new System.Exception("没有可用的ArcGIS平台运行授权.");
  69. }
  70. RuntimeManager.Bind(ProductCode.Desktop);
  71. RuntimeManager.BindLicense(ProductCode.EngineOrDesktop, LicenseLevel.GeodatabaseUpdate);
  72. ESRILicenseManager._aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
  73. }
  74. /// <summary>
  75. /// 关闭授权
  76. /// </summary>
  77. public static void ShutDown()
  78. {
  79. if(ESRILicenseManager._aoInitialize != null)
  80. {
  81. ESRILicenseManager._aoInitialize.Shutdown();
  82. }
  83. }
  84. }
  85. }