@@ -47,24 +47,35 @@ group article.Uid by serviceCategory into g
4747 select g
4848 ) . ToDictionary ( g => g . Key , g => g . ToList ( ) ) ;
4949
50- List < ServiceMappingItem > others = new List < ServiceMappingItem > ( ) ;
51- Dictionary < string , string > serviceHrefMapping = new Dictionary < string , string > ( ) ;
50+ ServiceMappingItem other = new ServiceMappingItem
51+ {
52+ name = "Other" ,
53+ landingPageType = LandingPageTypeService ,
54+ uid = "azure.java.sdk.landingpage.services.other" ,
55+ children = new List < string > { "*" } ,
56+ } ;
57+ Dictionary < string , string > hrefMapping = new Dictionary < string , string > ( ) ;
5258 if ( File . Exists ( outputPath ) )
5359 {
5460 using ( var reader = new StreamReader ( outputPath ) )
5561 {
5662 var oldMapping = new YamlDeserializer ( ) . Deserialize < ServiceMapping > ( reader ) ;
57- var oldservices = ( from m in oldMapping [ 0 ] . items
58- from sm in m . items ?? Enumerable . Empty < ServiceMappingItem > ( )
59- select new { SM = sm , Name = m . name }
60- ) . ToDictionary ( i => new ServiceCategory { Service = i . Name , Category = i . SM . name } , i => i . SM . children ? . ToList ( ) ?? new List < string > ( ) ) ;
61- Merge ( newservices , oldservices ) ;
62- var other = oldMapping [ 0 ] . items . SingleOrDefault ( i => i . name == "Other" ) ;
63- if ( other != null )
63+ foreach ( var m in oldMapping [ 0 ] . items )
6464 {
65- others . Add ( other ) ;
65+ if ( m . name == "Other" )
66+ {
67+ other = m ;
68+ continue ;
69+ }
70+ hrefMapping [ m . name ] = m . href ;
71+ foreach ( var c in m . items ?? Enumerable . Empty < ServiceMappingItem > ( ) )
72+ {
73+ var sc = new ServiceCategory { Service = m . name , Category = c . name } ;
74+ Merge ( newservices , sc , c . children ? . ToList ( ) ?? new List < string > ( ) ) ;
75+ hrefMapping [ GetKey ( m . name , c . name ) ] = c . href ;
76+ }
6677 }
67- serviceHrefMapping = oldMapping [ 0 ] . items . ToDictionary ( i => i . name , i => i . href ) ;
78+
6879 }
6980
7081 }
@@ -86,31 +97,34 @@ group v.Value by v.Key.Category into g0
8697 {
8798 new ServiceMappingItem ( )
8899 {
89- uid = "landingpage.reference" ,
100+ uid = "azure.java.sdk. landingpage.reference" ,
90101 name = "Reference" ,
91102 landingPageType = "Root" ,
92103 items = new ServiceMapping ( ( from pair in services
93104 let service = pair . Key
94- let hrefAndType = GetServiceHrefAndType ( serviceHrefMapping , service )
105+ let hrefAndType = GetHrefAndType ( hrefMapping , service )
95106 select new ServiceMappingItem ( )
96107 {
97108 name = service ,
98109 href = hrefAndType . Item1 ,
99110 landingPageType = hrefAndType . Item2 ,
100- uid = "landingpage.services." + service ,
111+ uid = "azure.java.sdk. landingpage.services." + service ,
101112 items = new ServiceMapping ( from item in pair . Value
102113 let category = item . Category
114+ let chrefAndType = GetHrefAndType ( hrefMapping , GetKey ( service , category ) )
103115 select new ServiceMappingItem ( )
104116 {
105117 name = item . Category ,
106- uid = "landingpage.services." + service + "." + category ,
107- landingPageType = LandingPageTypeService ,
118+ href = chrefAndType . Item1 ,
119+ landingPageType = chrefAndType . Item2 ,
120+ uid = "azure.java.sdk.landingpage.services." + service + "." + category ,
108121 children = item . Uids . ToList ( )
109122 } )
110123 } ) . OrderBy ( s => s . name ) )
111124 }
112125 } ;
113- mapping [ 0 ] . items . AddRange ( others ) ;
126+ mapping [ 0 ] . items . Add ( other ) ;
127+
114128 using ( var writer = new StreamWriter ( outputPath ) )
115129 {
116130 new YamlSerializer ( ) . Serialize ( writer , mapping ) ;
@@ -143,24 +157,21 @@ private static string FormatPath(string path)
143157 return path . Replace ( '\\ ' , '/' ) ;
144158 }
145159
146- private static void Merge ( Dictionary < ServiceCategory , List < string > > a , Dictionary < ServiceCategory , List < string > > b )
160+ private static void Merge ( Dictionary < ServiceCategory , List < string > > a , ServiceCategory sc , List < string > uids )
147161 {
148- foreach ( var pair in b )
162+ List < string > value ;
163+ if ( ! a . TryGetValue ( sc , out value ) )
149164 {
150- List < string > value ;
151- if ( ! a . TryGetValue ( pair . Key , out value ) )
152- {
153- a [ pair . Key ] = new List < string > ( ) ;
154- }
155- // to-do: when product repo's mapping file is ready, should change the behavior to overwrite.
156- a [ pair . Key ] . AddRange ( pair . Value ) ;
165+ a [ sc ] = new List < string > ( ) ;
157166 }
167+ // to-do: when product repo's mapping file is ready, should change the behavior to overwrite.
168+ a [ sc ] . AddRange ( uids ) ;
158169 }
159170
160- private static Tuple < string , string > GetServiceHrefAndType ( Dictionary < string , string > mapping , string service )
171+ private static Tuple < string , string > GetHrefAndType ( Dictionary < string , string > mapping , string key )
161172 {
162173 string href ;
163- if ( mapping . TryGetValue ( service , out href ) )
174+ if ( mapping . TryGetValue ( key , out href ) && ! string . IsNullOrEmpty ( href ) )
164175 {
165176 return Tuple . Create < string , string > ( href , null ) ;
166177 }
@@ -169,5 +180,10 @@ private static Tuple<string, string> GetServiceHrefAndType(Dictionary<string, st
169180 return Tuple . Create < string , string > ( null , LandingPageTypeService ) ;
170181 }
171182 }
183+
184+ private static string GetKey ( string service , string category )
185+ {
186+ return service + "." + category ;
187+ }
172188 }
173189}
0 commit comments