예제 #1
0
 private void FillCore(PageViewModel model, IHostService host)
 {
     if (model.References == null || model.References.Count == 0)
     {
         return;
     }
     foreach (var r in model.References)
     {
         var m = host.LookupByUid(r.Uid).Find(x => x.Type == DocumentType.Article);
         if (m == null)
         {
             continue;
         }
         var page = (PageViewModel)m.Content;
         var item = page.Items.Find(x => x.Uid == r.Uid);
         if (item == null)
         {
             continue;
         }
         r.Additional["summary"] = item.Summary;
         r.Additional["type"] = item.Type;
         r.Additional["syntax"] = item.Syntax;
         r.Additional["platform"] = item.Platform;
     }
 }
 private IEnumerable<XRefSpec> GetXRefFromReference(PageViewModel vm)
 {
     if (vm.References == null)
     {
         yield break;
     }
     foreach (var reference in vm.References)
     {
         if (reference != null && reference.IsExternal != false)
         {
             var dict = YamlUtility.ConvertTo<Dictionary<string, object>>(reference);
             if (dict != null)
             {
                 var spec = new XRefSpec();
                 foreach (var pair in dict)
                 {
                     var s = pair.Value as string;
                     if (s != null)
                     {
                         spec[pair.Key] = s;
                     }
                 }
                 yield return spec;
             }
         }
     }
 }
예제 #3
0
        public static ApiBuildOutput FromModel(PageViewModel model)
        {
            if (model == null || model.Items == null || model.Items.Count == 0)
            {
                return null;
            }

            object displayLangs;
            if (model.Metadata.TryGetValue("_displayLangs", out displayLangs))
            {
                var langsObj = displayLangs as object[];
                if (langsObj != null)
                {
                    var langs = langsObj.Select(x => x?.ToString()).ToArray();
                    model.Items.ForEach(item => item.SupportedLanguages = IntersectLangs(item.SupportedLanguages, langs));
                }
                else
                {
                    Logger.LogWarning("Invalid displayLangs setting in docfx.json. Ignored.");
                }
            }

            var metadata = model.Metadata;
            var references = new Dictionary<string, ApiReferenceBuildOutput>();

            foreach (var item in model.References)
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item, model.Items[0].SupportedLanguages);
                }
            }

            // Add other items to reference, override the one in reference with same uid
            foreach (var item in model.Items.Skip(1))
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item);
                }
            }

            return FromModel(model.Items[0], references, metadata);
        }
예제 #4
0
 private static MergeItem CreateMergeItemCore(ItemViewModel majorItem, PageViewModel page)
 {
     return new MergeItem
     {
         MajorItem = majorItem,
         AssemblyNameList = new SortedSet<string>(majorItem.AssemblyNameList ?? Enumerable.Empty<string>()),
         Children = new SortedSet<string>(majorItem.Children ?? Enumerable.Empty<string>()),
         Platform = new SortedSet<string>(majorItem.Platform ?? Enumerable.Empty<string>()),
         MinorItems = page?.Items.Where(x => x.Uid != majorItem.Uid).ToDictionary(item => item.Uid, item => CreateMergeItemCore(item, null)),
         References = page?.References.ToDictionary(item => item.Uid),
         Metadata = page?.Metadata,
     };
 }
예제 #5
0
 private void ConvertToVMCore(PageViewModel vm, MergeItem mergeItem)
 {
     if (mergeItem.AssemblyNameList.Count > 0)
     {
         mergeItem.MajorItem.AssemblyNameList = mergeItem.AssemblyNameList.ToList();
     }
     if (mergeItem.Children.Count > 0)
     {
         mergeItem.MajorItem.Children = mergeItem.Children.ToList();
     }
     if (mergeItem.Platform.Count > 0)
     {
         mergeItem.MajorItem.Platform = mergeItem.Platform.ToList();
     }
     vm.Items.Add(mergeItem.MajorItem);
     if (mergeItem.MinorItems != null)
     {
         foreach (var item in mergeItem.MinorItems.Values)
         {
             ConvertToVMCore(vm, item);
         }
     }
 }
예제 #6
0
 private PageViewModel ConvertToVM(MergeItem mergeItem)
 {
     var vm = new PageViewModel
     {
         Items = new List<ItemViewModel>(),
         References = mergeItem.References?.Values.ToList(),
         Metadata = mergeItem.Metadata,
     };
     ConvertToVMCore(vm, mergeItem);
     return vm;
 }