1+ using System . ComponentModel . DataAnnotations ;
2+
3+ namespace FlatBufferEx . Configuration
4+ {
5+ /// <summary>
6+ /// Application configuration class that holds all settings for the FlatBuffer code generator
7+ /// </summary>
8+ public class AppConfiguration
9+ {
10+ /// <summary>
11+ /// Input directory path containing .fbs schema files
12+ /// </summary>
13+ public string InputPath { get ; set ; } = string . Empty ;
14+
15+ /// <summary>
16+ /// Target languages for code generation (e.g., "c++|c#")
17+ /// </summary>
18+ public string Languages { get ; set ; } = "c#" ;
19+
20+ /// <summary>
21+ /// Output directory path for generated code
22+ /// </summary>
23+ public string OutputPath { get ; set ; } = "output" ;
24+
25+ /// <summary>
26+ /// Include directory path for additional schema files
27+ /// </summary>
28+ public string IncludePath { get ; set ; } = string . Empty ;
29+
30+ /// <summary>
31+ /// Supported languages
32+ /// </summary>
33+ public static readonly HashSet < string > SupportedLanguages = new ( ) { "c++" , "c#" } ;
34+
35+ /// <summary>
36+ /// Default FlatBuffer compiler download URL
37+ /// </summary>
38+ public string FlatBufferCompilerUrl { get ; set ; } = "https://github.com/google/flatbuffers/releases/download/v25.2.10/Windows.flatc.binary.zip" ;
39+
40+ /// <summary>
41+ /// Temporary directory for raw FlatBuffer files
42+ /// </summary>
43+ public string TempDirectory { get ; set ; } = "raw" ;
44+
45+ /// <summary>
46+ /// FlatBuffer compiler directory
47+ /// </summary>
48+ public string CompilerDirectory { get ; set ; } = "flatbuffer" ;
49+
50+ /// <summary>
51+ /// Template directory path
52+ /// </summary>
53+ public string TemplateDirectory { get ; set ; } = "Template" ;
54+
55+ /// <summary>
56+ /// Gets the parsed target languages
57+ /// </summary>
58+ public IEnumerable < string > GetTargetLanguages ( )
59+ {
60+ return Languages
61+ . Split ( '|' )
62+ . Select ( x => x . Trim ( ) . ToLower ( ) )
63+ . Where ( x => ! string . IsNullOrEmpty ( x ) )
64+ . Distinct ( ) ;
65+ }
66+
67+ /// <summary>
68+ /// Validates the configuration and returns validation errors
69+ /// </summary>
70+ /// <param name="errors">Collection of validation errors</param>
71+ /// <returns>True if configuration is valid, false otherwise</returns>
72+ public bool IsValid ( out List < string > errors )
73+ {
74+ errors = new List < string > ( ) ;
75+
76+ // Validate input path
77+ if ( string . IsNullOrWhiteSpace ( InputPath ) )
78+ {
79+ errors . Add ( "Input path is required" ) ;
80+ }
81+ else if ( ! Directory . Exists ( InputPath ) )
82+ {
83+ errors . Add ( $ "Input directory does not exist: { InputPath } ") ;
84+ }
85+
86+ // Validate output path
87+ if ( string . IsNullOrWhiteSpace ( OutputPath ) )
88+ {
89+ errors . Add ( "Output path is required" ) ;
90+ }
91+
92+ // Validate languages
93+ if ( string . IsNullOrWhiteSpace ( Languages ) )
94+ {
95+ errors . Add ( "At least one target language must be specified" ) ;
96+ }
97+ else
98+ {
99+ var targetLanguages = GetTargetLanguages ( ) . ToList ( ) ;
100+ if ( ! targetLanguages . Any ( ) )
101+ {
102+ errors . Add ( "No valid target languages specified" ) ;
103+ }
104+
105+ var unsupportedLanguages = targetLanguages . Where ( lang => ! SupportedLanguages . Contains ( lang ) ) . ToList ( ) ;
106+ if ( unsupportedLanguages . Any ( ) )
107+ {
108+ errors . Add ( $ "Unsupported languages: { string . Join ( ", " , unsupportedLanguages ) } . Supported languages: { string . Join ( ", " , SupportedLanguages ) } ") ;
109+ }
110+ }
111+
112+ // Validate template directory
113+ if ( ! Directory . Exists ( TemplateDirectory ) )
114+ {
115+ errors . Add ( $ "Template directory does not exist: { TemplateDirectory } ") ;
116+ }
117+
118+ return ! errors . Any ( ) ;
119+ }
120+
121+ /// <summary>
122+ /// Gets the full output path
123+ /// </summary>
124+ public string GetFullOutputPath ( )
125+ {
126+ return Path . GetFullPath ( OutputPath ) ;
127+ }
128+
129+ /// <summary>
130+ /// Gets the language-specific compiler environment name
131+ /// </summary>
132+ /// <param name="language">Target language</param>
133+ /// <returns>Compiler environment name</returns>
134+ public string GetCompilerEnvironment ( string language )
135+ {
136+ return language switch
137+ {
138+ "c++" => "cpp" ,
139+ "c#" => "csharp" ,
140+ _ => throw new ArgumentException ( $ "Unsupported language: { language } ")
141+ } ;
142+ }
143+
144+ /// <summary>
145+ /// Gets the file extension for the target language
146+ /// </summary>
147+ /// <param name="language">Target language</param>
148+ /// <returns>File extension</returns>
149+ public string GetFileExtension ( string language )
150+ {
151+ return language switch
152+ {
153+ "c++" => ".h" ,
154+ "c#" => ".cs" ,
155+ _ => throw new ArgumentException ( $ "Unsupported language: { language } ")
156+ } ;
157+ }
158+ }
159+ }
0 commit comments