Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
update generateservicemapping step as the mapping format updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ansyral committed Jun 15, 2017
1 parent 33e02b7 commit f7053fc
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

public class GenerateServiceMappingFile : IStep
{
private const string LandingPageTypeService = "Service";

public string StepName
{
get
Expand Down Expand Up @@ -46,6 +48,7 @@ select g
).ToDictionary(g => g.Key, g => g.ToList());

List<ServiceMappingItem> others = new List<ServiceMappingItem>();
Dictionary<string, string> serviceHrefMapping = new Dictionary<string, string>();
if (File.Exists(outputPath))
{
using (var reader = new StreamReader(outputPath))
Expand All @@ -61,6 +64,7 @@ select g
{
others.Add(other);
}
serviceHrefMapping = oldMapping[0].items.ToDictionary(i => i.name, i => i.href);
}

}
Expand All @@ -87,17 +91,20 @@ group v.Value by v.Key.Category into g0
landingPageType = "Root",
items = new ServiceMapping((from pair in services
let service = pair.Key
let hrefAndType = GetServiceHrefAndType(serviceHrefMapping, service)
select new ServiceMappingItem()
{
name = service,
href = "~/docs-ref-services/overview/azure/" + service + ".md",
href = hrefAndType.Item1,
landingPageType = hrefAndType.Item2,
uid = "landingpage.services." + service,
items = new ServiceMapping(from item in pair.Value
let category = item.Category
select new ServiceMappingItem()
{
name = item.Category,
uid = "landingpage.services." + service + "." + category,
landingPageType = "Service",
landingPageType = LandingPageTypeService,
children = item.Uids.ToList()
})
}).OrderBy(s => s.name))
Expand Down Expand Up @@ -145,8 +152,22 @@ private static void Merge(Dictionary<ServiceCategory, List<string>> a, Dictionar
{
a[pair.Key] = new List<string>();
}
// to-do: when product repo's mapping file is ready, should change the behavior to overwrite.
a[pair.Key].AddRange(pair.Value);
}
}

private static Tuple<string, string> GetServiceHrefAndType(Dictionary<string, string> mapping, string service)
{
string href;
if (mapping.TryGetValue(service, out href))
{
return Tuple.Create<string, string>(href, null);
}
else
{
return Tuple.Create<string, string>(null, LandingPageTypeService);
}
}
}
}

0 comments on commit f7053fc

Please sign in to comment.