Skip to content

Commit

Permalink
fix GenerationPath bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Jul 10, 2023
1 parent b258d1e commit 8817e43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.MapGeneration.Logics\EasyMicroservices.MapGeneration.Logics.csproj" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.1" />
</ItemGroup>

</Project>
32 changes: 23 additions & 9 deletions src/CSharp/EasyMicroservices.MapGeneration.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@ static async Task Main(string[] args)
{
try
{
Console.WriteLine("Please set Map.json (enter to generate last file openned)");
var jsonFilePath = Console.ReadLine();
var pathProvider = new SystemPathProvider();
string lastFileOppened = pathProvider.Combine(AppDomain.CurrentDomain.BaseDirectory, "LastFile.txt");
if (string.IsNullOrEmpty(jsonFilePath))
{
if (File.Exists(lastFileOppened))
jsonFilePath = await File.ReadAllTextAsync(lastFileOppened, Encoding.UTF8);
}

var jsonFilePath = await LoadFilePath(args, lastFileOppened);
Console.WriteLine($"File opend: {jsonFilePath}");
var appPath = AppDomain.CurrentDomain.BaseDirectory;
EnvironmentLoader loader = new EnvironmentLoader(new NewtonsoftJsonProvider(), new DiskFileProvider(new DiskDirectoryProvider(appPath, pathProvider)));
await loader.Load(jsonFilePath);
Generation generation = new Generation(loader.AppData.Environments.First());
var environmentSchemaBuild = await generation.Build();
CSharpBuilder cSharpBuilder = new CSharpBuilder();
var compiled = await cSharpBuilder.Build(environmentSchemaBuild);
string savedToPath = pathProvider.Combine(loader.AppData.Environments.First().GenerationPath, "CompileTimeClassesMappers.cs");
string savedToPath = pathProvider.Combine(loader.AppData.Environments.First().GetGenerationPath(), "CompileTimeClassesMappers.cs");
await File.WriteAllTextAsync(savedToPath, compiled.ToString(), Encoding.UTF8);
Console.WriteLine($"Generated to {savedToPath}");
await File.WriteAllTextAsync(lastFileOppened, jsonFilePath, Encoding.UTF8);
Expand All @@ -44,5 +38,25 @@ static async Task Main(string[] args)
Console.ReadLine();
await Main(args);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <param name="pathProvider"></param>
/// <returns></returns>
static async Task<string> LoadFilePath(string[] args, string lastFileOppened)
{
if (args != null && args.Any() && File.Exists(args[0]))
return args[0];
Console.WriteLine("Please set Map.json (enter to generate last file openned)");
var jsonFilePath = Console.ReadLine();
if (string.IsNullOrEmpty(jsonFilePath))
{
if (File.Exists(lastFileOppened))
jsonFilePath = await File.ReadAllTextAsync(lastFileOppened, Encoding.UTF8);
}
return jsonFilePath;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EnvironmentInfo

public string GetGenerationPath()
{
return GenerationPath.Replace(PathConstants.ExecutionPath,AppDomain.CurrentDomain.BaseDirectory);
return GenerationPath.Replace(PathConstants.ExecutionPath, AppDomain.CurrentDomain.BaseDirectory);
}

public string GetBuildPath()
Expand Down

0 comments on commit 8817e43

Please sign in to comment.