-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathCodeGenFileManager.cs
72 lines (63 loc) · 3.38 KB
/
CodeGenFileManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/Beef
using OnRamp;
using System;
using System.Collections.Generic;
using System.IO;
namespace Beef.CodeGen
{
/// <summary>
/// Provides code generation file management.
/// </summary>
public static class CodeGenFileManager
{
/// <summary>
/// Gets the list of supported <see cref="CommandType.Entity"/> filenames (will search in order specified).
/// </summary>
public static List<string> EntityFilenames { get; } = new List<string>(new string[] { "entity.beef-5.yaml", "entity.beef-5.yml", "entity.beef-5.json" });
/// <summary>
/// Gets the list of supported <see cref="CommandType.RefData"/> filenames (will search in order specified).
/// </summary>
public static List<string> RefDataFilenames { get; } = new List<string>(new string[] { "refdata.beef-5.yaml", "refdata.beef-5.yml", "refdata.beef-5.json" });
/// <summary>
/// Gets the list of supported <see cref="CommandType.RefData"/> filenames (will search in order specified).
/// </summary>
public static List<string> DataModelFilenames { get; } = new List<string>(new string[] { "datamodel.beef-5.yaml", "datamodel.beef-5.yml", "datamodel.beef-5.json" });
/// <summary>
/// Gets the list of supported <see cref="CommandType.Database"/> filenames (will search in order specified).
/// </summary>
public static List<string> DatabaseFilenames { get; } = new List<string>(new string[] { "database.beef-5.yaml", "database.beef-5.yml", "database.beef-5.json" });
/// <summary>
/// Get the configuration filename.
/// </summary>
/// <param name="directory">The directory/path.</param>
/// <param name="type">The <see cref="CommandType"/>.</param>
/// <param name="company">The company name.</param>
/// <param name="appName">The application name.</param>
/// <returns>The filename</returns>
public static string GetConfigFilename(string directory, CommandType type, string company, string appName)
{
List<string> files = [];
foreach (var n in GetConfigFilenames(type))
{
var fi = new FileInfo(Path.Combine(directory, n.Replace("{{Company}}", company, StringComparison.OrdinalIgnoreCase).Replace("{{AppName}}", appName, StringComparison.OrdinalIgnoreCase)));
if (fi.Exists)
return fi.FullName;
files.Add(fi.Name);
}
throw new CodeGenException($"Configuration file not found; looked for one of the following: {string.Join(", ", files)}.");
}
/// <summary>
/// Gets the list of possible filenames for the specified <paramref name="type"/>.
/// </summary>
/// <param name="type">The <see cref="CommandType"/>.</param>
/// <returns>The list of filenames.</returns>
public static List<string> GetConfigFilenames(CommandType type) => type switch
{
CommandType.Entity => EntityFilenames,
CommandType.RefData => RefDataFilenames,
CommandType.DataModel => DataModelFilenames,
CommandType.Database => DatabaseFilenames,
_ => throw new InvalidOperationException("Command Type is not valid.")
};
}
}