Ejemplo n.º 1
0
        /// <summary>
        /// Finds a linked settings document and merges it with the given settings.
        /// </summary>
        /// <param name="originalSettings">The original settings.</param>
        /// <param name="mergeOriginal">Indicates whether the merge the original settings with the linked settings.</param>
        /// <returns>Returns the merged settings.</returns>
        /// <remarks>This method is designed to work only in file-based environments.</remarks>
        private Settings FindMergedSettingsThroughLinkedSettings(Settings originalSettings, bool mergeOriginal)
        {
            Param.AssertNotNull(originalSettings, "originalSettings");
            Param.Ignore(mergeOriginal);

            StringProperty linkedSettingsProperty = originalSettings.GlobalSettings.GetProperty(SettingsMerger.LinkedSettingsProperty) as StringProperty;

            if (linkedSettingsProperty != null && !string.IsNullOrEmpty(linkedSettingsProperty.Value))
            {
                string linkedSettingsFile = Environment.ExpandEnvironmentVariables(linkedSettingsProperty.Value);

                if (linkedSettingsFile.StartsWith(".", StringComparison.Ordinal) || !linkedSettingsFile.Contains("\\"))
                {
                    linkedSettingsFile = StyleCopCore.MakeAbsolutePath(originalSettings.Location, linkedSettingsFile);
                }

                if (File.Exists(linkedSettingsFile))
                {
                    Settings mergedLinkedSettings = this.environment.GetSettings(linkedSettingsFile, true);
                    if (mergedLinkedSettings != null)
                    {
                        if (mergeOriginal)
                        {
                            return(MergeSettings(mergedLinkedSettings, originalSettings));
                        }

                        return(mergedLinkedSettings);
                    }
                }
            }

            // The linked settings do not exist. Just return the original settings.
            return(originalSettings);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when the edit linked settings file button is clicked.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void EditLinkedSettingsFileClicked(object sender, EventArgs e)
        {
            Param.Ignore(sender, e);

            if (string.IsNullOrEmpty(this.linkedFilePath.Text))
            {
                AlertDialog.Show(
                    this.tabControl.Core,
                    this,
                    Strings.EmptySettingsFilePath,
                    Strings.Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else
            {
                string expandedPath = Environment.ExpandEnvironmentVariables(this.linkedFilePath.Text);

                if (expandedPath.StartsWith(".", StringComparison.Ordinal) || !expandedPath.Contains("\\"))
                {
                    expandedPath = StyleCopCore.MakeAbsolutePath(this.tabControl.LocalSettings.Location, expandedPath);
                }

                // Check if there is a file at the given path. Create the settings file if needed.
                if (!File.Exists(expandedPath))
                {
                    // Create a new settings file at the given path.
                    Exception exception;

                    Settings createdSettingsFile = this.tabControl.Core.Environment.GetWritableSettings(expandedPath, out exception);
                    if (createdSettingsFile == null)
                    {
                        AlertDialog.Show(
                            this.tabControl.Core,
                            this,
                            string.Format(CultureInfo.CurrentUICulture, Strings.CannotLoadSettingsFilePath, exception == null ? string.Empty : exception.Message),
                            Strings.Title,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);

                        expandedPath = null;
                    }
                }

                if (!string.IsNullOrEmpty(expandedPath))
                {
                    this.EditParentSettings(expandedPath, false);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the page.
        /// </summary>
        /// <param name="propertyControl">The tab control object.</param>
        public void Initialize(PropertyControl propertyControl)
        {
            Param.AssertNotNull(propertyControl, "propertyControl");

            this.tabControl = propertyControl;

            // Get the merge style setting.
            StringProperty mergeTypeProperty = this.tabControl.LocalSettings.GlobalSettings.GetProperty(SettingsMerger.MergeSettingsFilesProperty) as StringProperty;
            string         mergeType         = mergeTypeProperty == null ? SettingsMerger.MergeStyleParent : mergeTypeProperty.Value;

            // If the merge style is set to link but the current environment doesn't support linking, change it to parent.
            if (!this.tabControl.Core.Environment.SupportsLinkedSettings && string.CompareOrdinal(mergeType, SettingsMerger.MergeStyleLinked) == 0)
            {
                mergeType           = SettingsMerger.MergeStyleParent;
                this.disableLinking = true;
            }

            if (string.CompareOrdinal(mergeType, SettingsMerger.MergeStyleNone) == 0)
            {
                this.noMerge.Checked = true;
            }
            else if (string.CompareOrdinal(mergeType, SettingsMerger.MergeStyleLinked) == 0)
            {
                this.mergeWithLinkedFile.Checked = true;

                StringProperty linkedSettingsFileProperty = this.tabControl.LocalSettings.GlobalSettings.GetProperty(SettingsMerger.LinkedSettingsProperty) as StringProperty;
                if (linkedSettingsFileProperty != null && !string.IsNullOrEmpty(linkedSettingsFileProperty.Value))
                {
                    // This mode assumes that StyleCop is running in a file-based environment.
                    string linkedSettingsFile = Environment.ExpandEnvironmentVariables(linkedSettingsFileProperty.Value);

                    if (linkedSettingsFile.StartsWith(".", StringComparison.Ordinal))
                    {
                        linkedSettingsFile = StyleCopCore.MakeAbsolutePath(this.tabControl.LocalSettings.Location, linkedSettingsFile);
                    }

                    this.linkedFilePath.Text = linkedSettingsFile;
                }
            }
            else
            {
                this.mergeWithParents.Checked = true;
            }

            this.EnableDisable();

            bool defaultSettings = this.tabControl.LocalSettings.DefaultSettings;

            // Disable the parent link controls if this is the default settings file.
            this.mergeWithParents.Enabled       = !defaultSettings;
            this.editParentSettingsFile.Enabled = !defaultSettings;
            this.mergeWithLinkedFile.Enabled    = !defaultSettings;
            this.locationLabel.Enabled          = !defaultSettings;
            this.linkedFilePath.Enabled         = !defaultSettings;
            this.browse.Enabled = !defaultSettings;
            this.editLinkedSettingsFile.Enabled = !defaultSettings;

            if (!this.noMerge.Checked && defaultSettings)
            {
                this.noMerge.Checked = true;
            }

            // Reset the dirty flag to false now.
            this.dirty = false;
            this.tabControl.DirtyChanged();
        }