Example #1
0
        private void CombineRootElementsAndSort(XNodeSection section, CsProjArrange.ArrangeOptions options)
        {
            var combineGroups =
                section.Nodes
                .Where(x => x is XElement)
                .Cast <XElement>()
                .GroupBy(
                    x =>
                    new CombineGroups
            {
                Name       = x.Name.Namespace.ToString() + ":" + x.Name.LocalName,
                Attributes =
                    string.Join(Environment.NewLine,
                                x.Attributes()
                                .Select(y => y.Name.Namespace.ToString() + ":" + y.Name.LocalName + ":" + y.Value)),
            }
                    );

            foreach (var elementGroup in combineGroups)
            {
                if (options.HasFlag(CsProjArrange.ArrangeOptions.CombineRootElements))
                {
                    CombineIdenticalRootElements(section, elementGroup);
                }

                ArrangeAllElementsInGroup(elementGroup);
            }
        }
        private void CombineRootElementsAndSort(XNodeSection section, CsProjArrange.ArrangeOptions options)
        {
            var combineGroups =
                section.Nodes
                .Where(x => x is XElement)
                .Cast <XElement>()
                .GroupBy(
                    x =>
            {
                var combGroup = new CombineGroups
                {
                    Name       = x.Name.Namespace.ToString() + ":" + x.Name.LocalName,
                    Attributes =
                        string.Join(Environment.NewLine,
                                    x.Attributes()
                                    .Select(y => y.Name.Namespace.ToString() + ":" + y.Name.LocalName + ":" + y.Value)),
                };

                combGroup.Name += this.TryAddSubNodeSuffix(x, "PropertyGroup", "VSToolsPath");
                combGroup.Name += this.TryAddSubNodeSuffix(x, "PropertyGroup", "PostBuildEvent");
                combGroup.Name += this.TryAddSubNodeSuffix(x, "ItemGroup", "Folder");

                return(combGroup);
            });

            foreach (var elementGroup in combineGroups)
            {
                if (options.HasFlag(CsProjArrange.ArrangeOptions.CombineRootElements))
                {
                    CombineIdenticalRootElements(section, elementGroup);
                }

                ArrangeAllElementsInGroup(elementGroup);
            }
        }
Example #3
0
        /// <summary>
        /// Run the program using the supplied command line arguments.
        /// </summary>
        /// <param name="args"></param>
        public void Run(string[] args)
        {
            bool   help       = false;
            string inputFile  = null;
            string outputFile = null;
            IEnumerable <string> stickyElementNames    = null;
            IEnumerable <string> keepOrderElementNames = null;
            IEnumerable <string> sortAttributes        = null;

            CsProjArrange.ArrangeOptions options = CsProjArrange.ArrangeOptions.All;

            OptionSet os = new OptionSet()
            {
                { "?|help", "Display this usage message.", x => help = x != null },
                { "i|input=", "Set the input file name. Standard input is the default.", x => inputFile = x },
                { "o|output=", "Set the output file name. Standard output is the default.", x => outputFile = x },
                { "s|sticky=", "Comma separated list of element names which should be stuck to the top.", x => stickyElementNames = x.Split(',') },
                { "k|keeporder=", "Comma separated list of element names where children should not be sorted.", x => keepOrderElementNames = x.Split(',') },
                { "a|attributes=", "Comma separated list of attributes to sort on.", x => sortAttributes = x.Split(',') },
                { "p|options=", "Specify options", x => Enum.TryParse(x, out options) },
            };
            List <string> extra;

            try
            {
                extra = os.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write(System.AppDomain.CurrentDomain.FriendlyName + ": ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `" + System.AppDomain.CurrentDomain.FriendlyName + " --help` for more information.");
                return;
            }

            if (
                help
                ||
                extra.Count > 0
                )
            {
                Help(os);
                return;
            }

            try
            {
                var csProjArrange = CreateCsProjArrange(stickyElementNames, keepOrderElementNames, sortAttributes, options);
                csProjArrange.Arrange(inputFile, outputFile ?? inputFile);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Encountered an error: {0}", e.Message);
#if DEBUG
                Console.ReadLine();
#endif
            }
        }
 public CsProjArrangeStrategy(IEnumerable <string> stickyElementNames, IEnumerable <string> keepOrderElementNames,
                              IEnumerable <string> sortAttributes, CsProjArrange.ArrangeOptions options)
 {
     _stickyElementNames = (stickyElementNames ?? new[] { DefaultMarker }).ToList();
     ReplaceDefaultMarker(_stickyElementNames, _defaultStickyElementNames);
     _keepOrderElementNames = (keepOrderElementNames ?? new[] { DefaultMarker }).ToList();
     ReplaceDefaultMarker(_keepOrderElementNames, _defaultKeepOrderElementNames);
     _sortAttributes = (sortAttributes ?? new[] { DefaultMarker }).ToList();
     ReplaceDefaultMarker(_sortAttributes, _defaultSortAttributes);
     _options = options;
 }
        private void ArrangeSection(XNodeSection section, CsProjArrange.ArrangeOptions options)
        {
            CombineRootElementsAndSort(section, options);

            if (options.HasFlag(CsProjArrange.ArrangeOptions.SplitItemGroups))
            {
                SplitItemGroups(section, _stickyElementNames);
            }

            if (options.HasFlag(CsProjArrange.ArrangeOptions.SortRootElements))
            {
                SortRootElements(section);
            }
        }
Example #6
0
        private static CsProjArrange CreateCsProjArrange(IEnumerable <string> stickyElementNames, IEnumerable <string> keepOrderElementNames,
                                                         IEnumerable <string> sortAttributes, CsProjArrange.ArrangeOptions options)
        {
            CsProjArrangeStrategy strategy      = new CsProjArrangeStrategy(stickyElementNames, keepOrderElementNames, sortAttributes, options);
            CsProjArrange         csProjArrange = new CsProjArrange(strategy);

            return(csProjArrange);
        }
Example #7
0
 public NodeNameComparer(IList <string> stickyElementNames = null, CsProjArrange.ArrangeOptions options = CsProjArrange.ArrangeOptions.None)
 {
     StickyElementNames = stickyElementNames ?? new string[] { };
 }
 private static CsProjArrangeStrategy CreateDefaultTestTarget(CsProjArrange.ArrangeOptions options)
 {
     return(new CsProjArrangeStrategy(null, null, null, options));
 }
 private static CsProjArrangeStrategy CreateTestTarget(IEnumerable <string> stickyElementNames, IEnumerable <string> keepOrderElementNames,
                                                       IEnumerable <string> sortAttributes, CsProjArrange.ArrangeOptions options)
 {
     return(new CsProjArrangeStrategy(stickyElementNames, keepOrderElementNames, sortAttributes, options));
 }
        /// <summary>
        /// Run the program using the supplied command line arguments.
        /// </summary>
        /// <param name="args"></param>
        public void Run(string[] args)
        {
            bool   help       = false;
            string inputFile  = null;
            string outputFile = null;
            IEnumerable <string> stickyElementNames    = null;
            IEnumerable <string> keepOrderElementNames = null;
            IEnumerable <string> sortAttributes        = null;
            bool xamarinOnly          = false;
            bool checkoutedOnly       = false;
            bool usePredefinedFolders = false;

            CsProjArrange.ArrangeOptions options = CsProjArrange.ArrangeOptions.All;

            OptionSet os = new OptionSet()
            {
                { "?|help", "Display this usage message.", x => help = x != null },
                { "i|input=", "Set the input file name. Standard input is the default.", x => inputFile = x },
                { "o|output=", "Set the output file name. Standard output is the default.", x => outputFile = x },
                { "s|sticky=", "Comma separated list of element names which should be stuck to the top.", x => stickyElementNames = x.Split(',') },
                { "k|keeporder=", "Comma separated list of element names where children should not be sorted.", x => keepOrderElementNames = x.Split(',') },
                { "a|attributes=", "Comma separated list of attributes to sort on.", x => sortAttributes = x.Split(',') },
                { "p|options=", "Specify options", x => Enum.TryParse <CsProjArrange.ArrangeOptions>(x, out options) },
                { "xamarinOnly", "search recursive csprojs.", x => xamarinOnly = x != null },
                { "checkoutedOnly", "update recursive csprojs which are modified.", x => checkoutedOnly = x != null },
                { "usePredefinedFolders", "update recursive csprojs which are modified.", x => usePredefinedFolders = x != null },
            };
            List <string> extra;

            try
            {
                extra = os.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write(System.AppDomain.CurrentDomain.FriendlyName + ": ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `" + System.AppDomain.CurrentDomain.FriendlyName + " --help` for more information.");
                return;
            }

            if (
                help
                ||
                extra.Count > 0
                )
            {
                Help(os);
                return;
            }

            try
            {
                //if (xamarinOnly || checkoutedOnly)
                {
                    new CustomSortingProcessor().ProcessSorting(inputFile, xamarinOnly, checkoutedOnly, usePredefinedFolders, (filePath, targetFilePath, arrangeOptions) =>
                    {
                        var csProjArrange = CreateCsProjArrange(stickyElementNames, keepOrderElementNames, sortAttributes, arrangeOptions);
                        csProjArrange.Arrange(filePath, targetFilePath, backupFile: false);
                    });
                }
                //else
                //{
                //	var csProjArrange = CreateCsProjArrange(stickyElementNames, keepOrderElementNames, sortAttributes, options);
                //	csProjArrange.Arrange(inputFile, outputFile ?? inputFile);
                //}
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Encountered an error: {0}", e.Message);
            }
        }