IsSolution() 공개 정적인 메소드

Determines whether or not the specified file is a solution.
public static IsSolution ( string inputFile ) : bool
inputFile string The input file.
리턴 bool
예제 #1
0
        /// <summary>
        /// Arranges a file, project or solution.
        /// </summary>
        /// <param name="inputFile">The input file.</param>
        /// <param name="outputFile">The output file.</param>
        /// <param name="backup">Whether or not to create a backup.</param>
        /// <returns>True if succesful, otherwise false.</returns>
        public bool Arrange(string inputFile, string outputFile, bool backup)
        {
            bool success = true;

            success = Initialize();

            if (success)
            {
                bool isProject   = _projectManager.IsProject(inputFile);
                bool isSolution  = !isProject && ProjectManager.IsSolution(inputFile);
                bool isDirectory = !isProject && !isSolution &&
                                   string.IsNullOrEmpty(Path.GetExtension(inputFile)) && Directory.Exists(inputFile);

                if (!(isProject || isSolution || isDirectory))
                {
                    if (outputFile == null)
                    {
                        outputFile = new FileInfo(inputFile).FullName;
                    }

                    bool canParse = _projectManager.CanParse(inputFile);
                    if (!canParse)
                    {
                        LogMessage(
                            LogLevel.Warning,
                            "No assembly is registered to handle file {0}.  Please update the configuration or select a valid file.",
                            inputFile);
                        success = false;
                    }
                }

                if (success)
                {
                    ReadOnlyCollection <string> sourceFiles = _projectManager.GetSourceFiles(inputFile);
                    if (sourceFiles.Count > 0)
                    {
                        LogMessage(LogLevel.Verbose, "Parsing files...");

                        foreach (string sourceFile in sourceFiles)
                        {
                            if (string.IsNullOrEmpty(outputFile))
                            {
                                ArrangeSourceFile(sourceFile, sourceFile);
                            }
                            else
                            {
                                ArrangeSourceFile(sourceFile, outputFile);
                            }
                        }

                        if (success && _arrangeResults.Count > 0)
                        {
                            success = WriteFiles(inputFile, backup);
                        }
                    }
                    else
                    {
                        if (isSolution)
                        {
                            LogMessage(
                                LogLevel.Warning,
                                "Solution {0} does not contain any supported source files.",
                                inputFile);
                        }
                        else if (isProject)
                        {
                            LogMessage(
                                LogLevel.Warning,
                                "Project {0} does not contain any supported source files.",
                                inputFile);
                        }
                        else
                        {
                            LogMessage(
                                LogLevel.Warning,
                                "Directory {0} does not contain any supported source files.",
                                inputFile);
                        }
                    }

                    if (_filesParsed == 0 && (sourceFiles.Count <= 1 && !(isProject || isSolution || isDirectory)))
                    {
                        success = false;
                    }
                }
            }

            LogMessage(LogLevel.Verbose, "{0} files written.", _filesWritten);

            return(success);
        }
예제 #2
0
        /// <summary>
        /// Arranges a file as a string
        /// </summary>
        /// <param name="inputFile">The input file.</param>
        /// <param name="inputText">The text of the file.</param>
        /// <param name="outputText">The arranged text of the file.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Arrange(string inputFile, string inputFileText, out string outputFileText)
        {
            outputFileText = null;

            if (!Initialize())
            {
                return(false);
            }

            bool isProject   = _projectManager.IsProject(inputFile);
            bool isSolution  = !isProject && ProjectManager.IsSolution(inputFile);
            bool isDirectory = !isProject && !isSolution && string.IsNullOrEmpty(Path.GetExtension(inputFile)) && Directory.Exists(inputFile);

            if (isProject || isSolution || isDirectory)
            {
                return(false);
            }

            if (File.Exists(String.Concat(inputFile, ".cs")))
            {
                inputFile = String.Concat(inputFile, ".cs");
            }
            else if (File.Exists(String.Concat(inputFile, ".vb")))
            {
                inputFile = String.Concat(inputFile, ".vb");
            }

            bool canParse = _projectManager.CanParse(inputFile);

            if (!canParse)
            {
                LogMessage(
                    LogLevel.Warning,
                    "No assembly is registered to handle file {0}.  Please update the configuration or select a valid file.",
                    inputFile);

                return(false);
            }

            ReadOnlyCollection <ICodeElement> elements = null;

            Encoding encoding = _encoding;

            if (encoding == null)
            {
                encoding = FileUtilities.GetEncoding(inputFile);
            }

            try
            {
                elements = _projectManager.ParseElements(inputFile, inputFileText);
                LogMessage(LogLevel.Trace, "Parsed {0}", inputFile);
            }
            catch (ParseException parseException)
            {
                LogMessage(
                    LogLevel.Warning,
                    "Unable to parse file {0}: {1}",
                    inputFile,
                    parseException.Message);

                return(false);
            }

            if (elements != null)
            {
                try
                {
                    if (_codeArranger == null)
                    {
                        _codeArranger = new CodeArranger(_configuration);
                    }

                    elements = _codeArranger.Arrange(elements);
                }
                catch (InvalidOperationException invalidEx)
                {
                    LogMessage(
                        LogLevel.Warning,
                        "Unable to arrange file {0}: {1}",
                        inputFile,
                        invalidEx.ToString());

                    return(false);
                }
            }

            if (elements != null)
            {
                ICodeElementWriter codeWriter = _projectManager.GetSourceHandler(inputFile).CodeWriter;
                codeWriter.Configuration = _configuration;

                StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
                try
                {
                    codeWriter.Write(elements, writer);
                }
                catch (Exception ex)
                {
                    LogMessage(LogLevel.Error, ex.ToString());
                    return(false);
                }

                outputFileText = writer.ToString();
            }

            return(true);
        }