1- using System ;
1+ using System ;
22using System . Collections ;
33using System . Collections . Specialized ;
44using System . IO ;
99using YamlDotNet . Core ;
1010using YamlDotNet . Core . Events ;
1111using System . CodeDom . Compiler ;
12+ using System . Collections . Generic ;
1213
1314
1415class Program
@@ -118,72 +119,54 @@ private static string ToLiteral(string input)
118119 }
119120 }
120121
121- private static string PrintData ( bool indent , int nesting , object data )
122- {
122+ private static string PrintData ( bool indent , int nesting , object data ) {
123123 var s = new StringBuilder ( ) ;
124124
125- if ( indent )
126- {
127- for ( int i = 0 ; i < nesting ; i ++ )
128- {
125+ if ( indent ) {
126+ for ( int i = 0 ; i < nesting ; i ++ ) {
129127 s . Append ( "\t " ) ;
130128 }
131129 }
132130
133- if ( data == null )
134- {
131+ if ( data == null ) {
135132 s . Append ( "null" ) ;
136- }
137- else if ( data is string )
138- {
133+ } else if ( data is string ) {
139134 s . Append ( ToLiteral ( ( string ) data ) ) ;
140- }
141- else if ( data is Array )
142- {
135+ } else if ( data is Array ) {
143136 s . Append ( "new string[]\n " ) ;
144- for ( int i = 0 ; i < nesting ; i ++ )
145- {
137+ for ( int i = 0 ; i < nesting ; i ++ ) {
146138 s . Append ( "\t " ) ;
147139 }
148140 s . Append ( "{\n " ) ;
149141
150142 bool comma = false ;
151- foreach ( object o in ( object [ ] ) data )
152- {
153- if ( comma )
154- {
143+ foreach ( object o in ( object [ ] ) data ) {
144+ if ( comma ) {
155145 s . Append ( ",\n " ) ;
156146 }
157147 s . Append ( PrintData ( true , nesting + 1 , o ) ) ;
158148 comma = true ;
159149 }
160150
161151 s . Append ( "\n " ) ;
162- for ( int i = 0 ; i < nesting ; i ++ )
163- {
152+ for ( int i = 0 ; i < nesting ; i ++ ) {
164153 s . Append ( "\t " ) ;
165154 }
166155 s . Append ( "}" ) ;
167- }
168- else if ( data is OrderedDictionary )
169- {
156+ } else if ( data is OrderedDictionary ) {
170157 s . Append ( "new OrderedDictionary(StructuralComparisons.StructuralEqualityComparer)\n " ) ;
171- for ( int i = 0 ; i < nesting ; i ++ )
172- {
158+ for ( int i = 0 ; i < nesting ; i ++ ) {
173159 s . Append ( "\t " ) ;
174160 }
175161 s . Append ( "{\n " ) ;
176162
177163 bool comma = false ;
178- foreach ( DictionaryEntry entry in ( OrderedDictionary ) data )
179- {
180- if ( comma )
181- {
164+ foreach ( DictionaryEntry entry in ( OrderedDictionary ) data ) {
165+ if ( comma ) {
182166 s . Append ( ",\n " ) ;
183167 }
184168
185- for ( int i = 0 ; i < nesting + 1 ; i ++ )
186- {
169+ for ( int i = 0 ; i < nesting + 1 ; i ++ ) {
187170 s . Append ( "\t " ) ;
188171 }
189172 s . Append ( "{\n " ) ;
@@ -195,8 +178,7 @@ private static string PrintData(bool indent, int nesting, object data)
195178 s . Append ( PrintData ( true , nesting + 2 , entry . Value ) ) ;
196179
197180 s . Append ( "\n " ) ;
198- for ( int i = 0 ; i < nesting + 1 ; i ++ )
199- {
181+ for ( int i = 0 ; i < nesting + 1 ; i ++ ) {
200182 s . Append ( "\t " ) ;
201183 }
202184 s . Append ( "}" ) ;
@@ -205,14 +187,42 @@ private static string PrintData(bool indent, int nesting, object data)
205187 }
206188
207189 s . Append ( "\n " ) ;
208- for ( int i = 0 ; i < nesting ; i ++ )
209- {
190+ for ( int i = 0 ; i < nesting ; i ++ ) {
210191 s . Append ( "\t " ) ;
211192 }
212193 s . Append ( "}" ) ;
194+
195+ } else if ( data is Dictionary < string , HashSet < string > > dict ) {
196+ s . Append ( "new Dictionary<string, HashSet<string>>()\n " ) ;
197+ for ( int i = 0 ; i < nesting ; i ++ ) {
198+ s . Append ( "\t " ) ;
213199 }
214- else
215- {
200+ s . Append ( "{\n " ) ;
201+
202+ bool comma = false ;
203+ foreach ( var entry in dict ) {
204+ if ( comma ) {
205+ s . Append ( ",\n " ) ;
206+ }
207+
208+ for ( int i = 0 ; i < nesting + 1 ; i ++ ) {
209+ s . Append ( "\t " ) ;
210+ }
211+ s . Append ( "{ " ) ;
212+ s . Append ( ToLiteral ( entry . Key ) . Trim ( ) ) ;
213+ s . Append ( ",new HashSet<string>( new string[] { " ) ;
214+ s . Append ( string . Join ( ", " , entry . Value . Select ( a=> ToLiteral ( a ) . Trim ( ) ) ) ) ;
215+ s . Append ( " } ) }" ) ;
216+
217+ comma = true ;
218+ }
219+
220+ s . Append ( "\n " ) ;
221+ for ( int i = 0 ; i < nesting ; i ++ ) {
222+ s . Append ( "\t " ) ;
223+ }
224+ s . Append ( "}" ) ;
225+ } else {
216226 throw new ArgumentException ( ) ;
217227 }
218228
@@ -257,7 +267,8 @@ static void DoWork(StreamReader ReadFrom,TextWriter WriteTo)
257267 er . Expect < DocumentEnd > ( ) ;
258268 er . Expect < StreamEnd > ( ) ;
259269
260-
270+ var modelsets = ( zones [ "modelsets" ] as OrderedDictionary ) . Cast < DictionaryEntry > ( ) . ToDictionary ( entry => entry . Key . ToString ( ) , entry=> ( entry . Value as object [ ] ) . Cast < string > ( ) . ToHashSet ( ) ) ;
271+ //Dictionary<string,string[]> modelSets=new(.Select());
261272 // Remove modelsets key, not a real zone
262273 zones . Remove ( "modelsets" ) ;
263274
@@ -288,7 +299,8 @@ static void DoWork(StreamReader ReadFrom,TextWriter WriteTo)
288299 OrderedDictionary newValueData = new OrderedDictionary ( StructuralComparisons . StructuralEqualityComparer )
289300 {
290301 { "name" , valueData [ "name" ] } ,
291- { "description" , valueData [ "description" ] }
302+ { "description" , valueData [ "description" ] } ,
303+ { "models" , valueData [ "models" ] }
292304 } ;
293305
294306 newValues . Add ( value , newValueData ) ;
@@ -349,6 +361,7 @@ from DictionaryEntry commandEntry in (IEnumerable)commands_
349361
350362 Console . Write (
351363 "using System.Collections;\n " +
364+ "using System.Collections.Generic;\n " +
352365 "using System.Collections.Specialized;\n \n " +
353366 "namespace Eiscp.Core\n " +
354367 "{\n " +
@@ -359,10 +372,12 @@ from DictionaryEntry commandEntry in (IEnumerable)commands_
359372 $ "\t \t public static readonly OrderedDictionary CommandMappings = { PrintData ( false , 2 , commandMappings ) } ;\n " +
360373 "\n " +
361374 $ "\t \t public static readonly OrderedDictionary ValueMappings = { PrintData ( false , 2 , valueMappings ) } ;\n " +
375+ "\n " +
376+ $ "\t \t public static readonly Dictionary<string,HashSet<string>> ModelSets = { PrintData ( false , 2 , modelsets ) } ;\n " +
362377 "\t }\n " +
363378 "}\n "
364379 ) ;
365- Console . Flush ( ) ;
380+ Console . Flush ( ) ; //modelsets
366381 }
367382}
368383
0 commit comments