Beispiel #1
0
        public static void Invoke(TargetAction action, CleanupOptions cleanupOptions)
        {
            try
            {
                var projects = SolutionActions.FindProjects(DteServiceProvider.Instance);

                for (var i = 0; i < projects.Count; i++)
                {
                    var currentProject = projects[i];
                    if (currentProject.ProjectItems == null)
                    {
                        continue;
                    }
                    if (currentProject.FullName.ToLower().EndsWith(".shproj"))
                    {
                        continue;
                    }

                    for (var j = 1; j < currentProject.ProjectItems.Count; j++)
                    {
                        ActionCSharpOnProjectItem.Action(currentProject.ProjectItems.Item(j), action, cleanupOptions);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
        public static void Invoke(TargetAction action, CleanupOptions cleanupOptions)
        {
            try
            {
                var projects = SolutionActions.FindProjects(DteServiceProvider.Instance);

                for (var i = 0; i < projects.Count; i++)
                {
                    var currentProject = projects[i];
                    if (currentProject.ProjectItems == null)
                    {
                        continue;
                    }
                    if (currentProject.FullName.EndsWith(".shproj", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    for (var j = 1; j < currentProject.ProjectItems.Count; j++)
                    {
                        ActionCSharpOnProjectItem.Action(currentProject.ProjectItems.Item(j), action, cleanupOptions);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorNotification.WriteErrorToFile(e);
                ErrorNotification.WriteErrorToOutputWindow(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
Beispiel #3
0
 public CleanupJob(IWorkflowInstanceStore workflowInstanceStore, IClock clock, IOptions <CleanupOptions> options, ILogger <CleanupJob> logger)
 {
     _workflowInstanceStore = workflowInstanceStore;
     _clock   = clock;
     _options = options.Value;
     _logger  = logger;
 }
Beispiel #4
0
        public static void Invoke(TargetAction action, CleanupOptions cleanupOptions)
        {
            try
            {
                var projects       = DteServiceProvider.Instance.ActiveSolutionProjects as Array;
                var currentProject = projects.GetValue(0) as Project;

                if (currentProject.ProjectItems == null)
                {
                    return;
                }

                if (currentProject.FullName.EndsWith(".shproj", StringComparison.OrdinalIgnoreCase))
                {
                    System.Windows.MessageBox
                    .Show("Clean up can't be called direlctly on Shared Project", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                for (var i = 1; i <= currentProject.ProjectItems.Count; i++)
                {
                    ActionCSharpOnProjectItem.Action(currentProject.ProjectItems.Item(i), action, cleanupOptions);
                }
            }
            catch (Exception e)
            {
                ErrorNotification.WriteErrorToOutputWindow(e);
                ErrorNotification.WriteErrorToFile(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
 static void DoActionForItems(ProjectItems projectItems, TargetAction action, CleanupOptions cleanupOptions)
 {
     for (int subItemIndex = 1; subItemIndex <= projectItems.Count; subItemIndex++)
     {
         var subItem = projectItems.Item(subItemIndex);
         ActionCSharpOnProjectItem.Action(subItem, action, cleanupOptions);
     }
 }
Beispiel #6
0
 public CleanupJob(
     IWorkflowInstanceStore workflowInstanceStore,
     IClock clock,
     IRetentionFilterPipeline retentionFilterPipeline,
     IOptions <CleanupOptions> options,
     ILogger <CleanupJob> logger)
 {
     _workflowInstanceStore = workflowInstanceStore;
     _clock = clock;
     _retentionFilterPipeline = retentionFilterPipeline;
     _options = options.Value;
     _logger  = logger;
 }
        public static void Run(ProjectItem item, CodeCleanerType command, CleanupOptions cleanupOptions)
        {
            if (!ActiveDocument.IsValid(item))
            {
                ErrorNotification.EmailError(Resources.PrivateModifierCleanUpFailed);
            }

            else
            {
                var instance = CodeCleanerFactory.Create(command, cleanupOptions);
                new CodeCleaner(instance, item).Run();
            }
        }
Beispiel #8
0
        public void RemoveUnusedResources()
        {
            //ExStart
            //ExFor:Document.Cleanup(CleanupOptions)
            //ExFor:CleanupOptions
            //ExFor:CleanupOptions.UnusedLists
            //ExFor:CleanupOptions.UnusedStyles
            //ExFor:CleanupOptions.UnusedBuiltinStyles
            //ExSummary:Shows how to remove all unused custom styles from a document.
            Document doc = new Document();

            doc.Styles.Add(StyleType.List, "MyListStyle1");
            doc.Styles.Add(StyleType.List, "MyListStyle2");
            doc.Styles.Add(StyleType.Character, "MyParagraphStyle1");
            doc.Styles.Add(StyleType.Character, "MyParagraphStyle2");

            // Combined with the built-in styles, the document now has eight styles.
            // A custom style is marked as "used" while there is any text within the document
            // formatted in that style. This means that the 4 styles we added are currently unused.
            Assert.AreEqual(8, doc.Styles.Count);

            // Apply a custom character style, and then a custom list style. Doing so will mark them as "used".
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Font.Style = doc.Styles["MyParagraphStyle1"];
            builder.Writeln("Hello world!");

            Aspose.Words.Lists.List list = doc.Lists.Add(doc.Styles["MyListStyle1"]);
            builder.ListFormat.List = list;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");

            // Now, there is one unused character style and one unused list style.
            // The Cleanup() method, when configured with a CleanupOptions object, can target unused styles and remove them.
            CleanupOptions cleanupOptions = new CleanupOptions
            {
                UnusedLists = true, UnusedStyles = true, UnusedBuiltinStyles = true
            };

            doc.Cleanup(cleanupOptions);

            Assert.AreEqual(4, doc.Styles.Count);

            // Removing every node that a custom style is applied to marks it as "unused" again.
            // Rerun the Cleanup method to remove them.
            doc.FirstSection.Body.RemoveAllChildren();
            doc.Cleanup(cleanupOptions);

            Assert.AreEqual(2, doc.Styles.Count);
            //ExEnd
        }
        public static void Action(ProjectItem item, TargetAction targetAction, CleanupOptions cleanupOptions)
        {
            targetAction(item, cleanupOptions);

            if (item.ProjectItems == null)
            {
                return;
            }

            for (var i = 1; i <= item.ProjectItems.Count; i++)
            {
                Action(item.ProjectItems.Item(i), targetAction, cleanupOptions);
            }
        }
        public void RemoveDuplicateStyles()
        {
            //ExStart
            //ExFor:CleanupOptions.DuplicateStyle
            //ExSummary:Shows how to remove duplicated styles from the document.
            Document doc = new Document();

            // Add two styles to the document with identical properties,
            // but different names. The second style is considered a duplicate of the first.
            Style myStyle = doc.Styles.Add(StyleType.Paragraph, "MyStyle1");

            myStyle.Font.Size  = 14;
            myStyle.Font.Name  = "Courier New";
            myStyle.Font.Color = Color.Blue;

            Style duplicateStyle = doc.Styles.Add(StyleType.Paragraph, "MyStyle2");

            duplicateStyle.Font.Size  = 14;
            duplicateStyle.Font.Name  = "Courier New";
            duplicateStyle.Font.Color = Color.Blue;

            Assert.AreEqual(6, doc.Styles.Count);

            // Apply both styles to different paragraphs within the document.
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.ParagraphFormat.StyleName = myStyle.Name;
            builder.Writeln("Hello world!");

            builder.ParagraphFormat.StyleName = duplicateStyle.Name;
            builder.Writeln("Hello again!");

            ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;

            Assert.AreEqual(myStyle, paragraphs[0].ParagraphFormat.Style);
            Assert.AreEqual(duplicateStyle, paragraphs[1].ParagraphFormat.Style);

            // Configure a CleanOptions object, then call the Cleanup method to substitute all duplicate styles
            // with the original and remove the duplicates from the document.
            CleanupOptions cleanupOptions = new CleanupOptions();

            cleanupOptions.DuplicateStyle = true;

            doc.Cleanup(cleanupOptions);

            Assert.AreEqual(5, doc.Styles.Count);
            Assert.AreEqual(myStyle, paragraphs[0].ParagraphFormat.Style);
            Assert.AreEqual(myStyle, paragraphs[1].ParagraphFormat.Style);
            //ExEnd
        }
        public void CleanupUnusedStylesAndLists()
        {
            //ExStart:CleanupUnusedStylesandLists
            Document doc = new Document(MyDir + "Document.docx");

            CleanupOptions cleanupOptions = new CleanupOptions {
                UnusedLists = false, UnusedStyles = true
            };

            // Cleans unused styles and lists from the document depending on given CleanupOptions.
            doc.Cleanup(cleanupOptions);

            doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupUnusedStylesAndLists.docx");
            //ExEnd:CleanupUnusedStylesandLists
        }
        public void CleanupDuplicateStyle()
        {
            //ExStart:CleanupDuplicateStyle
            Document doc = new Document(MyDir + "Document.docx");

            CleanupOptions options = new CleanupOptions {
                DuplicateStyle = true
            };

            // Cleans duplicate styles from the document.
            doc.Cleanup(options);

            doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupDuplicateStyle.docx");
            //ExEnd:CleanupDuplicateStyle
        }
        private static void CleanupDuplicateStyle(string dataDir)
        {
            // ExStart:CleanupDuplicateStyle
            Document doc = new Document(dataDir + "Document.doc");

            CleanupOptions options = new CleanupOptions();

            options.DuplicateStyle = true;

            // Cleans duplicate styles from the document.
            doc.Cleanup(options);

            doc.Save(dataDir + "Document.CleanupDuplicateStyle_out.docx");
            // ExEnd:CleanupDuplicateStyle
            Console.WriteLine("\nAll revisions accepted.\nFile saved at " + dataDir);
        }
Beispiel #14
0
        private void ApplyCleanup()
        {
            CleanupOptions = new CleanupOptions();

            foreach (CleanupItemUserControl item in mainPanel.Controls)
            {
                CleanupOptions.Accept(item);
            }


            Settings.Default.CleanupChoices = CleanupOptions.SerializeValues();
            if (string.IsNullOrEmpty(Settings.Default.CleanupChoices))
            {
                Settings.Default.CleanupChoices = "null";
            }
            Settings.Default.Save();
        }
        private static void CleanupUnusedStylesandLists(string dataDir)
        {
            // ExStart:CleanupUnusedStylesandLists
            Document doc = new Document(dataDir + "Document.doc");

            CleanupOptions cleanupoptions = new CleanupOptions();

            cleanupoptions.UnusedLists  = false;
            cleanupoptions.UnusedStyles = true;

            // Cleans unused styles and lists from the document depending on given CleanupOptions.
            doc.Cleanup(cleanupoptions);

            dataDir = dataDir + "Document.CleanupUnusedStylesandLists_out.docx";
            doc.Save(dataDir);
            // ExEnd:CleanupUnusedStylesandLists
            Console.WriteLine("\nAll revisions accepted.\nFile saved at " + dataDir);
        }
Beispiel #16
0
        public static void Run()
        {
            // ExStart:CleansUnusedStylesandLists
            // The path to the documents directory.
            string   dataDir = RunExamples.GetDataDir_WorkingWithDocument();
            Document doc     = new Document(dataDir + "Document.doc");

            CleanupOptions cleanupoptions = new CleanupOptions();

            cleanupoptions.UnusedLists  = false;
            cleanupoptions.UnusedStyles = true;

            // Cleans unused styles and lists from the document depending on given CleanupOptions.
            doc.Cleanup(cleanupoptions);

            dataDir = dataDir + "Document.Cleanup_out.docx";
            doc.Save(dataDir);
            // ExEnd:CleansUnusedStylesandLists
            Console.WriteLine("\nAll revisions accepted.\nFile saved at " + dataDir);
        }
        public void CleanupDuplicateStyle()
        {
            //ExStart:CleanupDuplicateStyle
            Document doc = new Document(MyDir + "Document.docx");

            // Count of styles before Cleanup.
            Console.WriteLine(doc.Styles.Count);

            // Cleans duplicate styles from the document.
            CleanupOptions options = new CleanupOptions {
                DuplicateStyle = true
            };

            doc.Cleanup(options);

            // Count of styles after Cleanup was decreased.
            Console.WriteLine(doc.Styles.Count);

            doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupDuplicateStyle.docx");
            //ExEnd:CleanupDuplicateStyle
        }
        public static void Invoke(TargetAction action, CleanupOptions cleanupOptions)
        {
            try
            {
                var ideSelectedItems = DteServiceProvider.Instance.SelectedItems;

                for (int itemIndex = 1; itemIndex <= ideSelectedItems.Count; itemIndex++)
                {
                    var selectItem = ideSelectedItems.Item(itemIndex);

                    var selectedProjectItem = selectItem.ProjectItem;

                    if (selectedProjectItem != null)
                    {
                        if (selectedProjectItem.ProjectItems == null || selectedProjectItem.ProjectItems.Count == 0 && action != null)
                        {
                            action(selectedProjectItem, cleanupOptions, true);
                        }
                        else
                        {
                            ActionCSharpOnProjectItem.Action(selectedProjectItem, action, cleanupOptions);
                        }
                    }
                    else if (selectItem.Project != null)
                    {
                        ActionCSharpOnProject.Invoke(action, cleanupOptions);
                    }
                    else
                    {
                        ActionCSharpOnSolution.Invoke(action, cleanupOptions);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorNotification.WriteErrorToFile(e);
                ErrorNotification.WriteErrorToOutputWindow(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
        public void CleanupUnusedStylesAndLists()
        {
            //ExStart:CleanupUnusedStylesandLists
            Document doc = new Document(MyDir + "Unused styles.docx");

            // Combined with the built-in styles, the document now has eight styles.
            // A custom style is marked as "used" while there is any text within the document
            // formatted in that style. This means that the 4 styles we added are currently unused.
            Console.WriteLine($"Count of styles before Cleanup: {doc.Styles.Count}\n" +
                              $"Count of lists before Cleanup: {doc.Lists.Count}");

            // Cleans unused styles and lists from the document depending on given CleanupOptions.
            CleanupOptions cleanupOptions = new CleanupOptions {
                UnusedLists = false, UnusedStyles = true
            };

            doc.Cleanup(cleanupOptions);

            Console.WriteLine($"Count of styles after Cleanup was decreased: {doc.Styles.Count}\n" +
                              $"Count of lists after Cleanup is the same: {doc.Lists.Count}");

            doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupUnusedStylesAndLists.docx");
            //ExEnd:CleanupUnusedStylesandLists
        }
        public ActionReadOnlyCodeCleanup()
        {
            CleanupOptions = new CleanupOptions();

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertZebbleGeneralMethods));
            // CleanupOptions.Accept(new
            //  ReadOnlyMainCleanup(CodeCleanerType.OrganizeUsingDirectives));
            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.SortClassMembers));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.SimplifyVariableDeclarations));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.RemoveAttributeKeywork));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.UpgradeCSharpSyntax));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertPropertiesToAutoProperties));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertFullNameTypesToBuiltInTypes));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.CompactSmallIfElseStatements));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertMsharpGeneralMethods));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertMsharpUIMethods));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertMsharpModelMethods));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.ConvertMembersToExpressionBodied,
                                                      new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)MembersToExpressionBodiedCleanupTypes.ConvertConstructors,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(MembersToExpressionBodiedCleanupTypes), MembersToExpressionBodiedCleanupTypes.ConvertConstructors).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)MembersToExpressionBodiedCleanupTypes.ConvertMethods,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(MembersToExpressionBodiedCleanupTypes),
                                        MembersToExpressionBodiedCleanupTypes.ConvertMethods).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)MembersToExpressionBodiedCleanupTypes.ConvertReadOnlyProperty,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(MembersToExpressionBodiedCleanupTypes), MembersToExpressionBodiedCleanupTypes.ConvertReadOnlyProperty).ToString()
                }
            }
                                                      ));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.CamelCasedFields, new CleanerItemUIInfo[]
            {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)CamelCasedClassFieldsCleanupTypes.NormalFields,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(CamelCasedClassFieldsCleanupTypes),
                                        CamelCasedClassFieldsCleanupTypes.NormalFields).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)CamelCasedClassFieldsCleanupTypes.ConstFields,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(CamelCasedClassFieldsCleanupTypes),
                                        CamelCasedClassFieldsCleanupTypes.ConstFields).ToString()
                },
            }));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.SimplyAsyncCalls, new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)SimplyAsyncCallCleanupTypes.SingleExpression,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(SimplyAsyncCallCleanupTypes), SimplyAsyncCallCleanupTypes.SingleExpression).ToString()
                },
            }));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.PrivateAccessModifier, new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemovePrivateModifierCleanupTypes.RemoveClassFieldsPrivateModifier,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemovePrivateModifierCleanupTypes), RemovePrivateModifierCleanupTypes.RemoveClassMethodsPrivateModifier).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemovePrivateModifierCleanupTypes.RemoveClassMethodsPrivateModifier,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemovePrivateModifierCleanupTypes), RemovePrivateModifierCleanupTypes.RemoveClassMethodsPrivateModifier).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemovePrivateModifierCleanupTypes.RemoveClassPropertiesPrivateModifier,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemovePrivateModifierCleanupTypes), RemovePrivateModifierCleanupTypes.RemoveClassPropertiesPrivateModifier).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemovePrivateModifierCleanupTypes.RemoveNestedClassPrivateModifier,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemovePrivateModifierCleanupTypes), RemovePrivateModifierCleanupTypes.RemoveNestedClassPrivateModifier).ToString()
                },
            }));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.RemoveExtraThisQualification, new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemoveExtraThisCleanupTypes.RemoveFromFieldsCall,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemoveExtraThisCleanupTypes), RemoveExtraThisCleanupTypes.RemoveFromFieldsCall).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemoveExtraThisCleanupTypes.RemoveFromMethodCall,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemoveExtraThisCleanupTypes), RemoveExtraThisCleanupTypes.RemoveFromMethodCall).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)RemoveExtraThisCleanupTypes.RemoveFromPropertiesCall,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(RemoveExtraThisCleanupTypes), RemoveExtraThisCleanupTypes.RemoveFromPropertiesCall).ToString()
                },
            }));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.CamelCasedMethodVariable, new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)CamelCasedMethodCleanupTypes.LocalVariable,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(CamelCasedMethodCleanupTypes), CamelCasedMethodCleanupTypes.LocalVariable).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)CamelCasedMethodCleanupTypes.MethodParameter,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(CamelCasedMethodCleanupTypes), CamelCasedMethodCleanupTypes.MethodParameter).ToString()
                },
            }));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.SimplifyClassFieldDeclarations, new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)SimplifyClassFieldDeclarationCleanupTypes.GroupAndMergeClassFields,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(SimplifyClassFieldDeclarationCleanupTypes), SimplifyClassFieldDeclarationCleanupTypes.GroupAndMergeClassFields).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)SimplifyClassFieldDeclarationCleanupTypes.RemoveClassFieldsInitializerLiteral,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(SimplifyClassFieldDeclarationCleanupTypes), SimplifyClassFieldDeclarationCleanupTypes.RemoveClassFieldsInitializerLiteral).ToString()
                }, new CleanerItemUIInfo
                {
                    CleanerType = (int)SimplifyClassFieldDeclarationCleanupTypes.RemoveClassFieldsInitializerNull,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(SimplifyClassFieldDeclarationCleanupTypes), SimplifyClassFieldDeclarationCleanupTypes.RemoveClassFieldsInitializerNull).ToString()
                },
            }));

            CleanupOptions.Accept(new
                                  ReadOnlyMainCleanup(CodeCleanerType.NormalizeWhiteSpaces, new CleanerItemUIInfo[] {
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Adding_Blank_After_Block_Close_Bracket,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Adding_Blank_After_Block_Close_Bracket).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Adding_Blank_After_Method_Close_Bracket,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Adding_Blank_After_Method_Close_Bracket).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Add_Blank_Line_Between_Statements_More_Than_One_Line,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Add_Blank_Line_Between_Statements_More_Than_One_Line).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Insert_Space_Before_Comment_Text,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Insert_Space_Before_Comment_Text).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.RemoveBlankAfterOpenBracketAndBeforeCloseBrackets,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.RemoveBlankAfterOpenBracketAndBeforeCloseBrackets).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Remove_Brackets_Of_Block_That_Has_Only_One_Statement_With_Length_Shorter_Than_80_Chars,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Remove_Brackets_Of_Block_That_Has_Only_One_Statement_With_Length_Shorter_Than_80_Chars).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.RemoveDuplicateBetweenClassMembers,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.RemoveDuplicateBetweenClassMembers).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.RemoveDuplicateBetweenMethodsStatements,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.RemoveDuplicateBetweenMethodsStatements).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.RemoveDuplicateBetweenNamespaceMembers,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.RemoveDuplicateBetweenNamespaceMembers).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.RemoveDuplicateInsideComments,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.RemoveDuplicateInsideComments).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.RemoveDuplicateInsideUsings,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.RemoveDuplicateInsideUsings).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.TrimTheFile,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.TrimTheFile).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Use_Slash_Instead_Of_Slash_Slash,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Use_Slash_Instead_Of_Slash_Slash).ToString()
                },
                new CleanerItemUIInfo
                {
                    CleanerType = (int)NormalizeWhitespaceCleanupTypes.Add_An_Empty_Line_After_Using_Statements,
                    ShouldBeSelectedByDefault = true,
                    Name = Enum.GetName(typeof(NormalizeWhitespaceCleanupTypes), NormalizeWhitespaceCleanupTypes.Add_An_Empty_Line_After_Using_Statements).ToString()
                },
            }));
        }
        public static void DoCleanup(ProjectItem item, CleanupOptions cleanupOptions, bool fileWindowMustBeOpend = false)
        {
            if (!item.IsCsharpFile() || item.IsCSharpDesignerFile())
            {
                return;
            }

            try
            {
                var path = item.Properties.Item("FullPath").Value.ToString();
                if (path.EndsWithAny(new[] { "AssemblyInfo.cs", "TheApplication.cs" }))
                {
                    return;
                }

                var documentText = item.ToSyntaxNode().SyntaxTree.GetText().ToString();
                if (documentText.Contains("[EscapeGCop(\"Auto generated code.\")]"))
                {
                    return;
                }

                if (item.ToSyntaxNode()
                    .DescendantNodesOfType <AttributeSyntax>()
                    .Any(x => x.Name.ToString() == "EscapeGCop" &&
                         x.ArgumentList != null &&
                         x.ArgumentList.Arguments.FirstOrDefault().ToString()
                         == "\"Auto generated code.\""))
                {
                    return;
                }

                var window = item.Open(Constants.vsViewKindCode);
                window.Activate();

                foreach (var actionTypeItem in cleanupOptions.ActionTypes)
                {
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces)
                    {
                        continue;
                    }
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives)
                    {
                        continue;
                    }
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.ConvertMsharpGeneralMethods)
                    {
                        continue;
                    }

                    CodeCleanerHost.Run(item, actionTypeItem, cleanupOptions);
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces))
                {
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces, cleanupOptions);
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives))
                {
                    window.Document.Close(vsSaveChanges.vsSaveChangesYes);

                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives, cleanupOptions);

                    if (fileWindowMustBeOpend == false)
                    {
                        window = item.Open(Constants.vsViewKindCode);

                        window.Activate();
                    }
                }
                else
                {
                    window.Document.Save();
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.ConvertMsharpGeneralMethods))
                {
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.ConvertMsharpGeneralMethods, cleanupOptions);
                }

                if (fileWindowMustBeOpend == false)
                {
                    window.Close(vsSaveChanges.vsSaveChangesYes);
                }
            }
            catch (Exception e)
            {
                ErrorNotification.WriteErrorToFile(e, item.Properties.Item("FullPath").Value.ToString());
                ErrorNotification.WriteErrorToOutputWindow(e, item.Properties.Item("FullPath").Value.ToString());
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
 public static void DoCleanup(ProjectItem item, CleanupOptions cleanupOptions)
 {
     DoCleanup(item, cleanupOptions, false);
 }
        public static void ReportOnlyDoNotCleanup(ProjectItem item, CleanupOptions cleanupOptions, bool fileWindowMustBeOpend = false)
        {
            if (!item.IsCsharpFile() || item.IsCSharpDesignerFile())
            {
                return;
            }

            try
            {
                ThreadHelper.JoinableTaskFactory
                .Run(async delegate
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                });

                // Sometimes cannot find document's file
                try
                {
                    var documentText = item.ToSyntaxNode().SyntaxTree.GetText().ToString();
                    if (documentText.Contains("[EscapeGCop(\"Auto generated code.\")]"))
                    {
                        return;
                    }
                }
                catch
                {
                    return;
                }

                var path = item.Properties.Item("FullPath").Value.ToString();
                if (path.EndsWithAny(new[] { "AssemblyInfo.cs", "TheApplication.cs" }))
                {
                    return;
                }

                using (var tidyruntimelog = new StreamWriter(Path.Combine(Path.GetTempPath(), "TidyCurrentfilelog.txt"), true))
                    tidyruntimelog.WriteLine(path);


                foreach (var actionTypeItem in cleanupOptions.ActionTypes)
                {
                    if (actionTypeItem != VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces &&
                        actionTypeItem != VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives &&
                        actionTypeItem != VSIX.TidyCSharp.Cleanup.CodeCleanerType.ConvertMsharpGeneralMethods)
                    {
                        var watch = System.Diagnostics.Stopwatch.StartNew();
                        CodeCleanerHost.Run(item, actionTypeItem, cleanupOptions, true);
                        watch.Stop();

                        using (var tidyruntimelog = new StreamWriter(Path.Combine(Path.GetTempPath(), "TidyCurrentActionslog.txt"), true))
                        {
                            tidyruntimelog.WriteLine("Phase1-" + actionTypeItem.ToString() + "-" + watch.ElapsedMilliseconds + " ms");
                        }
                    }
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces))
                {
                    var watch = System.Diagnostics.Stopwatch.StartNew();
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces, cleanupOptions, true);
                    watch.Stop();

                    using (var tidyruntimelog = new StreamWriter(Path.Combine(Path.GetTempPath(), "TidyCurrentActionslog.txt"), true))
                    {
                        tidyruntimelog.WriteLine("Phase2-" + "NormalizeWhiteSpaces" + "-" + watch.ElapsedMilliseconds + " ms");
                    }
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives))
                {
                    var watch = System.Diagnostics.Stopwatch.StartNew();
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives, cleanupOptions, true);
                    watch.Stop();

                    using (var tidyruntimelog = new StreamWriter(Path.Combine(Path.GetTempPath(), "TidyCurrentActionslog.txt"), true))
                    {
                        tidyruntimelog.WriteLine("Phase3-" + "OrganizeUsingDirectives" + "-" + watch.ElapsedMilliseconds + " ms");
                    }
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.ConvertMsharpGeneralMethods))
                {
                    var watch = System.Diagnostics.Stopwatch.StartNew();
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.ConvertMsharpGeneralMethods, cleanupOptions, true);
                    watch.Stop();

                    using (var tidyruntimelog = new StreamWriter(Path.Combine(Path.GetTempPath(), "TidyCurrentActionslog.txt"), true))
                    {
                        tidyruntimelog.WriteLine("Phase4-" + "ConvertMsharpGeneralMethods" + "-" + watch.ElapsedMilliseconds + " ms");
                    }
                }
            }
            catch (Exception e)
            {
                ErrorNotification.WriteErrorToFile(e, item.Properties.Item("FullPath").Value.ToString());
                ErrorNotification.WriteErrorToOutputWindow(e, item.Properties.Item("FullPath").Value.ToString());
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
Beispiel #24
0
        public static ICodeCleaner Create(CodeCleanerType type, CleanupOptions cleanupOptions)
        {
            switch (type)
            {
            case CodeCleanerType.NormalizeWhiteSpaces:
                return(new WhiteSpaceNormalizer()
                {
                    Options = cleanupOptions.WhiteSpaceNormalizer
                });

            case CodeCleanerType.ConvertMembersToExpressionBodied:
                return(new ConvertMembersToExpressionBodied()
                {
                    Options = cleanupOptions.ConvertMembersToExpressionBodied
                });

            case CodeCleanerType.ConvertFullNameTypesToBuiltInTypes:
                return(new ConvertFullNameTypesToBuiltInTypes());

            case CodeCleanerType.SortClassMembers:
                return(new SortClassMembers());

            case CodeCleanerType.SimplyAsyncCalls:
                return(new SimplyAsyncCalls());

            case CodeCleanerType.SimplifyClassFieldDeclarations:
                return(new SimplifyClassFieldDeclarations()
                {
                    Options = cleanupOptions.SimplifyClassFieldDeclarations
                });

            case CodeCleanerType.RemoveAttributeKeywork:
                return(new RemoveAttributeKeywork());

            case CodeCleanerType.CompactSmallIfElseStatements:
                return(new CompactSmallIfElseStatements());

            case CodeCleanerType.RemoveExtraThisQualification:
                return(new RemoveExtraThisQualification()
                {
                    Options = cleanupOptions.RemoveExtraThisQualification
                });

            case CodeCleanerType.CamelCasedMethodVariable:
                return(new CamelCasedLocalVariable());

            case CodeCleanerType.CamelCasedFields:
                return(new CamelCasedFields());

            case CodeCleanerType.PrivateAccessModifier:
                return(new PrivateModifierRemover());

            case CodeCleanerType.OrganizeUsingDirectives:
                return(new UsingDirectiveOrganizer()
                {
                    Options = cleanupOptions.PrivateModifierRemover
                });

            case CodeCleanerType.SimplifyVariableDeclarations:
                return(new SimplifyVariableDeclarations());

            case CodeCleanerType.ConvertPropertiesToAutoProperties:
                return(new ConvertPropertiesToAutoProperties());

            default: return(null);    // TODO
            }
        }
Beispiel #25
0
        public static void DoCleanup(ProjectItem item, CleanupOptions cleanupOptions, bool fileWindowMustBeOpend = false)
        {
            if (!item.IsCsharpFile() || item.IsCSharpDesignerFile())
            {
                return;
            }

            try
            {
                var path = item.Properties.Item("FullPath").Value.ToString();
                if (path.EndsWithAny(new[] { "AssemblyInfo.cs", "TheApplication.cs" }))
                {
                    return;
                }

                var window = item.Open(Constants.vsViewKindCode);

                window.Activate();

                foreach (var actionTypeItem in cleanupOptions.ActionTypes)
                {
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces)
                    {
                        continue;
                    }
                    if (actionTypeItem == VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives)
                    {
                        continue;
                    }

                    CodeCleanerHost.Run(item, actionTypeItem, cleanupOptions);
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces))
                {
                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.NormalizeWhiteSpaces, cleanupOptions);
                }

                if (cleanupOptions.ActionTypes.Contains(VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives))
                {
                    window.Document.Close(vsSaveChanges.vsSaveChangesYes);

                    CodeCleanerHost.Run(item, VSIX.TidyCSharp.Cleanup.CodeCleanerType.OrganizeUsingDirectives, cleanupOptions);

                    if (fileWindowMustBeOpend == false)
                    {
                        window = item.Open(Constants.vsViewKindCode);

                        window.Activate();
                    }
                }
                else
                {
                    window.Document.Save();
                }

                if (fileWindowMustBeOpend == false)
                {
                    window.Close(vsSaveChanges.vsSaveChangesYes);
                }
            }
            catch (Exception e)
            {
                ErrorNotification.EmailError(e);
                ProcessActions.GeeksProductivityToolsProcess();
            }
        }
        public static ICodeCleaner Create(CodeCleanerType type, CleanupOptions cleanupOptions, bool isReportOnly = false)
        {
            switch (type)
            {
            case CodeCleanerType.NormalizeWhiteSpaces:
                return(new WhiteSpaceNormalizer()
                {
                    Options = cleanupOptions.WhiteSpaceNormalizer, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertMembersToExpressionBodied:
                return(new ConvertMembersToExpressionBodied()
                {
                    Options = cleanupOptions.ConvertMembersToExpressionBodied, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertFullNameTypesToBuiltInTypes:
                return(new ConvertFullNameTypesToBuiltInTypes()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.SortClassMembers:
                return(new SortClassMembers()
                {
                    IsReportOnlyMode = isReportOnly
                });;

            case CodeCleanerType.SimplyAsyncCalls:
                return(new SimplyAsyncCalls()
                {
                    Options = cleanupOptions.SimplyAsyncCall, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.SimplifyClassFieldDeclarations:
                return(new SimplifyClassFieldDeclarations()
                {
                    Options = cleanupOptions.SimplifyClassFieldDeclarations, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.RemoveAttributeKeywork:
                return(new RemoveAttributeKeywork()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.CompactSmallIfElseStatements:
                return(new CompactSmallIfElseStatements()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.RemoveExtraThisQualification:
                return(new RemoveExtraThisQualification()
                {
                    Options = cleanupOptions.RemoveExtraThisQualification, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.CamelCasedMethodVariable:
                return(new CamelCasedLocalVariable()
                {
                    Options = cleanupOptions.CamelCasedLocalVariable, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.CamelCasedFields:
                return(new CamelCasedFields()
                {
                    Options = cleanupOptions.CamelCasedFields, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.PrivateAccessModifier:
                return(new PrivateModifierRemover()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.OrganizeUsingDirectives:
                return(new UsingDirectiveOrganizer()
                {
                    Options = cleanupOptions.PrivateModifierRemover, IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.SimplifyVariableDeclarations:
                return(new SimplifyVariableDeclarations()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertPropertiesToAutoProperties:
                return(new ConvertPropertiesToAutoProperties()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertMsharpUIMethods:
                return(new MSharpUICleaner()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertMsharpModelMethods:
                return(new MSharpModelCleaner()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertMsharpGeneralMethods:
                return(new MSharpGeneralCleaner()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.ConvertZebbleGeneralMethods:
                return(new ZebbleCleaner()
                {
                    IsReportOnlyMode = isReportOnly
                });

            case CodeCleanerType.UpgradeCSharpSyntax:
                return(new CSharpSyntaxUpgrade()
                {
                    IsReportOnlyMode = isReportOnly
                });

            default: return(null);    // TODO
            }
        }
Beispiel #27
0
 public CleanupService(IOptions <CleanupOptions> options, IServiceScopeFactory serviceScopeFactory)
 {
     _serviceScopeFactory = serviceScopeFactory;
     _options             = options.Value;
     _timer = new Timer(ExecuteAsync, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
 }