//// Methods ============================================================================================================

        /// <summary>
        /// Gets the list of filenames of ignored source files in the supplied StyleCop .Settings XML file.
        /// </summary>
        /// <param name="xmlFilePath">Absolute path to the StyleCop .Settings XML file.</param>
        /// <returns>A string array of all the ignored filenames, with extensions (e.g. Example.txt)</returns>
        internal static string[] GetIgnoredFileNames(UniversalPath xmlFilePath)
        {
            // Load the XML file
            var xmlDocument = new XmlDocument();

            xmlDocument.Load((string)xmlFilePath);

            // Check its contents for a StyleCop Settings outer element
            var rootElement = (XmlElement)xmlDocument.SelectSingleNode("/StyleCopSettings");

            if (rootElement == null)
            {
                return(new string[0]);
            }

            // Get the list of ignored source filenames, depending on the storage method
            switch (ignoreListStorageMode)
            {
            case IgnoreListType.GeneratedFileFilter:
                return(GetIgnoredFileNamesFromGeneratedFileFilter(xmlDocument));

            case IgnoreListType.SourceFileList:
                return(GetIgnoredFileNamesFromSourceFileList(xmlDocument));

            default:
                throw new System.InvalidOperationException("Invalid storage mode for the StyleCop ignore list!");
            }
        }
        /// <summary>
        /// Replaces the list of ignored filenames in the StyleCop .Settings file with a new list.
        /// </summary>
        /// <param name="xmlFilePath">Absolute path to the StyleCop .Settings XML file.</param>
        /// <param name="newFileNames">A string array containing the new list of filenames to ignore.</param>
        /// <returns>Returns true if the operation succeeds, false otherwise.</returns>
        internal static bool ReplaceIgnoreFileNames(UniversalPath xmlFilePath, string[] newFileNames)
        {
            // Load the XML file
            var xmlDocument = new XmlDocument();

            xmlDocument.Load((string)xmlFilePath);

            var rootElement = (XmlElement)xmlDocument.SelectSingleNode("/StyleCopSettings");

            if (rootElement == null)
            {
                return(false);
            }

            // Replace the list of ignored source filenames, depending on the storage method
            switch (ignoreListStorageMode)
            {
            case IgnoreListType.GeneratedFileFilter:
                ReplaceIgnoredFileNamesInGeneratedFileFilter(xmlDocument, newFileNames);
                break;

            case IgnoreListType.SourceFileList:
                ReplaceIgnoredFileNamesInSourceFileList(xmlDocument, newFileNames);
                break;

            default:
                throw new System.InvalidOperationException("Invalid storage mode for the StyleCop ignore list!");
            }

            xmlDocument.Save((string)xmlFilePath);

            return(true);
        }
Esempio n. 3
0
        ////=====================================================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="DirectoryView" /> class.
        /// </summary>
        /// <param name="path">UniversalPath to construct the DirectoryView from</param>
        internal DirectoryView(UniversalPath path)
        {
            if (!System.IO.Directory.Exists((string)path))
            {
                throw new System.ArgumentException(string.Format("Attempting to create a Directory with invalid path: {0}", path));
            }

            this.Build(new DirectoryInfo((string)path));
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the location of the StyleCop .Settings XML file, and validates it
        /// </summary>
        /// <param name="filePath">UniversalPath to the StyleCop .Settings file</param>
        internal void SetStyleCopFile(UniversalPath filePath)
        {
            string errorMessage;

            if (!XMLTool.IsStyleCopFileValid(filePath, out errorMessage))
            {
                throw new System.ArgumentException(errorMessage);
            }

            this.saveData.StyleCopSettingsFilePath = filePath;

            this.cachedIsStyleCopSettingsFileValid = true;
            this.CheckStyleCopFileSynced();
        }
        /// <summary>
        /// Determines whether the supplied file path is a valid StyleCop .Settings XML file, providing an error message if not
        /// </summary>
        /// <param name="xmlFilePath">Absolute full path to the StyleCop .Settings XML file</param>
        /// <param name="errorMessage">String field to hold the error message</param>
        /// <returns>Returns true if the supplied file is a valid StyleCop .Settings XML file, otherwise false</returns>
        internal static bool IsStyleCopFileValid(UniversalPath xmlFilePath, out string errorMessage)
        {
            if (!xmlFilePath.IsValid)
            {
                errorMessage = "Selected file does not exist:" + Environment.NewLine + Environment.NewLine + xmlFilePath;
                return(false);
            }

            var fileInfo = new FileInfo((string)xmlFilePath);

            if (fileInfo.Extension != ("." + StyleCopIgnoreUtility.StyleCopFileExtension))
            {
                errorMessage = "Selected file does not have the correct extension:" + Environment.NewLine + Environment.NewLine + xmlFilePath;
                return(false);
            }

            // Try loading the XML file
            var xmlDocument = new XmlDocument();

            try
            {
                xmlDocument.Load((string)xmlFilePath);
            }
            catch
            {
                errorMessage = "Selected file is not a valid StyleCop Settings file:" + Environment.NewLine + Environment.NewLine + xmlFilePath;
                return(false);
            }

            // Check its contents for a StyleCop Settings outer element
            var rootElement = (XmlElement)xmlDocument.SelectSingleNode("/StyleCopSettings");

            if (rootElement == null)
            {
                // XML doesn't seem to contain StyleCop stuff
                errorMessage = "Selected file does not contain valid StyleCop Settings contents:" + Environment.NewLine + Environment.NewLine + xmlFilePath;
                return(false);
            }

            errorMessage = string.Empty;
            return(true);
        }
        //// ====================================================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="FileTreeView"/> class., starting from the supplied path
        /// </summary>
        /// <param name="rootPath">A UniversalPath to the root of the FileTreeView to be created</param>
        internal FileTreeView(UniversalPath rootPath)
        {
            this.root            = new DirectoryView(rootPath);
            this.root.IsExpanded = true;
        }
        /// <summary>
        /// Determines whether the supplied file path is a valid StyleCop .Settings XML file
        /// </summary>
        /// <param name="xmlFilePath">Absolute full path to the StyleCop .Settings XML file</param>
        /// <returns>Returns true if the supplied file is a valid StyleCop .Settings XML file, otherwise false</returns>
        internal static bool IsStyleCopFileValid(UniversalPath xmlFilePath)
        {
            string throwAwayString;

            return(IsStyleCopFileValid(xmlFilePath, out throwAwayString));
        }