Ejemplo n.º 1
0
        /// <summary>
        /// Occurs when the <see cref="LaunchStyleCopButton"/> is clicked.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> that raised the event.</param>
        /// <param name="e">An <see cref="System.EventArgs"/> containing event data.</param>
        private void LaunchStyleCopButton_Click(object sender, EventArgs e)
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                // Write the existing settings to the file before creating the UI.
                File.WriteAllText(tempFileName, this.Settings.StyleCopSettings);

                StyleCopCore core = new StyleCopCore(null, null);
                core.Initialize(null, true);
                core.DisplayUI         = true;
                core.WriteResultsCache = false;

                if (core.ShowSettings(tempFileName))
                {
                    // Read the new settings from the file.
                    this.Settings.StyleCopSettings = File.ReadAllText(tempFileName);
                }
            }
            finally
            {
                // Destroy the temp file so remnants aren't left lying around.
                File.Delete(tempFileName);
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Param.Ignore(args);

            if (args != null && args.Length > 0 && !string.IsNullOrEmpty(args[0]))
            {
                try
                {
                    string settingsFilePath = Path.GetFullPath(args[0]);
                    settingsFilePath = Environment.ExpandEnvironmentVariables(settingsFilePath);

                    if (File.Exists(settingsFilePath))
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);

                        using (StyleCopCore core = new StyleCopCore(null, null))
                        {
                            core.Initialize(null, true);
                            core.WriteResultsCache = false;
                            core.DisplayUI         = true;

                            core.ShowSettings(settingsFilePath);
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileDoesNotExist, settingsFilePath),
                            null,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
                catch (IOException ex)
                {
                    MessageBox.Show(
                        string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message),
                        null,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                catch (UnauthorizedAccessException ex)
                {
                    MessageBox.Show(
                        string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message),
                        null,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                catch (SecurityException ex)
                {
                    MessageBox.Show(
                        string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message),
                        null,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(
                        string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message),
                        null,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(Resources.InvalidArguments, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }