public virtual void Save(IServiceProvider serviceProvider)
        {
            ConfigurationSectionInfo info = null;
            ConfigurationNode        node = ServiceHelper.GetCurrentRootNode(serviceProvider);

            try
            {
                IConfigurationSource    configurationSource = GetConfigurationSource(serviceProvider);
                IConfigurationParameter parameter           = GetConfigurationParameter(serviceProvider);

                info = GetConfigurationSectionInfo(serviceProvider);
                if (null != info && !string.IsNullOrEmpty(info.SectionName))
                {
                    if (null != info.Section)
                    {
                        configurationSource.Add(parameter, info.SectionName, info.Section);
                    }
                    else
                    {
                        configurationSource.Remove(parameter, info.SectionName);
                    }
                }
            }
            catch (Exception e)
            {
                ServiceHelper.LogError(serviceProvider, info != null ? info.Node : node, e);
            }
        }
Exemple #2
0
        /// <summary>
        /// <para>Opens the configuration settings and registers them with the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public void Open(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext       = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);
            ConfigurationSectionCollectionNode sectionsNode = null;
            ConfigurationNode configurationNode             = ServiceHelper.GetCurrentRootNode(serviceProvider);

            RemoveCurrentConfigurationSectionCollectionNode(serviceProvider);
            try
            {
                string appName = SR.DefaultApplicationName;
                ConfigurationSettings configurationSettings = configurationContext.GetMetaConfiguration();
                if (null != configurationSettings)
                {
                    appName = configurationSettings.ApplicationName;
                    if (configurationSettings.ConfigurationSections.Count > 0)
                    {
                        sectionsNode = new ConfigurationSectionCollectionNode(configurationSettings);
                        configurationNode.Nodes.Add(sectionsNode);
                    }
                }
                if (configurationNode is ApplicationConfigurationNode)
                {
                    ((ApplicationConfigurationNode)configurationNode).Name = appName;
                }
            }
            catch (ConfigurationException e)
            {
                ServiceHelper.LogError(serviceProvider, sectionsNode, e);
            }
        }
        public void Open(IServiceProvider serviceProvider)
        {
            IConfigurationSource         configurationSource = GetConfigurationSource(serviceProvider);
            ConfigurationApplicationNode appNode             = ServiceHelper.GetCurrentRootNode(serviceProvider);

            try
            {
                ConfigurationSectionInfo info = GetConfigurationSectionInfo(serviceProvider);
                if (null != info)
                {
                    ConfigurationSection section = configurationSource.GetSection(info.SectionName);
                    OpenCore(serviceProvider, appNode, section);
                }
            }
            catch (Exception e)
            {
                ServiceHelper.LogError(serviceProvider, appNode, e);
            }
        }
        /// <summary>
        /// Determines if the current <see cref="FileName"/> can be overwrriten. It will prompt the user throuth the user interface if the user wants to overwrite the file.
        /// </summary>
        /// <returns>
        /// <see langword="true"/> if the file can be overwritten; otherwise, <see langword="false"/>.
        /// </returns>
        protected bool CanOverwriteFile()
        {
            if (IsFileReadOnly(fileName))
            {
                IUIService uiService = ServiceHelper.GetUIService(ServiceProvider);

                DialogResult result = uiService.ShowMessage(string.Format(CultureInfo.CurrentUICulture, Resources.OverwriteFileMessage, fileName), Resources.OverwriteFileCaption, System.Windows.Forms.MessageBoxButtons.YesNo);
                if (DialogResult.Yes == result)
                {
                    ChangeFileAttributesToWritable(fileName);
                }
                else
                {
                    ServiceHelper.LogError(ServiceProvider, new ConfigurationError(null, Resources.ExceptionFilesNotSaved));
                    return(false);
                }
            }
            return(true);
        }
Exemple #5
0
        private void OpenFile(ConfigurationNode node)
        {
            string fileToOpen = file;

            if (!Path.IsPathRooted(file))
            {
                string dir = Directory.GetCurrentDirectory();
                fileToOpen = Path.Combine(dir, file);
            }
            if (!File.Exists(file))
            {
                ServiceHelper.LogError(ServiceProvider, new ConfigurationError(node, string.Format(CultureInfo.CurrentCulture, Resources.ErrorFileCouldNotBeOpened, file)));
                return;
            }
            ConfigurationApplicationFile data      = new ConfigurationApplicationFile(Path.GetDirectoryName(fileToOpen), fileToOpen);
            IConfigurationUIHierarchy    hierarchy = new ConfigurationUIHierarchy(new ConfigurationApplicationNode(data), ServiceProvider);

            ConfigurationUIHierarchyService.AddHierarchy(hierarchy);
            hierarchy.Open();
        }
Exemple #6
0
        /// <summary>
        /// <para>Saves the configuration settings created for the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public void Save(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);
            ConfigurationNode    node = ServiceHelper.GetCurrentRootNode(serviceProvider);

            try
            {
                ConfigurationSettings configurationSettings = GetConfigurationSettings(serviceProvider);
                configurationSettings.ApplicationName = node.Name;
                configurationContext.WriteMetaConfiguration(configurationSettings);
            }
            catch (ConfigurationException e)
            {
                ServiceHelper.LogError(serviceProvider, node, e);
            }
            catch (InvalidOperationException e)
            {
                ServiceHelper.LogError(serviceProvider, node, e);
            }
        }
Exemple #7
0
 /// <summary>
 /// <para>Log a <see cref="ValidationError"/> to the <see cref="IConfigurationErrorLogService"/>.</para>
 /// </summary>
 /// <param name="error">
 /// <para>The <see cref="ValidationError"/> to log.</para>
 /// </param>
 protected void LogError(ValidationError error)
 {
     ServiceHelper.LogError(serviceProvider, error);
 }
Exemple #8
0
 /// <summary>
 /// <para>Log a <see cref="ConfigurationError"/> to the <see cref="IConfigurationErrorLogService"/>.</para>
 /// </summary>
 /// <param name="error">
 /// <para>The <see cref="ConfigurationError"/> to log.</para>
 /// </param>
 protected void LogError(ConfigurationError error)
 {
     ServiceHelper.LogError(serviceProvider, error);
 }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        protected void LogError(string message)
        {
            IConfigurationUIHierarchyService uiHierarchyService = ServiceHelper.GetUIHierarchyService(ServiceProvider);

            ServiceHelper.LogError(ServiceProvider, new ConfigurationError(uiHierarchyService.SelectedHierarchy.RootNode, message));
        }