Esempio n. 1
0
        /// <summary>
        /// Inserts the file name into the file.
        /// </summary>
        /// <param name="file">
        /// The file to insert into.
        /// </param>
        public static void InsertFileName(ICSharpFile file)
        {
            string fileName = file.GetSourceFile().ToProjectFile().Location.Name;

            FileHeader fileHeader = new FileHeader(file) { FileName = fileName };
            fileHeader.Update();
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the existing header or inserts one if missing.
        /// </summary>
        /// <param name="file">
        /// THe file to check the header on.
        /// </param>
        public static void InsertFileHeader(ICSharpFile file)
        {
            Lifetimes.Using(
                lifetime =>
                    {
                        FileHeader fileHeader = new FileHeader(file);
                        DocumentationRulesConfiguration docConfig = GetDocumentationRulesConfig(lifetime, file);

                        fileHeader.FileName = file.GetSourceFile().ToProjectFile().Location.Name;
                        fileHeader.CompanyName = docConfig.CompanyName;
                        fileHeader.CopyrightText = docConfig.Copyright;
                        fileHeader.Summary = Utils.GetSummaryText(file);

                        fileHeader.Update();
                    });
        }
Esempio n. 3
0
 /// <summary>
 /// Inserts a summary into the file's header.
 /// </summary>
 /// <param name="file">
 /// The file to insert into.
 /// </param>
 public static void InsertFileHeaderSummary(ICSharpFile file)
 {
     FileHeader fileHeader = new FileHeader(file) { Summary = Utils.GetSummaryText(file) };
     fileHeader.Update();
 }
Esempio n. 4
0
        /// <summary>
        /// Inserts copyright text into the file's header.
        /// </summary>
        /// <param name="file">
        /// The file to insert the company name into.
        /// </param>
        public static void InsertCopyrightText(ICSharpFile file)
        {
            Lifetimes.Using(
                lifetime =>
                    {
                        DocumentationRulesConfiguration docConfig = GetDocumentationRulesConfig(lifetime, file);

                        FileHeader fileHeader = new FileHeader(file) { CopyrightText = docConfig.Copyright };

                        fileHeader.Update();
                    });
        }
Esempio n. 5
0
        /// <summary>
        /// Inserts any missing items from the file header.
        /// Also formats the existing header ensuring that the top and bottom line start with 2 slashes and a space and that a newline follows the header.
        /// </summary>
        /// <param name="file">
        /// The file to update.
        /// </param>
        /// <param name="analyzerSettings">
        /// The analyzer Settings.
        /// </param>
        private static void UpdateFileHeader(ICSharpFile file, AnalyzerSettings analyzerSettings)
        {
            // The idea here is to load the existing header into our FileHeader object
            // The FileHeader object will ensure that the format of the header is correct even if we're not changing its contents
            // Thus we'll swap it out if its changed at the end.
            string fileName = file.GetSourceFile().ToProjectFile().Location.Name;

            // TODO: How do we handle updating the file header?
            // From the main options page?
            // Actually, looks like ReplaceCopyrightElement is the best option. It fixes the filename,
            // the company name and the copyright, and it'll update the summary, if it isn't already set.
            UpdateFileHeaderStyle updateFileHeaderOption = UpdateFileHeaderStyle.ReplaceCopyrightElement;

            if (updateFileHeaderOption == UpdateFileHeaderStyle.Ignore)
            {
                return;
            }

            Lifetimes.Using(
                lifetime =>
                    {
                        DocumentationRulesConfiguration docConfig = GetDocumentationRulesConfig(lifetime, file);
                        string summaryText = Utils.GetSummaryText(file);
                        FileHeader fileHeader = new FileHeader(file) { InsertSummary = analyzerSettings.IsRuleEnabled("FileHeaderMustHaveSummary") };

                        switch (updateFileHeaderOption)
                        {
                            case UpdateFileHeaderStyle.ReplaceCopyrightElement:
                                fileHeader.FileName = fileName;
                                fileHeader.CompanyName = docConfig.CompanyName;
                                fileHeader.CopyrightText = docConfig.Copyright;
                                fileHeader.Summary = string.IsNullOrEmpty(fileHeader.Summary) ? summaryText : fileHeader.Summary;
                                break;

                            case UpdateFileHeaderStyle.ReplaceAll:
                                fileHeader.FileName = fileName;
                                fileHeader.CompanyName = docConfig.CompanyName;
                                fileHeader.CopyrightText = docConfig.Copyright;
                                fileHeader.Summary = summaryText;
                                break;

                            case UpdateFileHeaderStyle.InsertMissing:
                                fileHeader.FileName = string.IsNullOrEmpty(fileHeader.FileName) ? fileName : fileHeader.FileName;
                                fileHeader.CompanyName = string.IsNullOrEmpty(fileHeader.CompanyName) ? docConfig.CompanyName : fileHeader.CompanyName;
                                fileHeader.CopyrightText = string.IsNullOrEmpty(fileHeader.CopyrightText) ? docConfig.Copyright : fileHeader.CopyrightText;
                                fileHeader.Summary = string.IsNullOrEmpty(fileHeader.Summary) ? summaryText : fileHeader.Summary;
                                break;
                        }

                        fileHeader.Update();
                    });
        }
Esempio n. 6
0
        /// <summary>
        /// Inserts copyright text into the file's header.
        /// </summary>
        /// <param name="file">
        /// The file to insert the company name into.
        /// </param>
        public void InsertCopyrightText(ICSharpFile file)
        {
            DocumentationRulesConfiguration docConfig = this.GetDocumentationRulesConfig(file);

            FileHeader fileHeader = new FileHeader(file) { CopyrightText = docConfig.Copyright };

            fileHeader.Update();
        }
Esempio n. 7
0
        /// <summary>
        /// Inserts the company name into the file's header.
        /// </summary>
        /// <param name="file">
        /// The file to insert the company name into.
        /// </param>
        public void InsertCompanyName(ICSharpFile file)
        {
            DocumentationRulesConfiguration docConfig = this.GetDocumentationRulesConfig(file);

            FileHeader fileHeader = new FileHeader(file) { CompanyName = docConfig.CompanyName };

            fileHeader.Update();
        }
Esempio n. 8
0
        /// <summary>
        /// Inserts any missing items from the file header.
        /// Also formats the existing header ensuring that the top and bottom line start with 2 slashes and a space and that a newline follows the header.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <param name="file">
        /// The file to update.
        /// </param>
        private void UpdateFileHeader(DocumentationOptions options, ICSharpFile file)
        {
            // The idea here is to load the existing header into our FileHeader object
            // The FileHeader object will ensure that the format of the header is correct even if we're not changing its contents
            // Thus we'll swap it out if its changed at the end.
            string fileName = file.GetSourceFile().ToProjectFile().Location.Name;
            UpdateFileHeaderStyle updateFileHeaderOption = options.SA1633SA1641UpdateFileHeader;

            if (updateFileHeaderOption == UpdateFileHeaderStyle.Ignore)
            {
                return;
            }

            DocumentationRulesConfiguration docConfig = this.GetDocumentationRulesConfig(file);
            string summaryText = Utils.GetSummaryText(file);
            FileHeader fileHeader = new FileHeader(file) { InsertSummary = options.SA1639FileHeaderMustHaveSummary };

            switch (updateFileHeaderOption)
            {
                case UpdateFileHeaderStyle.ReplaceCopyrightElement:
                    fileHeader.FileName = fileName;
                    fileHeader.CompanyName = docConfig.CompanyName;
                    fileHeader.CopyrightText = docConfig.Copyright;
                    fileHeader.Summary = string.IsNullOrEmpty(fileHeader.Summary) ? summaryText : fileHeader.Summary;
                    break;

                case UpdateFileHeaderStyle.ReplaceAll:
                    fileHeader.FileName = fileName;
                    fileHeader.CompanyName = docConfig.CompanyName;
                    fileHeader.CopyrightText = docConfig.Copyright;
                    fileHeader.Summary = summaryText;
                    break;

                case UpdateFileHeaderStyle.InsertMissing:
                    fileHeader.FileName = string.IsNullOrEmpty(fileHeader.FileName) ? fileName : fileHeader.FileName;
                    fileHeader.CompanyName = string.IsNullOrEmpty(fileHeader.CompanyName) ? docConfig.CompanyName : fileHeader.CompanyName;
                    fileHeader.CopyrightText = string.IsNullOrEmpty(fileHeader.CopyrightText) ? docConfig.Copyright : fileHeader.CopyrightText;
                    fileHeader.Summary = string.IsNullOrEmpty(fileHeader.Summary) ? summaryText : fileHeader.Summary;
                    break;
            }

            fileHeader.Update();
        }