Ejemplo n.º 1
0
        public override void Run(IEnumerable <string> args)
        {
            string        rootdir     = "";
            string        omitlist    = "";
            string        processlist = "";
            string        pattern     = "";
            List <string> extras      = CommandUtils.ProcessFileArgs(args,
                                                                     ref rootdir,
                                                                     ref omitlist,
                                                                     ref processlist,
                                                                     ref pattern);
            string sigil      = "To be added.";
            string outputfile = "";

            var opt = new OptionSet
            {
                { "s|sigil=", (s) => sigil = s },
                { "o|output|ofile=", (o) => outputfile = o.EndsWith(@"csv") ? o : outputfile }
            };

            extras = opt.Parse(extras);

            if (String.IsNullOrEmpty(outputfile))
            {
                throw new ArgumentException("You must supply an output file, and it must end with '.csv'");
            }

            CommandUtils.ThrowOnFiniteExtras(extras);

            List <XElement> results = new List <XElement>();

            IEnumerable <string> files    = CommandUtils.GetFileList(processlist, omitlist, rootdir, pattern);
            List <string>        fileList = files.ToList();

            foreach (string file in fileList)
            {
                AddResults(file, results, sigil);
            }

            WriteResults(results, outputfile);
        }
Ejemplo n.º 2
0
        public override void Run(IEnumerable <string> args)
        {
            string        rootdir     = "";
            string        omitlist    = "";
            string        processlist = "";
            string        pattern     = "";
            List <string> extras      = CommandUtils.ProcessFileArgs(args,
                                                                     ref rootdir,
                                                                     ref omitlist,
                                                                     ref processlist,
                                                                     ref pattern
                                                                     );

            CommandUtils.ThrowOnFiniteExtras(extras);

            foreach (string file in CommandUtils.GetFileList(processlist, omitlist, rootdir, pattern))
            {
                bool      changed = false;
                XDocument xdoc    = new XDocument(XElement.Load(file));

                XElement memberRoot = xdoc.Element("Type").Element("Members");
                if (memberRoot == null || !memberRoot.Descendants().Any())
                {
                    continue;
                }


                foreach (XElement m in memberRoot.Elements("Member"))
                {
                    XElement summary = m.Element("Docs").Element("summary");

                    if (null == summary)
                    {
                        continue;
                    }

                    if (summary.IsEmpty || (summary.Value.Length == 0 && summary.Descendants().Count() == 0))
                    {
                        summary.Value = "To be added.";
                        changed       = true;
                        continue;
                    }

                    IEnumerable <XElement> mistakeParams = summary.Descendants("param");

                    if (mistakeParams.Count() == 0)
                    {
                        continue;
                    }

                    mistakeParams.ToList().ForEach(e => e.Name = "paramref");

                    changed = true;
                }

                if (changed)
                {
                    CommandUtils.WriteXDocument(xdoc, file);
                }
            }
        }
Ejemplo n.º 3
0
        public override void Run(IEnumerable <string> args)
        {
            string        rootdir     = "";
            string        omitlist    = "";
            string        processlist = "";
            string        pattern     = "";
            List <string> extras      = CommandUtils.ProcessFileArgs(args,
                                                                     ref rootdir,
                                                                     ref omitlist,
                                                                     ref processlist,
                                                                     ref pattern
                                                                     );

            string message = "For internal use only.";
            string sigil   = "To be added.";
            bool   nocheck = false;
            bool   nosigil = false;

            var opt = new OptionSet {
                { "m|message=", (m) => message = m },
                { "s|sigil=", (s) => sigil = s },
                { "no-check-browsable", (n) => nocheck = n != null },
                { "no-check-TBA", (t) => nosigil = t != null }
            };

            extras = opt.Parse(extras);

            CommandUtils.ThrowOnFiniteExtras(extras);

            Func <XElement, bool>  hassigil;
            Func <XDocument, bool> typehassigil;
            Func <XElement, bool>  qualifies;

            if (nosigil)
            {
                // Mark types and members internal, regardless of whether the summaries are filled out
                hassigil     = (x) => true;
                typehassigil = (x) => true;
            }
            else
            {
                hassigil     = (e) => e.Element("Docs").Element("summary").Value == sigil;
                typehassigil = (t) => t.Element("Type").Element("Docs").Element("summary").Value == sigil;
            }

            if (!nocheck)
            {
                qualifies = (e) =>
                {
                    return(e.Elements("Attributes")
                           .Any((XElement child) => child.Elements("Attribute")
                                .Any((XElement name) => name.Value.Contains("EditorBrowsableState.Never"))) &&
                           hassigil(e));
                };
            }
            else
            {
                qualifies = hassigil;
            }

            foreach (string file in CommandUtils.GetFileList(processlist, omitlist, rootdir, pattern))
            {
                XDocument xdoc = new XDocument(XElement.Load(file));
                // Find every member that has the internal marker and summary="To be added." (or the provided sigil)

                XElement memberRoot = xdoc.Element("Type").Element("Members");
                if (memberRoot == null || !memberRoot.Descendants().Any())
                {
                    continue;
                }

                IEnumerable <XElement> hits = memberRoot.Elements("Member").Where(s => qualifies(s));

                foreach (XElement x in hits)
                {
                    x.Element("Docs").Element("summary").Value = message;
                }

                if (typehassigil(xdoc))
                {
                    xdoc.Element("Type").Element("Docs").Element("summary").Value = message;
                }


                CommandUtils.WriteXDocument(xdoc, file);
            }
        }
Ejemplo n.º 4
0
        public override void Run(IEnumerable <string> args)
        {
            string filesToFixDir = "";
            string omitlist      = "";
            string processlist   = "";
            string pattern       = "";

            List <string> extras = CommandUtils.ProcessFileArgs(args,
                                                                ref filesToFixDir,
                                                                ref omitlist,
                                                                ref processlist,
                                                                ref pattern);
            // must have
            string filesToUseAsRefDir = "";
            // should have
            bool doSummaries  = true;
            bool doParameters = true;
            bool doReturns    = true;
            bool doRemarks    = true;
            bool doTypes      = true;
            // nice to have
            bool dryRun        = false;
            bool reportChanges = false;

            var opts = new OptionSet {
                { "f|fix=", (f) => filesToFixDir = f },
                { "u|using=", (u) => filesToUseAsRefDir = u },
                { "s|summaries", (s) => doSummaries = s != null },
                { "a|params", (p) => doParameters = p != null },
                { "r|retvals", (r) => doReturns = r != null },
                { "m|remarks", (r) => doRemarks = r != null },
                { "t|typesummaries", (t) => doTypes = t != null },
                { "y|dryrun", (d) => dryRun = d != null },
                { "c|reportchanges", (c) => reportChanges = c != null },
            };

            extras = opts.Parse(extras);
            CommandUtils.ThrowOnFiniteExtras(extras);
            if (String.IsNullOrEmpty(filesToUseAsRefDir))
            {
                throw new ArgumentException("You must supply a parallel directory from which to source new content with '[u|using]'=.");
            }


            IEnumerable <string> filesToFix            = CommandUtils.GetFileList(processlist, omitlist, filesToFixDir, pattern);
            HashSet <string>     filesToUseAsReference = new HashSet <string>(CommandUtils.GetFileList("", "", filesToUseAsRefDir, ""));

            filesToFix =
                filesToFix.Where((f) =>
                                 filesToUseAsReference.Contains(EcmaXmlHelper.GetParallelFilePathFor(f,
                                                                                                     filesToUseAsRefDir,
                                                                                                     filesToFixDir)));


            foreach (var f in filesToFix)
            {
                XDocument currentRefXDoc = EcmaXmlHelper.GetParallelXDocFor(
                    EcmaXmlHelper.GetParallelFilePathFor(f, filesToUseAsRefDir, filesToFixDir),
                    filesToUseAsReference
                    );

                if (null == currentRefXDoc)
                {
                    continue;
                }

                Action <XElement> fix =
                    (XElement e) => EcmaXmlHelper.Fix(e, EcmaXmlHelper.GetSelectorFor(e)(currentRefXDoc));

                bool      changed          = false;
                XDocument currentXDocToFix = XDocument.Load(f);

                EventHandler <XObjectChangeEventArgs> SetTrueIfChanged = null;
                SetTrueIfChanged =
                    new EventHandler <XObjectChangeEventArgs>((sender, e) => { currentXDocToFix.Changed -= SetTrueIfChanged; changed = true; });
                currentXDocToFix.Changed += SetTrueIfChanged;

                foreach (XElement e in EcmaXmlHelper.ElementsOfInterest(currentXDocToFix))
                {
                    fix(e);
                }

                if (changed)
                {
                    CommandUtils.WriteXDocument(currentXDocToFix, f);
                }
            }
        }
Ejemplo n.º 5
0
        public override void Run(IEnumerable <string> args)
        {
            // throw new NotImplementedException();

            string updatedDir  = "";
            string omitlist    = "";
            string processlist = "";
            string pattern     = "";

            List <string> extras = CommandUtils.ProcessFileArgs(args,
                                                                ref updatedDir,
                                                                ref omitlist,
                                                                ref processlist,
                                                                ref pattern);

            string oldFilesDir = "";
            bool   typeOnly    = false;
            string reportFile  = "";
            bool   nosigil     = false;

            var options = new OptionSet {
                { "previous=", (p) => oldFilesDir = p },
                { "typeonly", (t) => typeOnly = t != null },
                { "reportfile=", (r) => reportFile = r },
                { "no-check-TBA", (t) => nosigil = t != null }
            };

            extras = options.Parse(extras);

            CommandUtils.ThrowOnFiniteExtras(extras);

            if (String.IsNullOrEmpty(oldFilesDir))
            {
                throw new ArgumentException("You must supply a parallel directory from which to source new content with 'previous='.");
            }

            if (String.IsNullOrEmpty(reportFile) || !reportFile.EndsWith(".csv"))
            {
                throw new ArgumentException("'reportfile=' must be used, and its value must end with '.csv'.");
            }

            string bareReportDir = Path.GetDirectoryName(Path.GetFullPath(reportFile));

            if (!Directory.Exists(bareReportDir))
            {
                throw new ArgumentException(bareReportDir + " does not exist.");
            }

            IEnumerable <string> updated = CommandUtils.GetFileList(processlist, omitlist, updatedDir, pattern);

            StreamWriter reportStream = new StreamWriter(reportFile);

            reportStream.WriteLine(String.Format(CommandUtils.CSVFormatString(5), "File Name", "Type", "Member", "Need file summary", "Need member summary"));

            Func <XElement, bool> hasSigil = null;

            if (nosigil)
            {
                hasSigil = (XElement e) => true;
            }
            else
            {
                hasSigil = (XElement e) => e.Element("Docs").Element("summary").Value == "To be added.";
            }

            //Func<XElement, bool> needSummary = (XElement e) => e.Element("Docs").Element("summary").Value == "To be added.";

            Func <XElement, string> MemberLine = (XElement e) => {
                return(string.Format(
                           CommandUtils.CSVFormatString(5),
                           "",
                           "",
                           e.Attribute("MemberName").Value,
                           "",
                           hasSigil(e) ? "y" : "n"));
            };



            List <string> toWrite = new List <string>();

            foreach (string updatedXMLFile in updated)
            {
                bool fileLineAdded = false;

                XDocument updatedXDoc = XDocument.Load(updatedXMLFile);

                Func <string> FileLine = () =>
                {
                    return(string.Format(
                               CommandUtils.CSVFormatString(5),
                               updatedXMLFile,
                               updatedXDoc.Element("Type").Attribute("FullName").Value,
                               "",
                               hasSigil(updatedXDoc.Element("Type")) ? "y" : "n",
                               ""));
                };


                string    oldXMLFile = EcmaXmlHelper.GetParallelFilePathFor(updatedXMLFile, oldFilesDir, updatedDir);
                XDocument oldXDoc    = File.Exists(oldXMLFile) ? XDocument.Load(oldXMLFile) : null;
                if (null == oldXDoc && hasSigil(updatedXDoc.Element("Type")))
                {
                    toWrite.Add(FileLine());
                    fileLineAdded = true;
                }

                IEnumerable <XElement> newMembers = EcmaXmlHelper.NewMembers(updatedXDoc, oldXDoc);
                if (null != newMembers && newMembers.Where((f) => hasSigil(f)).Any())
                {
                    if (!fileLineAdded)
                    {
                        toWrite.Add(FileLine());
                    }

                    foreach (XElement e in newMembers.Where((f) => hasSigil(f)))
                    {
                        toWrite.Add(MemberLine(e));
                    }
                }

                // If toWrite isn't empty, write all lines
                if (toWrite.Any())
                {
                    foreach (string s in toWrite)
                    {
                        reportStream.WriteLine(s);
                    }
                }
                toWrite.Clear();
            }
            reportStream.Flush();
            reportStream.Close();
        }
Ejemplo n.º 6
0
        public override void Run(IEnumerable <string> args)
        {
            string rootdir     = "";
            string omitlist    = "";
            string processlist = "";
            string pattern     = "";

            List <string> extras = CommandUtils.ProcessFileArgs(args,
                                                                ref rootdir,
                                                                ref omitlist,
                                                                ref processlist,
                                                                ref pattern);
            string obsoleteMarker = "System.Obsolete";
            string sigil          = "To be added.";
            bool   skipSigil      = false;
            string message        = "Deprecated. Do not use.";
            var    opt            = new OptionSet {
                { "a|attribute",
                  (x) => obsoleteMarker = x },
                { "s|sigil=", (s) => sigil = s },
                { "no-check-TBA", (s) => skipSigil = s != null },
                { "m|message=", (m) => message = m }
            };

            extras = opt.Parse(extras);
            CommandUtils.ThrowOnFiniteExtras(extras);

            Func <XElement, bool> sigilCheck;
            Func <XElement, bool> obsoleteCheck;

            if (skipSigil)
            {
                sigilCheck = (e) => true;
            }
            else
            {
                sigilCheck = (e) => e.Element("Docs").Element("summary").Value == sigil;
            }

            obsoleteCheck = (e) => e.Elements("Attribute").Any((arg) =>
                                                               arg.Elements("Attribute").Any((arg2) =>
                                                                                             arg2.Value.StartsWith(obsoleteMarker)));;;

            foreach (string file in CommandUtils.GetFileList(processlist, omitlist, rootdir, pattern))
            {
                // find all the ones that have attributes that start with the provided attribute
                XDocument xdoc = XDocument.Load(file);

                XElement memberRoot = xdoc.Element("Type").Element("Members");
                if (memberRoot == null || !memberRoot.Descendants().Any())
                {
                    continue;
                }

                foreach (XElement toMark in memberRoot.Elements("Member")
                         .Where((e) => obsoleteCheck(e) && sigilCheck(e)))
                {
                    toMark.Element("Docs").Element("summary").Value = message;
                }
                CommandUtils.WriteXDocument(xdoc, file);
            }
        }