Example #1
0
 public static bool TryResolveSimpleTypeString(string typeStr, ECMAStore store, out string uid)
 {
     if (!string.IsNullOrEmpty(typeStr))
     {
         if (store.TypesByFullName.TryGetValue(typeStr, out var t))
         {
             uid = t.Uid;
             return(true);
         }
         if (typeStr.Contains('<'))
         {
             bool simpleGeneric = false;
             var  result        = GenericPartTypeStrRegex.Replace(typeStr, match =>
             {
                 simpleGeneric = true;
                 return("`" + (match.Value.Count(c => c == ',') + 1));
             });
             if (simpleGeneric)
             {
                 uid = result;
                 return(true);
             }
         }
     }
     uid = typeStr;
     return(false);
 }
Example #2
0
        public static string BuildSeeAlsoList(Docs docs, ECMAStore store)
        {
            if ((docs.AltMemberCommentIds == null || docs.AltMemberCommentIds?.Count == 0) &&
                (docs.Related == null || docs.Related?.Count == 0))
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            if (docs.AltMemberCommentIds != null)
            {
                foreach (var altMemberId in docs.AltMemberCommentIds)
                {
                    var uid = altMemberId.ResolveCommentId(store)?.Uid ?? altMemberId.Substring(altMemberId.IndexOf(':') + 1);
                    uid = System.Web.HttpUtility.UrlEncode(uid);
                    sb.AppendLine($"- <xref:{uid}>");
                }
            }
            if (docs.Related != null)
            {
                foreach (var rTag in docs.Related)
                {
                    var uri = rTag.Uri.Contains(' ') ? rTag.Uri.Replace(" ", "%20") : rTag.Uri;
                    sb.AppendLine($"- [{rTag.OriginalText}]({uri})");
                }
            }

            return(sb.ToString());
        }
Example #3
0
        public static ReflectionItem ResolveCommentId(this string commentId, ECMAStore store)
        {
            if (string.IsNullOrEmpty(commentId))
            {
                return(null);
            }
            if (store.ItemsByDocId.TryGetValue(commentId, out var item))
            {
                return(item);
            }
            var(prefix, uid) = commentId.ParseCommentId();
            if (string.IsNullOrEmpty(prefix) || string.IsNullOrEmpty(uid))
            {
                return(null);
            }
            switch (prefix)
            {
            case "N":
                return(store.Namespaces.ContainsKey(uid) ? store.Namespaces[uid] : null);

            case "T":
                return(store.TypesByUid.ContainsKey(uid) ? store.TypesByUid[uid] : null);

            default:
                return(store.MembersByUid.ContainsKey(uid) ? store.MembersByUid[uid] : null);
            }
        }
Example #4
0
        public static void GenerateReport(ECMAStore store, string reportFilePath, string branch = null)
        {
            if (store.UWPMode)
            {
                _validator = new UWPDocValidator();
            }
            else
            {
                _validator = new DotnetDocValidator();
            }

            List <ReportItem> items = new List <ReportItem>();

            items.AddRange(store.Namespaces.Values.Where(ns => !string.IsNullOrEmpty(ns.Uid)).Select(ns => ValidateItem(ns, branch)));
            items.AddRange(store.TypesByUid.Values.Select(t => ValidateItem(t, branch)));
            items.AddRange(store.MembersByUid.Values.Select(m => ValidateItem(m, branch)));
            items.Sort(new ReportItemComparer());

            var report = new Report()
            {
                ReportItems = items,
                Branch      = branch
            };

            SaveToExcel(report, reportFilePath);
        }
Example #5
0
 public static string ToOuterTypeUid(this string typeStr)
 {
     if (!NeedParseByECMADesc(typeStr))
     {
         return(typeStr);
     }
     return(ECMAStore.GetOrAddTypeDescriptor(typeStr).ToOuterTypeUid());
 }
Example #6
0
 public static string ToSpecId(this string typeStr, List <string> knownTypeParamsOnType = null, List <string> knownTypeParamsOnMember = null)
 {
     if (!NeedParseByECMADesc(typeStr))
     {
         return(typeStr);
     }
     return(ECMAStore.GetOrAddTypeDescriptor(typeStr).ToSpecId(knownTypeParamsOnType, knownTypeParamsOnMember) ?? typeStr);
 }
Example #7
0
 public static string UidToTypeMDString(string uid, ECMAStore store)
 {
     if (store.TypesByUid.TryGetValue(uid, out var t))
     {
         return(EncodeXrefLink(t.Name, t.Uid));
     }
     if (store.MembersByUid.TryGetValue(uid, out var m))
     {
         return(EncodeXrefLink(m.Name, m.Uid));
     }
     return($"<xref href=\"{uid}\" data-throw-if-not-resolved=\"True\"/>");
 }
Example #8
0
        public static string ToDisplayName(this string typeStr)
        {
            if (string.IsNullOrEmpty(typeStr))
            {
                return(typeStr);
            }
            if (!typeStr.Contains('<'))
            {
                var parts = typeStr.Split('.');
                return(parts.Last());
            }

            return(ECMAStore.GetOrAddTypeDescriptor(typeStr).ToDisplayName());
        }
Example #9
0
        public static string TypeStringToTypeMDString(string typeStr, ECMAStore store)
        {
            if (store.TryGetTypeByFullName(typeStr, out var t))
            {
                return(EncodeXrefLink(t.Name, t.Uid));
            }

            var desc = ECMAStore.GetOrAddTypeDescriptor(typeStr);

            if (desc != null)
            {
                return(DescToTypeMDString(desc));
            }
            return(typeStr);
        }
Example #10
0
        public static TOCRootYamlModel Generate(ECMAStore store)
        {
            TOCRootYamlModel toc = new TOCRootYamlModel()
            {
                Items = new List <TOCNodeYamlModel>()
            };

            foreach (var ns in store.Namespaces.Values)
            {
                if (ns.Types?.Count > 0)
                {
                    toc.Items.Add(GenerateTocItemForNamespace(ns));
                }
            }
            return(toc);
        }
Example #11
0
        public static string DocIdToTypeMDString(string docId, ECMAStore store)
        {
            var item = docId.ResolveCommentId(store);

            if (item != null)
            {
                if (item is Member m)
                {
                    return(EncodeXrefLink(m.DisplayName, item.Uid));
                }
                else
                {
                    return(EncodeXrefLink(item.Name, item.Uid));
                }
            }
            var(_, uid) = docId.ParseCommentId();
            return(UidToTypeMDString(uid, store));
        }
Example #12
0
        public ECMAStore LoadFolder(string sourcePath, bool isUWPMode = false)
        {
            //if (!System.IO.Directory.Exists(sourcePath))
            //{
            //    OPSLogger.LogUserWarning(string.Format("Source folder does not exist: {0}", sourcePath));
            //    return null;
            //}

            var filterStore      = LoadFilters(sourcePath);
            var typeMappingStore = LoadTypeMap(sourcePath);
            var pkgInfoMapping   = LoadPackageInformationMapping(sourcePath);

            ConcurrentBag <Namespace> namespaces = new ConcurrentBag <Namespace>();
            ParallelOptions           opt        = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            //foreach(var nsFile in ListFiles(sourcePath, "ns-*.xml"))
            Parallel.ForEach(ListFiles(sourcePath, "ns-*.xml"), opt, nsFile =>
            {
                var ns = LoadNamespace(sourcePath, nsFile);
                if (ns == null)
                {
                    OPSLogger.LogUserError(LogCode.ECMA2Yaml_Namespace_LoadFailed, nsFile.AbsolutePath);
                }
                else if (ns.Types == null)
                {
                    OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_Namespace_NoTypes, nsFile.AbsolutePath);
                }
                else
                {
                    namespaces.Add(ns);
                    if (nsFile.IsVirtual)
                    {
                        FallbackFiles.Add(nsFile.AbsolutePath);
                    }
                }
            });

            if (namespaces.Count == 0)
            {
                return(null);
            }

            if (_errorFiles.Count > 0)
            {
                OPSLogger.LogUserError(LogCode.ECMA2Yaml_File_LoadFailed, null, _errorFiles.Count);
                return(null);
            }

            var frameworks = LoadFrameworks(sourcePath);

            if (frameworks == null || frameworks.DocIdToFrameworkDict.Count == 0)
            {
                OPSLogger.LogUserError(LogCode.ECMA2Yaml_Framework_NotFound, null, "any API, please check your FrameworkIndex folder");
                return(null);
            }

            var filteredNS = Filter(namespaces, filterStore, frameworks);
            var store      = new ECMAStore(filteredNS.OrderBy(ns => ns.Name).ToArray(), frameworks)
            {
                FilterStore      = filterStore,
                TypeMappingStore = isUWPMode ? typeMappingStore : null,
                PkgInfoMapping   = pkgInfoMapping,
                UWPMode          = isUWPMode
            };

            return(store);
        }
Example #13
0
 public SDPYamlConverter(ECMAStore store, bool withVersioning = false)
 {
     _store          = store;
     _withVersioning = withVersioning;
 }
Example #14
0
 public SDPYamlConverter(ECMAStore store)
 {
     _store = store;
 }
Example #15
0
        public static IDictionary <string, List <string> > Generate(
            ECMAStore store,
            string outputFolder,
            bool flatten)
        {
            WriteLine("Generating SDP Yaml models...");

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            var sdpConverter = new SDPYamlConverter(store);

            sdpConverter.Convert();

            WriteLine("Writing SDP Yaml files...");
            ConcurrentDictionary <string, List <string> > fileMapping = new ConcurrentDictionary <string, List <string> >();
            ParallelOptions po = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            Parallel.ForEach(store.Namespaces, po, ns =>
            {
                Dictionary <string, int> existingFileNames = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                var nsFolder = Path.Combine(outputFolder, ns.Key);
                if (!string.IsNullOrEmpty(ns.Key) && sdpConverter.NamespacePages.TryGetValue(ns.Key, out var nsPage))
                {
                    var nsFileName = Path.Combine(outputFolder, ns.Key + ".yml");
                    if (!string.IsNullOrEmpty(ns.Value.SourceFileLocalPath))
                    {
                        fileMapping.TryAdd(ns.Value.SourceFileLocalPath, new List <string> {
                            nsFileName
                        });
                    }
                    YamlUtility.Serialize(nsFileName, nsPage, nsPage.YamlMime);
                }

                if (!flatten && !Directory.Exists(nsFolder))
                {
                    Directory.CreateDirectory(nsFolder);
                }

                foreach (var t in ns.Value.Types)
                {
                    if (!string.IsNullOrEmpty(t.Uid) && sdpConverter.TypePages.TryGetValue(t.Uid, out var typePage))
                    {
                        var tFileName = Path.Combine(flatten ? outputFolder : nsFolder, t.Uid.Replace('`', '-') + ".yml");
                        var ymlFiles  = new List <string>()
                        {
                            tFileName
                        };
                        YamlUtility.Serialize(tFileName, typePage, typePage.YamlMime);

                        if (t.Members != null)
                        {
                            foreach (var m in t.Members)
                            {
                                if (!string.IsNullOrEmpty(m.Uid) && sdpConverter.OverloadPages.TryGetValue(m.Uid, out var mPage))
                                {
                                    var fileName = PathUtility.ToCleanUrlFileName(m.Uid);
                                    fileName     = GetUniqueFileNameWithSuffix(fileName, existingFileNames) + ".yml";
                                    var path     = Path.Combine(flatten ? outputFolder : nsFolder, fileName);
                                    ymlFiles.Add(path);
                                    YamlUtility.Serialize(path, mPage, mPage.YamlMime);
                                }
                            }

                            if (t.Overloads != null)
                            {
                                foreach (var ol in t.Overloads)
                                {
                                    if (!string.IsNullOrEmpty(ol.Uid) && sdpConverter.OverloadPages.TryGetValue(ol.Uid, out var mPage))
                                    {
                                        var fileName = PathUtility.ToCleanUrlFileName(GetNewFileName(t.Uid, ol));
                                        fileName     = GetUniqueFileNameWithSuffix(fileName, existingFileNames) + ".yml";
                                        var path     = Path.Combine(flatten ? outputFolder : nsFolder, fileName);
                                        ymlFiles.Add(path);
                                        YamlUtility.Serialize(path, mPage, mPage.YamlMime);
                                    }
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(t.SourceFileLocalPath))
                        {
                            fileMapping.TryAdd(t.SourceFileLocalPath, ymlFiles);
                        }
                    }
                }
            });

            WriteLine("Done writing SDP Yaml files.");
            return(fileMapping);
        }