Gccg 1.1.2

dotnet add package Gccg --version 1.1.2                
NuGet\Install-Package Gccg -Version 1.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gccg" Version="1.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gccg --version 1.1.2                
#r "nuget: Gccg, 1.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Gccg as a Cake Addin
#addin nuget:?package=Gccg&version=1.1.2

// Install Gccg as a Cake Tool
#tool nuget:?package=Gccg&version=1.1.2                

usage

using DbContext (only for Entity Framework)

Gccg.Core.Generator.Generate({DbContext object}); ex) Gccg.Core.Generator.Generate(new ChinookContext());

using schema file

Gccg.Core.Generator.Generate({schema file path}); ex) Gccg.Core.Generator.Generate(@"C:\git\Gccg\Examples\Chinook\Chinnok.Gccg\Chinook.json");

Check out README.md in GitHub repository for basic usage and examples. https://github.com/cplkimth/Gccg

internal static class Program
{
    private const int Sleep = 1500;

    private static readonly DbContext _dbContext = new ChinookContext();

    private const string SolutionName = "Chinook";
    private const string Root = @$"D:\git\Gccg\Examples\{SolutionName}";

    private const string DataEF = $@"{Root}\{SolutionName}.Data\EF";
    private const string GccgEF = $@"{Root}\{SolutionName}.Gccg\EF";
    
    private const string ContextPostfix = $@"*Context.cs";

    private static void Main(string[] args)
    {
        Console.WriteLine($"[{DataEF}] 프로젝트에서 EF Core Power Tools를 실행하였습니까?");

        var commands = (Command[])Enum.GetValues(typeof(Command));
        foreach (var command in commands)
            Console.WriteLine($"{(int)command} : {command}");

        var commandInput = (Command)int.Parse(Console.ReadLine()!);

        switch (commandInput)
        {
            case Command.Preparation:
                Prepare();
                break;
            case Command.Generatation:
                Generate();
                break;
        }
        
        Console.WriteLine("done!");
    }

    private static void Prepare()
    {
        Console.WriteLine($"deleting [{GccgEF}]");
        Directory.Delete(GccgEF, true);
        Thread.Sleep(Sleep);

        Console.WriteLine($"copying [{DataEF}] to [{GccgEF}]");
        CopyDirectory(DataEF, GccgEF, true);
        Thread.Sleep(Sleep);

        var contextFile = Directory.GetFiles(DataEF, ContextPostfix).FirstOrDefault();
        Console.WriteLine($"removing OnConfiguring in [{contextFile}]");
        var lines = File.ReadAllLines(contextFile);
        var indexToMove = FindIndexToDelete(lines, "protected override void OnConfiguring");

        if (indexToMove != -1)
        {
            var result = new List<string>();
            result.AddRange(lines.Take(indexToMove));
            result.AddRange(lines.Skip(indexToMove + 3));

            File.WriteAllLines(contextFile, result);
            Thread.Sleep(Sleep);
        }

        Thread.Sleep(Sleep);
    }

    private static void Generate()
    {
        var json = Generator.Generate(_dbContext);
        File.WriteAllText($"{SolutionName}.json", json);
    }

    private static int FindIndexToDelete(string[] lines, string text)
    {
        for (int i = 0; i < lines.Length; i++)
        {
            if (lines[i].Contains(text))
                return i;
        }

        return -1;
    }

    static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
    {
        // Get information about the source directory
        var dir = new DirectoryInfo(sourceDir);

        // Check if the source directory exists
        if (!dir.Exists)
            throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");

        // Cache directories before we start copying
        DirectoryInfo[] dirs = dir.GetDirectories();

        // Create the destination directory
        if (Directory.Exists(destinationDir) == false)
            Directory.CreateDirectory(destinationDir);

        // Get the files in the source directory and copy to the destination directory
        foreach (FileInfo file in dir.GetFiles())
        {
            string targetFilePath = Path.Combine(destinationDir, file.Name);
            file.CopyTo(targetFilePath, true);
        }

        // If recursive and copying subdirectories, recursively call this method
        if (recursive)
        {
            foreach (DirectoryInfo subDir in dirs)
            {
                string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
                CopyDirectory(subDir.FullName, newDestinationDir, true);
            }
        }
    }
}

public enum Command
{
    Preparation = 1,
    Generatation
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 97 8/1/2024
1.1.1 137 4/25/2024
1.1.0 110 4/25/2024
1.0.7 150 4/22/2024
1.0.6 129 1/28/2024
1.0.2 157 9/27/2023 1.0.2 is deprecated because it is no longer maintained.