/// <summary> /// Prompt user for download. /// </summary> /// <param name="currentVersionNumber"> /// The current version number. /// </param> /// <param name="newVersionNumber"> /// The new version number. /// </param> /// <param name="messageText"> /// The message text. /// </param> /// <returns> /// The prompt user for download. /// </returns> private bool PromptUserForDownload(string currentVersionNumber, string newVersionNumber, string messageText) { if (string.IsNullOrEmpty(messageText)) { messageText = string.Empty; } else { messageText += "." + Environment.NewLine; } if (this.core.DisplayUI) { // display dialog asking whether to perform auto-update DialogResult result = AlertDialog.Show( this.core, null, string.Format(Strings.AutoUpdateQuestion, messageText, newVersionNumber, currentVersionNumber), Strings.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question); return(result == DialogResult.Yes); } // send notification to the output for non-UI environment AlertDialog.Show( this.core, null, string.Format(Strings.AutoUpdateInformation, messageText, newVersionNumber, currentVersionNumber), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); }
/// <summary> /// Saves the data and clears the dirty flag. /// </summary> /// <returns>Returns true if the data was saved, false if not.</returns> public bool Apply() { // Save the path to the linked settings file if necessary. if (this.mergeWithLinkedFile.Checked) { bool valid = false; // Validate the contents of the global file path textbox. try { // Make sure the file exists. if (File.Exists(this.linkedFilePath.Text)) { // Make sure the file can be loaded and contains valid Xml. XmlDocument document = new XmlDocument(); document.Load(this.linkedFilePath.Text); // Make sure the file contains the correct type of root node. if (document.DocumentElement.Name == "StyleCopSettings" || document.DocumentElement.Name == "SourceAnalysisSettings") { valid = true; } } } catch (ArgumentException) { } catch (SecurityException) { } catch (UnauthorizedAccessException) { } catch (IOException) { } catch (XmlException) { } if (valid) { string relativePath = this.linkedFilePath.Text; if (!relativePath.StartsWith(".", StringComparison.Ordinal)) { // Create a URI pointing to the local project folder. string localFolderPath = Path.GetDirectoryName(this.tabControl.LocalSettings.Location); if (!localFolderPath.EndsWith("\\", StringComparison.Ordinal)) { localFolderPath += "\\"; } Uri uri = new Uri(localFolderPath); // Create the relative path to the global file folder. Uri relative = uri.MakeRelativeUri(new Uri(this.linkedFilePath.Text)); relativePath = GlobalSettingsFileOptions.ConvertBackslashes(relative.OriginalString); } this.tabControl.LocalSettings.GlobalSettings.SetProperty( new StringProperty(this.tabControl.Core, SettingsMerger.LinkedSettingsProperty, relativePath)); this.tabControl.LocalSettings.GlobalSettings.SetProperty( new StringProperty(this.tabControl.Core, SettingsMerger.MergeSettingsFilesProperty, SettingsMerger.MergeStyleLinked)); } else { AlertDialog.Show(this.tabControl.Core, this, Strings.NoLinkedSettingsFile, Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { this.tabControl.LocalSettings.GlobalSettings.SetProperty( new StringProperty( this.tabControl.Core, SettingsMerger.MergeSettingsFilesProperty, this.noMerge.Checked ? SettingsMerger.MergeStyleNone : SettingsMerger.MergeStyleParent)); this.tabControl.LocalSettings.GlobalSettings.Remove(SettingsMerger.LinkedSettingsProperty); } this.dirty = false; this.tabControl.DirtyChanged(); return(true); }
/// <summary> /// Applies the data on the property pages. /// </summary> /// <param name="dirtyPages">Returns true if any pages were dirty.</param> /// <returns>Returns false if any page returned false from it's apply call, in which case /// the apply failed.</returns> internal PropertyControlSaveResult Apply(out bool dirtyPages) { dirtyPages = false; // Call the apply method for each of the pages. PropertyControlSaveResult result = PropertyControlSaveResult.Success; bool cancel = false; bool[] pageDirtyState = new bool[this.pageInterfaces.Count]; // Pre-apply the pages. for (int i = 0; i < this.pageInterfaces.Count; ++i) { if (this.pageInterfaces[i] != null) { pageDirtyState[i] = this.pageInterfaces[i].Dirty; if (!this.pageInterfaces[i].PreApply()) { cancel = true; break; } } } if (!cancel) { // Apply the pages. int breakIndex = -1; for (int i = 0; i < this.pageInterfaces.Count; ++i) { if (this.pageInterfaces[i] != null && this.pageInterfaces[i].Dirty) { dirtyPages = true; if (!this.pageInterfaces[i].Apply()) { result = PropertyControlSaveResult.PageAbort; breakIndex = i; break; } } } // Post-apply the pages. int lastIndex = breakIndex == -1 ? this.pageInterfaces.Count - 1 : breakIndex; for (int i = 0; i <= lastIndex; ++i) { if (this.pageInterfaces[i] != null) { this.pageInterfaces[i].PostApply(pageDirtyState[i]); } } if (breakIndex == -1) { // Save the settings files. Exception exception = null; if (!this.core.Environment.SaveSettings(this.localSettings, out exception)) { AlertDialog.Show( this.core, this, string.Format(CultureInfo.CurrentUICulture, Strings.CouldNotSaveSettingsFile, exception.Message), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); result = PropertyControlSaveResult.SaveError; // Reset the dirty flag on each page. for (int i = 0; i < this.pageInterfaces.Count; ++i) { if (this.pageInterfaces[i] != null) { this.pageInterfaces[i].Dirty = pageDirtyState[i]; } } } else { this.dirty = false; this.host.Dirty(false); } } } return(result); }
/// <summary> /// The form's OnLoad event. Initializes the PropertyControl object. /// </summary> /// <param name="e"> /// The event arguments. /// </param> protected override void OnLoad(EventArgs e) { Param.Ignore(e); base.OnLoad(e); if (this.helpCallback == null) { this.MoveButton(this.ok, this.cancel); this.MoveButton(this.cancel, this.apply); this.MoveButton(this.apply, this.help); this.help.Visible = false; } this.apply.Enabled = false; try { this.properties.Initialize(this, this.pages, this.settingsFile, this.core, this.context); } catch (IOException ioex) { AlertDialog.Show( this.core, this, string.Format(CultureInfo.CurrentUICulture, Strings.LocalSettingsNotOpenedOrCreated, ioex.Message), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } catch (SecurityException secex) { AlertDialog.Show( this.core, this, string.Format(CultureInfo.CurrentUICulture, Strings.LocalSettingsNotOpenedOrCreated, secex.Message), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } catch (UnauthorizedAccessException unauthex) { AlertDialog.Show( this.core, this, string.Format(CultureInfo.CurrentUICulture, Strings.LocalSettingsNotOpenedOrCreated, unauthex.Message), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } catch (XmlException xmlex) { AlertDialog.Show( this.core, this, string.Format(CultureInfo.CurrentUICulture, Strings.LocalSettingsNotOpenedOrCreated, xmlex.Message), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }