/// <summary>
        /// Shows the FeatureWindow modally, using the specified window as the owner.
        /// </summary>
        /// <param name="owner">The window that owns the FeatureWindow</param>
        /// <returns></returns>
        public static DialogResult ShowFeatureWindow(IWin32Window owner, object sender)
        {
            DialogResult result = DialogResult.Cancel;

            // get the executing window manager
            WindowManager windowManager = WindowManager.GetExecutingInstance();

            // create the features window
            FeatureWindow window = new FeatureWindow();

            // ask the window manager if we can show the window
            if (windowManager.CanShow(window, new object[] {}))
            {
                // ask the window manager to track the window
                windowManager.BeginTrackingLifetime(window, SnapIns.SnapInHostingEngine.WindowKeys.FeaturesWindowKey);

                // build the list of features to display
                FeatureCollectionEventArgs cea = new FeatureCollectionEventArgs();
                FeatureEngine.OnBuildingFeatureList(sender, cea);

                // select the features into the feature window
                window.SelectedFeatures = cea.Features;

                // show the window modally
                result = (owner == null ? window.ShowDialog() : window.ShowDialog(owner));
            }

            // if the result is ok, then something may need to be dealt with
            if (result == DialogResult.OK)
            {
                // grab the checked features
                FeatureCollection features = window.CheckedFeatures;

                // iterate over each feature
                foreach (Feature feature in features)
                {
                    // see if anyone wants to cancel the action on the feature
                    FeatureCancelEventArgs fcea = new FeatureCancelEventArgs(feature, false);
                    FeatureEngine.OnBeforeActionTakenForFeature(sender, fcea);
                    if (!fcea.Cancel)
                    {
                        // take the action on the feature
                        FeatureEventArgs fea = new FeatureEventArgs(feature);
                        FeatureEngine.OnTakeActionForFeature(sender, fea);

                        // notify others that an action has been taken on a feature
                        FeatureEngine.OnAfterActionTakenForFeature(sender, fea);
                    }
                }
            }

            return(result);
        }
		/// <summary>
		/// Shows the FeatureWindow modally, using the specified window as the owner.
		/// </summary>
		/// <param name="owner">The window that owns the FeatureWindow</param>
		/// <returns></returns>
		public static DialogResult ShowFeatureWindow(IWin32Window owner, object sender)
		{
			DialogResult result = DialogResult.Cancel;

			// get the executing window manager
			WindowManager windowManager = WindowManager.GetExecutingInstance();

			// create the features window
			FeatureWindow window = new FeatureWindow();

			// ask the window manager if we can show the window
			if (windowManager.CanShow(window, new object[] {}))
			{
				// ask the window manager to track the window
				windowManager.BeginTrackingLifetime(window, SnapIns.SnapInHostingEngine.WindowKeys.FeaturesWindowKey);

				// build the list of features to display
				FeatureCollectionEventArgs cea = new FeatureCollectionEventArgs();			
				FeatureEngine.OnBuildingFeatureList(sender, cea);

				// select the features into the feature window
				window.SelectedFeatures = cea.Features;

				// show the window modally
				result = (owner == null ? window.ShowDialog() : window.ShowDialog(owner));
			}
			
			// if the result is ok, then something may need to be dealt with
			if (result == DialogResult.OK)
			{
				// grab the checked features
				FeatureCollection features = window.CheckedFeatures;

				// iterate over each feature 
				foreach(Feature feature in features)
				{
					// see if anyone wants to cancel the action on the feature
					FeatureCancelEventArgs fcea = new FeatureCancelEventArgs(feature, false);
					FeatureEngine.OnBeforeActionTakenForFeature(sender, fcea);
					if (!fcea.Cancel)
					{
						// take the action on the feature
						FeatureEventArgs fea = new FeatureEventArgs(feature);
						FeatureEngine.OnTakeActionForFeature(sender, fea);
							
						// notify others that an action has been taken on a feature
						FeatureEngine.OnAfterActionTakenForFeature(sender, fea);
					}
				}		
			}

			return result;
		}	
 /// <summary>
 /// Raises the BuildingFeatureList event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected static void OnBuildingFeatureList(object sender, FeatureCollectionEventArgs e)
 {
     try
     {
         if (FeatureEngine.BuildingFeatureList != null)
         {
             FeatureEngine.BuildingFeatureList(sender, e);
         }
     }
     catch (System.Exception systemException)
     {
         System.Diagnostics.Trace.WriteLine(systemException);
     }
 }
		private void WindowPositioningEngineSnapIn_BuildingFeatureList(object sender, FeatureCollectionEventArgs e)
		{
			WindowPositioningEngineSnapIn engine = WindowPositioningEngineSnapIn.Instance;

			foreach(DictionaryEntry entry in engine._listeners)
			{
				WindowPositionListener wpl = (WindowPositionListener)entry.Value;
				IWindowPositioningEngineFeaturable featurable = wpl.Target as IWindowPositioningEngineFeaturable;
				if (featurable != null)
				{
					WindowPositionFeature wpf = new WindowPositionFeature(wpl.Key, "Controls the position and state of the window.", wpl.Target, FeatureActions.ResetToDefault);
					wpf.Tag = wpl;
					e.Features.Add(wpf);
				}								
			}
		}
		/// <summary>
		/// Raises the BuildingFeatureList event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected static void OnBuildingFeatureList(object sender, FeatureCollectionEventArgs e)
		{
			try
			{
				if (FeatureEngine.BuildingFeatureList != null)
					FeatureEngine.BuildingFeatureList(sender, e);
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
		}
		/// <summary>
		/// Handles the BuildingFeatureList event from the FeatureEngine
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		internal static void OnFeatureEngineBuildingFeatureList(object sender, FeatureCollectionEventArgs e)
		{
			SnapInHostingEngine hostingEngine = SnapInHostingEngine.GetExecutingInstance();

			// add features for resetting the configuration files
			e.Features.Add(new ConfigurationFeature(SnapInHostingEngine.DefaultCommonConfigurationName, "The common configuration stores options common to all users.", FeatureActions.ResetToDefault));
			e.Features.Add(new ConfigurationFeature(SnapInHostingEngine.DefaultLocalUserConfigurationName, "The local user configuration stores options specific to the current user.", FeatureActions.ResetToDefault));

			// since this event may fire before we have loaded any snapins (as a result of the _troubleshoot flag from the command line or app config )
			// we need to make sure we descriptors before we try this
			if ( hostingEngine.SnapInDescriptors != null )
			{
				// add features for reinstalling the snapins
				foreach(SnapInDescriptor descriptor in hostingEngine.SnapInDescriptors)
				{
					try
					{
						SnapInAttributeReader r = new SnapInAttributeReader(descriptor.Type);
						SnapInTitleAttribute ta = r.GetSnapInTitleAttribute();
						SnapInDescriptionAttribute da = r.GetSnapInDescriptionAttribute();

						string name = descriptor.Type.FullName;
						string description = null;

						if (ta != null)
							name = ta.Title;

						if (da != null)
							description = da.Description;

						e.Features.Add(new SnapInFeature(name, description, descriptor.Type, FeatureActions.Reinstall));
					}
					catch(System.Exception systemException)
					{
						System.Diagnostics.Trace.WriteLine(systemException);
					}
				}
			}
		}