//Initialize the Tracking Environment, you only need to do this once
    private void setupTrackingEnv()
    {
      if (!m_bInitialized && ArcMap.Application != null)
      {
        IExtensionManager extentionManager = new ExtensionManagerClass();

        UID uid = new UIDClass();
        uid.Value = "esriTrackingAnalyst.TrackingEngineUtil";
        object mapRef = ArcMap.Application;

        ((IExtensionManagerAdmin)extentionManager).AddExtension(uid, ref mapRef);

        ITrackingEnvironment3 trackingEnv = new TrackingEnvironmentClass();
        try
        {
          trackingEnv.Initialize(ref mapRef);
        }
        catch (Exception ex)
        {
        }
        trackingEnv.EnableTemporalDisplayManagement = true;
     
        m_bInitialized = true;
      }
    }
    private ITrackingEnvironment3 setupTrackingEnv(ref object mapObj)
    {
      IExtensionManager extentionManager = new ExtensionManagerClass();

      UID uid = new UIDClass();
      uid.Value = "esriTrackingAnalyst.TrackingEngineUtil";

      ((IExtensionManagerAdmin)extentionManager).AddExtension(uid, ref mapObj);

      ITrackingEnvironment3 trackingEnv = new TrackingEnvironmentClass();
      try
      {
        trackingEnv.Initialize(ref mapObj);
      }
      catch (Exception ex)
      {
      }
      trackingEnv.EnableTemporalDisplayManagement = true;
      return trackingEnv;
    }
        private bool EnablePublisherExtension()
        {

            bool checkedOutOK = false;

            try
            {
                IExtensionManager extMgr = new ExtensionManagerClass();

                IExtensionManagerAdmin extAdmin = (IExtensionManagerAdmin)extMgr;

                UID uid = new UID();
                uid.Value = "esriPublisherUI.Publisher";
                object obj = 0;
                extAdmin.AddExtension(uid, ref obj);

                IExtensionConfig extConfig = (IExtensionConfig)extMgr.FindExtension(uid);

                if ((!(extConfig.State == esriExtensionState.esriESUnavailable)))
                {
                    //This checks on the extension
                    extConfig.State = esriExtensionState.esriESEnabled;
                    checkedOutOK = true;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Publisher extension has failed to check out.", "Error");
            }

            return checkedOutOK;
        } 
        private static void EnableEsriLiscences()
        {
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
            ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Desktop);

            UID pUid = new UIDClass();
            pUid.Value = "esriSpatialAnalystUI.SAExtension";

            // Add Spatial Analyst extension to the license manager.
            object v = null;
            IExtensionManagerAdmin extensionManagerAdmin = new ExtensionManagerClass();
            extensionManagerAdmin.AddExtension(pUid, ref v);

            // Enable the license.
            IExtensionManager extensionManager = (IExtensionManager)extensionManagerAdmin;
            IExtension extension = extensionManager.FindExtension(pUid);
            IExtensionConfig extensionConfig = (IExtensionConfig)extension;

            if (extensionConfig.State != esriExtensionState.esriESUnavailable)
            {
                extensionConfig.State = esriExtensionState.esriESEnabled;
            }
            else
            {
                Console.WriteLine("No Spatial Analyst License available");
            }
        }
        private void Toggle3DExtension(string strState)
        {
            try
            {
                IExtensionManagerAdmin pExtAdmin2 = new ExtensionManagerClass();
                IExtensionManager pExtManager2 = pExtAdmin2 as IExtensionManager;
                UID pUID = new UID();
                pUID.Value = "{94305472-592E-11D4-80EE-00C04FA0ADF8}";
                IExtensionConfig pExtConfig2 = pExtManager2.FindExtension(pUID) as IExtensionConfig;

                switch (strState)
                {
                    case "ON":
                        pExtConfig2.State = esriExtensionState.esriESEnabled;
                        break;
                    case "OFF":
                        pExtConfig2.State = esriExtensionState.esriESDisabled;
                        break;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
		public override void OnClick()
		{
			//Get the current extent of the active view
			IActiveView activeView = m_HookHelper.ActiveView;
			IEnvelope envelope = activeView.Extent;

			//Get the extension manager
			ExtensionManager extensionManager = new ExtensionManagerClass();
			//Get the extension from the extension manager
			IExtension extension = extensionManager.FindExtension("Zoom Factor Extension");

			//Get the zoom factor from the extension
			double zoomFactor = 1.1;
			if (extension != null)
			{
				IZoomExtension zoomExtension = (IZoomExtension) extension;
				zoomFactor = zoomExtension.ZoomFactor;
			}
			else
			{
				System.Windows.Forms.MessageBox.Show("The extension cannot be found!");
			}

			//Update the current extent of the active view
			envelope.Expand((System.Convert.ToDouble(1.0)/ zoomFactor), (System.Convert.ToDouble(1.0) / zoomFactor), true);
			activeView.Extent = envelope;
			activeView.Refresh();
		}
        private void ToggleSA(bool toggle)
        {
            UID puid = new UID();
            puid.Value = "esriGeoAnalyst.SAExtension.1";

            object v = 0;
            IExtensionManagerAdmin pLicAdmin = new ExtensionManagerClass();
            pLicAdmin.AddExtension(puid, ref v);

            IExtensionManager pLicManager = pLicAdmin as IExtensionManager;
            IExtensionConfig pExtensionConfig = pLicManager.FindExtension(puid) as IExtensionConfig;
            if (toggle)
            {
                pExtensionConfig.State = esriExtensionState.esriESEnabled;
            }
            else
            {
                pExtensionConfig.State = esriExtensionState.esriESDisabled;
            }
        }
		public override void OnClick()
		{
			//Get the extension manager
			ExtensionManager extensionManager = new ExtensionManagerClass();
			//Get the extension from the extension manager
			IExtension extension = extensionManager.FindExtension("Zoom Factor Extension");

			IZoomExtension zoomExtension = (IZoomExtension) extension;
			double zoomFactor = zoomExtension.ZoomFactor;

			//Get a zoom factor from the user
			InputFormResult res = InputForm.ShowModal(null,"Enter a zoom factor","ZoomExtension Sample", zoomExtension.ZoomFactor.ToString() );

			if (res.Result == DialogResult.Cancel) return;
			string zoomString = res.InputString;
			if (zoomString.Trim() == "") return;

			//Set the zoom factor
			if (System.Char.IsNumber(zoomString,0) == true) zoomExtension.ZoomFactor = System.Convert.ToDouble(zoomString);
		}