3
3
using System ;
4
4
using Microsoft . Azure . Management . ApiManagement . ArmTemplates . Common ;
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
7
8
namespace Microsoft . Azure . Management . ApiManagement . ArmTemplates . Create
8
9
{
@@ -31,6 +32,7 @@ public CreateCommand()
31
32
32
33
// initialize helper classes
33
34
FileWriter fileWriter = new FileWriter ( ) ;
35
+ FileNameGenerator fileNameGenerator = new FileNameGenerator ( ) ;
34
36
TemplateCreator templateCreator = new TemplateCreator ( ) ;
35
37
APIVersionSetTemplateCreator apiVersionSetTemplateCreator = new APIVersionSetTemplateCreator ( templateCreator ) ;
36
38
ProductAPITemplateCreator productAPITemplateCreator = new ProductAPITemplateCreator ( ) ;
@@ -41,48 +43,51 @@ public CreateCommand()
41
43
42
44
// create templates from provided configuration
43
45
Template apiVersionSetTemplate = creatorConfig . apiVersionSet != null ? apiVersionSetTemplateCreator . CreateAPIVersionSetTemplate ( creatorConfig ) : null ;
44
- List < Template > initialAPITemplates = new List < Template > ( ) ;
45
- List < Template > subsequentAPITemplates = new List < Template > ( ) ;
46
- List < LinkedMasterTemplateAPIInformation > apiInformation = new List < LinkedMasterTemplateAPIInformation > ( ) ;
46
+ // store name and full template on each api necessary to build unlinked templates
47
+ Dictionary < string , Template > initialAPITemplates = new Dictionary < string , Template > ( ) ;
48
+ Dictionary < string , Template > subsequentAPITemplates = new Dictionary < string , Template > ( ) ;
49
+ // store name and whether the api will depend on the version set template each api necessary to build linked templates
50
+ Dictionary < string , bool > apiInformation = new Dictionary < string , bool > ( ) ;
47
51
48
52
foreach ( APIConfig api in creatorConfig . apis )
49
53
{
50
54
Template initialAPITemplate = await apiTemplateCreator . CreateInitialAPITemplateAsync ( creatorConfig , api ) ;
51
55
Template subsequentAPITemplate = apiTemplateCreator . CreateSubsequentAPITemplate ( api ) ;
52
- initialAPITemplates . Add ( initialAPITemplate ) ;
53
- subsequentAPITemplates . Add ( subsequentAPITemplate ) ;
54
- apiInformation . Add ( new LinkedMasterTemplateAPIInformation ( ) { name = api . name , hasAPIVersionSetId = api . apiVersionSetId != null } ) ;
56
+ initialAPITemplates . Add ( api . name , initialAPITemplate ) ;
57
+ subsequentAPITemplates . Add ( api . name , subsequentAPITemplate ) ;
58
+ apiInformation . Add ( api . name , api . apiVersionSetId != null ) ;
55
59
}
56
60
57
- CreatorFileNames creatorFileNames = fileWriter . GenerateCreatorLinkedFileNames ( creatorConfig ) ;
61
+ CreatorFileNames creatorFileNames = fileNameGenerator . GenerateCreatorLinkedFileNames ( creatorConfig ) ;
62
+ Template masterTemplateParameters = masterTemplateCreator . CreateMasterTemplateParameterValues ( creatorConfig ) ;
58
63
if ( creatorConfig . linked == true )
59
64
{
60
65
// create linked master template
61
- Template masterTemplate = masterTemplateCreator . CreateLinkedMasterTemplate ( apiVersionSetTemplate , apiInformation , creatorFileNames ) ;
66
+ Template masterTemplate = masterTemplateCreator . CreateLinkedMasterTemplate ( apiVersionSetTemplate , apiInformation , creatorFileNames , fileNameGenerator ) ;
67
+ // write parameters to outputLocation
68
+ fileWriter . WriteJSONToFile ( masterTemplateParameters , String . Concat ( creatorConfig . outputLocation , creatorFileNames . linkedParameters ) ) ;
62
69
// write linked specific template to outputLocationc
63
70
fileWriter . WriteJSONToFile ( masterTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . linkedMaster ) ) ;
64
71
}
65
72
else
66
73
{
67
- // write unlinked specific templates to outputLocationc
68
- foreach ( Template initialAPITemplate in initialAPITemplates )
69
- {
70
- fileWriter . WriteJSONToFile ( initialAPITemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . initialAPI ) ) ;
71
- }
72
- foreach ( Template subsequentAPITemplate in subsequentAPITemplates )
73
- {
74
- fileWriter . WriteJSONToFile ( subsequentAPITemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . subsequentAPI ) ) ;
75
- }
76
-
74
+ // write parameters to outputLocation
75
+ fileWriter . WriteJSONToFile ( masterTemplateParameters , String . Concat ( creatorConfig . outputLocation , creatorFileNames . unlinkedParameters ) ) ;
76
+ }
77
+ // write templates to outputLocation
78
+ foreach ( KeyValuePair < string , Template > initialAPITemplatePair in initialAPITemplates )
79
+ {
80
+ string initialAPIFileName = fileNameGenerator . GenerateAPIFileName ( initialAPITemplatePair . Key , true ) ;
81
+ fileWriter . WriteJSONToFile ( initialAPITemplatePair . Value , String . Concat ( creatorConfig . outputLocation , initialAPIFileName ) ) ;
82
+ }
83
+ foreach ( KeyValuePair < string , Template > subsequentAPITemplatePair in subsequentAPITemplates )
84
+ {
85
+ string subsequentAPIFileName = fileNameGenerator . GenerateAPIFileName ( subsequentAPITemplatePair . Key , false ) ;
86
+ fileWriter . WriteJSONToFile ( subsequentAPITemplatePair . Value , String . Concat ( creatorConfig . outputLocation , subsequentAPIFileName ) ) ;
77
87
}
78
- // write parameters to outputLocation
79
- Template masterTemplateParameters = masterTemplateCreator . CreateMasterTemplateParameterValues ( creatorConfig ) ;
80
- fileWriter . WriteJSONToFile ( masterTemplateParameters , String . Concat ( creatorConfig . outputLocation , creatorFileNames . masterParameters ) ) ;
81
-
82
- // write common templates to outputLocationc
83
88
if ( apiVersionSetTemplate != null )
84
89
{
85
- fileWriter . WriteJSONToFile ( apiVersionSetTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . apiVersionSet ) ) ;
90
+ fileWriter . WriteJSONToFile ( apiVersionSetTemplate , String . Concat ( creatorConfig . outputLocation , creatorFileNames . apiVersionSets ) ) ;
86
91
}
87
92
ColoredConsole . WriteLine ( "Templates written to output location" ) ;
88
93
}
0 commit comments