Exemple #1
0
        public void SaveToDirectory(string directoryPath)
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new InvalidOperationException("Der Projektname muss angegeben werden.");
            }

            string srcDirectory  = Path.Combine(directoryPath, Name);
            string testDirectory = Path.Combine(directoryPath, $"{Name}.Test");

            // Ordner anlegen
            Directory.CreateDirectory(srcDirectory);
            Directory.CreateDirectory(testDirectory);

            // Sourcen schreiben
            foreach (var sourceBuilder in Sources)
            {
                string path = Path.Combine(srcDirectory, sourceBuilder.Name);

                var codeBuilder = new CodeBuilder();
                sourceBuilder.CodeGen(codeBuilder);

                File.WriteAllText(path, codeBuilder.ToString());
            }

            // packaging-Ordner schreiben
            CreatePackaging(Path.Combine(srcDirectory, "packaging"));

            // csproj schreiben
            var csproj = PrepareSkeleton(StaticCodeLoader.Load(StaticCodeLoader.ProjectSkeletonCsprojStaticCodeName));

            File.WriteAllText(Path.Combine(srcDirectory, $"{Name}.csproj"), csproj);

            if (TestDataPaths != null && TestDataPaths.Length > 0)
            {
                // Testdaten kopieren
                int filei = 0;
                foreach (string path in TestDataPaths)
                {
                    File.Copy(path, Path.Combine(testDirectory, $"testdata-{++filei}.csv"));
                }

                // Testprojekt schreiben
                string testClass = PrepareSkeleton(StaticCodeLoader.Load(StaticCodeLoader.TestSkeletonStaticCodeName));
                File.WriteAllText(Path.Combine(testDirectory, "Test.cs"), testClass);

                // csproj schreiben
                var testCsproj = PrepareSkeleton(StaticCodeLoader.Load(StaticCodeLoader.TestProjectSkeletonCsprojStaticCodeName));
                File.WriteAllText(Path.Combine(testDirectory, $"{Name}.Test.csproj"), testCsproj);
            }

            // Solution schreiben
            var solution = PrepareSkeleton(StaticCodeLoader.Load(StaticCodeLoader.SolutionSkeletonStaticCodeName));

            File.WriteAllText(Path.Combine(directoryPath, $"{Name}.sln"), solution);
        }
Exemple #2
0
        private void CreatePackaging(string path)
        {
            Directory.CreateDirectory(path);

            // _._ für das NuGet-Paket
            File.Create(Path.Combine(path, "_._")).Dispose();

            // Targets-Datei
            string targets = PrepareSkeleton(StaticCodeLoader.Load(StaticCodeLoader.TargetsSkeletonStaticCodeName));

            File.WriteAllText(Path.Combine(path, $"{Name}.targets"), targets);
        }