public void AddAttributesToElementTest()
        {
            var exp = CreateExceptedElement();

            var element  = CsXmlDocumentParser.ParseMultiFiles(new string[] { "TestData/TestXmlDoc1.xml" });
            var csParser = new CSharpEasyAnalyzer();

            csParser.Parse("TestData/Test");
            csParser.AddAttributesToElement(element);

            Assert.AreEqual(exp, element);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Entry point.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var envParser = new Parser.EnvArgumentParser();

            envParser.AddOptionCount("-h", 0);
            envParser.AddOptionCount("-b", 1);
            envParser.AddOptionCount("-o", 1);
            envParser.AddOptionCount("-s", 1);
            envParser.AddOptionCount("-t", 1);
            envParser.AddOptionCount("-i", 1);

            envParser.Analyze(args);
            if (envParser.GetOption("-h") != null)
            {
                ShowHelp();
                return;
            }

            var type            = ProjectTypeConverter.ToProjectType(envParser.GetOption("-t") ?? "Classic");
            var baseTemplateDir = envParser.GetOption("-b") ?? "BaseTemplate";
            var sourceFilesDir  = envParser.GetOption("-s") ?? "src"; // XmlDocumentExtensions.xml  XmlDocumentParser.xml XmlDocumentToHtml.xml
            var inputFiles      = envParser.GetValues();              // GetXmlFiles(sourceFilesDir); // envParser.GetValues();

            if (inputFiles.Length < 1)
            {
                inputFiles = GetXmlFiles(sourceFilesDir);
            }
            var outputPath = envParser.GetOutputFilepath() ?? PathUtils.UnifiedPathSeparator("{0}/Root".FormatString(CommonCoreLib.AppInfo.GetAppPath()));

            var ignorePathText = envParser.GetOption("-i");
            var ignorePathList = new List <string>();

            if (ignorePathText != null)
            {
                var lines = ignorePathText.Split(' ');
                foreach (var line in lines)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        ignorePathList.Add(line);
                    }
                }
            }

            var(singleDirectoryName, directoryName) = GetSingleDirectoryNameAndDirectoryName(outputPath);

            var csprojAnalyzer = new ClassicCsprojAnalyzer(sourceFilesDir)
            {
                IgnoreProjectNames = ignorePathList
            };
            Element root;

            if (inputFiles.Length < 1)
            {
                var generator   = new CSharpDocumentGenerator(csprojAnalyzer);
                var xmlDocument = generator.ToString();

                root = CsXmlDocumentParser.ParseFromText(
                    xmlDocument: xmlDocument,
                    rootName: singleDirectoryName,
                    parseProgressEventHandler: XmlParser_ParserProgress,
                    completed: XmlParser_CodeAnalysisCompleted,
                    startAct: (name) => Console.WriteLine("Start XmlParse {0}", name)
                    );
            }
            else
            {
                root = CsXmlDocumentParser.ParseMultiFiles(
                    files: inputFiles,
                    rootName: singleDirectoryName,
                    parseProgressEventHandler: XmlParser_ParserProgress,
                    completed: XmlParser_CodeAnalysisCompleted,
                    startAct: (name) => Console.WriteLine("Start XmlParse {0}", name)
                    );
            }

            var parser = new CSharpEasyAnalyzer();

            parser.CodeAnalysisCompleted += Parser_CodeAnalysisCompleted;
            parser.AnalysisProgress      += Parser_AnalysisProgress;

            Console.WriteLine("Start C# code analysis.");
            parser.Parse(csprojAnalyzer);
            parser.AddAttributesToElement(root);

            var converter = new CsXmlToHtmlWriter(root)
            {
                TemplateDir = baseTemplateDir
            };

            converter.WriteToDisk(directoryName);
        }