Esempio n. 1
0
        internal void Run()
        {
            var projectDirectoryString = ProjectDirectory?.Trim();

            if (projectDirectoryString is null)
            {
                throw new ArgumentException("必须指定项目路径。", nameof(ProjectDirectory));
            }
            var projectDirectory = new DirectoryInfo(projectDirectoryString);

            var workingDirectoryString = WorkingDirectory?.Trim();

            if (workingDirectoryString is null)
            {
                throw new ArgumentException("必须指定项目工作路径,IntermediateOutputPath。", nameof(WorkingDirectory));
            }
            var workingDirectory = Path.IsPathRooted(workingDirectoryString)
                ? new DirectoryInfo(workingDirectoryString)
                : new DirectoryInfo(Path.Combine(projectDirectory.FullName, workingDirectoryString));

            var rootNamespace = RootNamespace?.Trim();

            if (rootNamespace is null || string.IsNullOrWhiteSpace(rootNamespace))
            {
                throw new ArgumentException("必须指定项目的根命名空间,RootNamespace。", nameof(RootNamespace));
            }

            if (DebugMode is true)
            {
                Debugger.Launch();
                Debugger.Break();
            }

            var yamlFiles = YamlSourceFiles?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                            .Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim())
                            .Select(x => new FileInfo(Path.Combine(projectDirectory.FullName, x))).ToArray();

            if (yamlFiles is null || yamlFiles.Length == 0)
            {
                YC.Logger.Warning("没有指定任何需要转换为 C# 代码的 YAML 文件。是否忘记在项目中设置 <YamlToCSharpFile Include=\"Yaml\\**\\*.yml\" />?");
                yamlFiles ??= new FileInfo[0];
            }

            var outputIndexFileString = OutputIndexFile?.Trim();

            if (outputIndexFileString is null)
            {
                throw new ArgumentException("必须指定输出源代码的目录文件,OutputIndexFile。", nameof(OutputIndexFile));
            }
            var outputIndexFile = Path.IsPathRooted(outputIndexFileString)
                ? new FileInfo(outputIndexFileString)
                : new FileInfo(Path.Combine(projectDirectory.FullName, outputIndexFileString));

            var convertedFiles = RunCore(projectDirectory, workingDirectory, rootNamespace, yamlFiles);

            File.WriteAllText(
                outputIndexFile.FullName,
                string.Join(Environment.NewLine, convertedFiles.Select(x => x.FullName)));
        }