/// <summary> /// Initializes a new instance of the <see cref="StyleCopSettingsHandler"/> class. /// </summary> /// <param name="settingsFilePath">The path to the StyleCop settings file.</param> /// <param name="coreInstance">The StyleCop core instance.</param> internal StyleCopSettingsHandler(string settingsFilePath, StyleCopCore coreInstance) { Param.AssertValidString(settingsFilePath, "settingsFilePath"); Param.AssertNotNull(coreInstance, "coreInstance"); this.core = coreInstance; // Load the local settings. Exception exception = null; this.localSettings = this.core.Environment.GetWritableSettings(settingsFilePath, out exception); if (exception != null) { Gtk.MessageDialog messageDialog = new Gtk.MessageDialog( null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, string.Format(CultureInfo.CurrentUICulture, StaticStringResources.ProjectSettingsFileNotLoadedOrCreated, exception.Message)); messageDialog.Title = StaticStringResources.Title; messageDialog.Run(); messageDialog.Destroy(); throw exception; } else if (this.localSettings != null) { if (string.Compare(settingsFilePath, this.core.Environment.GetDefaultSettingsPath(), true) == 0) { // We must use reflection at the moment to set the DefaultSettings property (in case it exists). PropertyInfo prop = this.localSettings.GetType().GetProperty("DefaultSettings", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (prop != null && prop.CanWrite) { prop.SetValue(this.localSettings, true, null); } } // Set the contents of the parent settings file. SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment); this.parentSettings = merger.ParentMergedSettings; this.mergedSettings = merger.MergedSettings; // Set up the settings comparer. this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings); } else { throw new InvalidOperationException("StyleCop settings couldn't be loaded!"); } }
/// <summary> /// Creates a new <see cref="PolicySettings"/> instance. /// </summary> /// <param name="useDefaultSettings"><c>true</c> if the default settings should be used; otherwise, <c>false</c>.</param> /// <returns>A new <see cref="PolicySettings"/> object.</returns> public static PolicySettings Create(bool useDefaultSettings) { PolicySettings settings = new PolicySettings(); if (useDefaultSettings) { // Set the default values for the new instance. settings.TaskCategory = PolicyTaskCategory.Error; settings.EvaluateOn = EvaluateOnType.Add | EvaluateOnType.Edit | EvaluateOnType.Rename | EvaluateOnType.Merge; settings.StyleCopSettings = WritableSettings.NewDocument().OuterXml; } return(settings); }
/// <summary> /// Saves the settings document at the path specified within the document. /// </summary> /// <param name="settings">The settings to save.</param> /// <param name="exception">Upon return, contains an exception if an exception occurs while saving the settings.</param> /// <returns><c>true</c> if the settings were saved successfully; otherwise, <c>false</c>.</returns> public override bool SaveSettings(WritableSettings settings, out Exception exception) { exception = null; return(true); }