/// <summary>
 /// <para>Closes the application configuration.</para>
 /// </summary>
 /// <param name="node">
 /// <para>The node to execute the command upon.</para>
 /// </param>
 protected override void ExecuteCore(ConfigurationNode node)
 {
     try
     {
         UIService.BeginUpdate();
         if (UIService.IsDirty(node.Hierarchy))
         {
             DialogResult result = UIService.ShowMessage(SR.SaveApplicationRequest, SR.SaveApplicationCaption, MessageBoxButtons.YesNo);
             if (DialogResult.Yes == result)
             {
                 if (!TryAndSaveApplication(node))
                 {
                     return;
                 }
             }
         }
         if (ConfigurationErrorLogService.ConfigurationErrors.Count > 0)
         {
             UIService.DisplayErrorLog(ConfigurationErrorLogService);
             DialogResult result = UIService.ShowMessage(SR.SaveApplicationErrorRequestMessage, SR.SaveApplicationCaption, MessageBoxButtons.YesNo);
             if (result == DialogResult.No)
             {
                 return;
             }
         }
         UIHierarchyService.RemoveHierarchy(node.Hierarchy.Id);
     }
     finally
     {
         UIService.EndUpdate();
     }
 }
 /// <summary>
 /// <para>Creates a new <see cref="ApplicationConfigurationNode"/> object and adds it to the solution.</para>
 /// </summary>
 /// <param name="node">
 /// <para>The <see cref="ApplicationConfigurationNode"/> is the root of an <see cref="IUIHierarchy"/> so the <paramref name="node"/> is not used, so passing <see langword="null"/> is expected.</para>
 /// </param>
 protected override void ExecuteCore(ConfigurationNode node)
 {
     try
     {
         UIService.BeginUpdate();
         ApplicationConfigurationNode appNode = new ApplicationConfigurationNode(applicationData);
         IUIHierarchy hierarchy = ConfigurationUIHierarchyFactory.Create(appNode, ServiceProvider);
         UIHierarchyService.AddHierarchy(hierarchy);
         UIService.SetUIDirty(hierarchy);
     }
     finally
     {
         UIService.EndUpdate();
     }
 }
        private void OpenFile()
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter           = SR.ConfigurationFileDialogFilter;
            fileDialog.CheckFileExists  = true;
            fileDialog.CheckPathExists  = true;
            fileDialog.AddExtension     = true;
            fileDialog.DefaultExt       = ".config";
            fileDialog.RestoreDirectory = true;
            DialogResult result = UIService.ShowOpenDialog(fileDialog);

            if (result == DialogResult.OK)
            {
                string          file      = fileDialog.FileName;
                ApplicationData data      = new ApplicationData(string.Empty, Path.GetDirectoryName(file), file);
                IUIHierarchy    hierarchy = new UIHierarchy(new ApplicationConfigurationNode(data), ServiceProvider, new ConfigurationContext(file));
                UIHierarchyService.AddHierarchy(hierarchy);
                hierarchy.Open();
            }
        }
 /// <summary>
 /// <para>Removes the <see cref="IUIHierarchy"/> (<see cref="ApplicationConfigurationNode"/> from the <see cref="IUIHierarchyService"/>.</para>
 /// </summary>
 /// <param name="node">
 /// <para>The node to execute the command upon.</para>
 /// </param>
 protected override void ExecuteCore(ConfigurationNode node)
 {
     Debug.Assert(node.GetType().Equals(typeof(ApplicationConfigurationNode)), "Expected an ApplicationConfigurationNode");
     UIHierarchyService.RemoveHierarchy(node.Hierarchy.Id);
 }