public imageAnalysisUtil() { gp.OverwriteOutput = true; IAoInitialize a = new AoInitializeClass(); if (!a.IsExtensionCheckedOut(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst)) { weCheckedOutSpa = true; a.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst); } }
private static void Ensure3dAnalyst() { IAoInitialize aoInitialize = new AoInitializeClass(); bool is3dAvailable = aoInitialize.IsExtensionCheckedOut( esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst); if (!is3dAvailable) { esriLicenseStatus status = aoInitialize.CheckOutExtension( esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst); _msg.DebugFormat("3D Analyst checkout status: {0}", status); } }
public void Execute(IArray paramvalues, ITrackCancel TrackCancel, IGPEnvironmentManager envMgr, IGPMessages message) { IAoInitialize aoInitialize = new AoInitializeClass(); esriLicenseStatus naStatus = esriLicenseStatus.esriLicenseUnavailable; IGPUtilities2 gpUtil = null; IDataset osmDataset = null; try { if (!aoInitialize.IsExtensionCheckedOut(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork)) naStatus = aoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork); gpUtil = new GPUtilitiesClass(); // OSM Dataset Param IGPParameter osmDatasetParam = paramvalues.get_Element(in_osmFeatureDataset) as IGPParameter; IDEDataset2 osmDEDataset = gpUtil.UnpackGPValue(osmDatasetParam) as IDEDataset2; if (osmDEDataset == null) { message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), osmDatasetParam.Name)); return; } osmDataset = gpUtil.OpenDatasetFromLocation(((IDataElement)osmDEDataset).CatalogPath) as IDataset; // Network Config File Param IGPParameter osmNetConfigParam = paramvalues.get_Element(in_NetworkConfigurationFile) as IGPParameter; IGPValue osmNetConfigFile = gpUtil.UnpackGPValue(osmNetConfigParam) as IGPValue; if ((osmNetConfigFile == null) || (string.IsNullOrEmpty(osmNetConfigFile.GetAsText()))) { message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), osmNetConfigParam.Name)); return; } // Target Network Dataset Param IGPParameter ndsParam = paramvalues.get_Element(out_NetworkDataset) as IGPParameter; IDataElement deNDS = gpUtil.UnpackGPValue(ndsParam) as IDataElement; if (deNDS == null) { message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), ndsParam.Name)); return; } // Create Network Dataset using (NetworkDataset nd = new NetworkDataset(osmNetConfigFile.GetAsText(), osmDataset, deNDS.Name, message, TrackCancel)) { if (nd.CanCreateNetworkDataset()) nd.CreateNetworkDataset(); } } catch (UserCancelException ex) { message.AddWarning(ex.Message); } catch (Exception ex) { message.AddError(120008, ex.Message); #if DEBUG message.AddError(120008, ex.StackTrace); #endif } finally { if (osmDataset != null) ComReleaser.ReleaseCOMObject(osmDataset); if (naStatus == esriLicenseStatus.esriLicenseCheckedOut) aoInitialize.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork); if (gpUtil != null) ComReleaser.ReleaseCOMObject(gpUtil); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }
public void Execute(IArray paramvalues, ITrackCancel TrackCancel, IGPEnvironmentManager envMgr, IGPMessages message) { IAoInitialize aoInitialize = new AoInitializeClass(); esriLicenseStatus naStatus = esriLicenseStatus.esriLicenseUnavailable; IGPUtilities2 gpUtil = null; IDataset osmDataset = null; try { if (!aoInitialize.IsExtensionCheckedOut(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork)) { naStatus = aoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork); } gpUtil = new GPUtilitiesClass(); // OSM Dataset Param IGPParameter osmDatasetParam = paramvalues.get_Element(in_osmFeatureDataset) as IGPParameter; IDEDataset2 osmDEDataset = gpUtil.UnpackGPValue(osmDatasetParam) as IDEDataset2; if (osmDEDataset == null) { message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), osmDatasetParam.Name)); return; } osmDataset = gpUtil.OpenDatasetFromLocation(((IDataElement)osmDEDataset).CatalogPath) as IDataset; // Network Config File Param IGPParameter osmNetConfigParam = paramvalues.get_Element(in_NetworkConfigurationFile) as IGPParameter; IGPValue osmNetConfigFile = gpUtil.UnpackGPValue(osmNetConfigParam) as IGPValue; if ((osmNetConfigFile == null) || (string.IsNullOrEmpty(osmNetConfigFile.GetAsText()))) { message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), osmNetConfigParam.Name)); return; } // Target Network Dataset Param IGPParameter ndsParam = paramvalues.get_Element(out_NetworkDataset) as IGPParameter; IDataElement deNDS = gpUtil.UnpackGPValue(ndsParam) as IDataElement; if (deNDS == null) { message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), ndsParam.Name)); return; } // Create Network Dataset using (NetworkDataset nd = new NetworkDataset(osmNetConfigFile.GetAsText(), osmDataset, deNDS.Name, message, TrackCancel)) { if (nd.CanCreateNetworkDataset()) { nd.CreateNetworkDataset(); } } } catch (UserCancelException ex) { message.AddWarning(ex.Message); } catch (Exception ex) { message.AddError(120008, ex.Message); #if DEBUG message.AddError(120008, ex.StackTrace); #endif } finally { if (osmDataset != null) { ComReleaser.ReleaseCOMObject(osmDataset); } if (naStatus == esriLicenseStatus.esriLicenseCheckedOut) { aoInitialize.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork); } if (gpUtil != null) { ComReleaser.ReleaseCOMObject(gpUtil); } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }
public bool IsLicensed() { // Only allow this tool to run if Network extension is checked out IAoInitialize aoi = new AoInitializeClass(); return aoi.IsExtensionCheckedOut(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork); }