protected override void OnShutdown() { log.Info("Extension is shutting down."); // go through each layer and remove any temporary layers for (int k = 0; k < m_map.LayerCount; k++) { if (m_map.get_Layer(k).Name == "Google Maps Engine Asset Catalog") { ILayer layer = m_map.get_Layer(k); m_map.DeleteLayer(layer); Release(layer); } } // clean-up Google Maps Engine temporary files foreach (System.IO.DirectoryInfo dir in tempDirs) { try { // TODO: Do not delete so abruptly, handle better //dir.Delete(true); } catch (System.Exception) { } } // uninitialize ArcMap events log.Debug("Uninitializing ArcMap event handlers."); UninitializeArcMap(); // wire up ArcMap events and stop listening to them log.Debug("Un-wiring up ArcMap document events."); ArcMap.Events.NewDocument += InitializeArcMap; ArcMap.Events.OpenDocument -= InitializeArcMap; // set the map and extension to null to clear up log.Debug("Setting the arcmap and extension reference objects to null."); m_map = null; s_extension = null; // shutdown base.OnShutdown(); }
protected override void OnShutdown() { log.Info("Extension is shutting down."); // go through each layer and remove any temporary layers for (int k = 0; k < m_map.LayerCount; k++) { if (m_map.get_Layer(k).Name == "Google Maps Engine Asset Catalog") { ILayer layer = m_map.get_Layer(k); m_map.DeleteLayer(layer); Release(layer); } } // clean-up Google Maps Engine temporary files foreach (System.IO.DirectoryInfo dir in tempDirs) { try { // TODO: Do not delete so abruptly, handle better //dir.Delete(true); } catch (System.Exception) { } } // uninitialize ArcMap events log.Debug("Uninitializing ArcMap event handlers."); UninitializeArcMap(); // wire up ArcMap events and stop listening to them log.Debug("Un-wiring up ArcMap document events."); ArcMap.Events.NewDocument -= InitializeArcMap; ArcMap.Events.OpenDocument -= InitializeArcMap; // set the map and extension to null to clear up log.Debug("Setting the arcmap and extension reference objects to null."); m_map = null; s_extension = null; // shutdown base.OnShutdown(); }
public GoogleMapsEngineToolsExtensionForArcGIS() { // initialize and configure log4net, reading from Xml .config file log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config")); log.Info("The extension is initializing."); // set the extension object to this log.Debug("Setting the extension object to this."); s_extension = this; // The Google Maps Engine Tools Extension for ArcMap is initializing // This occures when the extension is loaded or referenced for the first time // The extension is set for delayed loading, so this may happen at Map Load or later, for instance // when the user goes to the Tools > Extension menu // initialize the OAuth2 token object log.Debug("Initializing the OAuth2 token object."); token = null; // Step 1: Check to see if the extension is enabled log.Debug("Checking to see if the extension is enabled."); if (this.State == ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) { log.Debug("The extension is enabled."); // raise an extension changed event OnRaiseExtensionStateChangeEvent(new Extension.StateChangeEventArgs(true)); // check to see if there is a valid token stored for this user log.Debug("Checking to see if the token object exists in the user's profile."); if (Extension.Auth.OAuth2Utilities.doesTokenExist(ref log)) { log.Debug("Token exists."); // retrieve token from the user's profile for use log.Debug("Getting token object from user's proflie."); token = Extension.Auth.OAuth2Utilities.getToken(ref log); } // check to see if there is an update to the Extension //TODO: Spin off a seperate thread to do this // create an update check object log.Debug("Creating an update check object."); Extension.Update.ExtensionUpdateCheck updateCheck = new Extension.Update.ExtensionUpdateCheck(); // check to see if there is an update available log.Debug("Checking to see if there is an update available."); if (updateCheck.isUpdateAvailable()) { log.Debug("isUpdateAvailable = true"); // create a dialog to inform the user of an update log.Debug("Showing the user an OK/Cancel dialog to notify them of an update."); if (System.Windows.Forms.MessageBox.Show("An update to the Google Maps Engine Tools for ArcGIS is avaiable. Would you like to update the Add-in now?" , "Update Available (" + updateCheck.getLocalVersion().ToString() + " < " + updateCheck.getServerVersion().ToString() + ")" , System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { // launch browser at the URL provided in the update check log.Debug("Launching the browser to the update URL, as the user selected OK."); System.Diagnostics.Process.Start(updateCheck.getUpdateURI()); } } } else { // the extension is not enabled or is unavailable log.Debug("The extension is disabled or unavailable (" + this.State + ")."); } }