public static (string, string) ParseCommentId(this string commentId) { var parts = commentId.Split(':'); if (parts?.Length != 2) { OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_CommentID_ParseFailed, null, commentId); return(null, null); } return(parts[0], parts[1]); }
static Dictionary <string, Dictionary <string, object> > LoadFile(string path) { var rval = new Dictionary <string, Dictionary <string, object> >(); var text = File.ReadAllText(path); var matches = YamlHeaderRegex.Matches(text); if (matches != null && matches.Count > 0) { foreach (Match match in matches) { using (StringReader reader = new StringReader(match.Groups[1].Value)) { Dictionary <string, object> result = null; try { result = YamlUtility.Deserialize <Dictionary <string, object> >(reader); } catch (Exception ex) { OPSLogger.LogUserError(LogCode.ECMA2Yaml_YamlHeader_ParseFailed_WithException, path, ex); } if (result == null) { OPSLogger.LogUserError(LogCode.ECMA2Yaml_YamlHeader_ParseFailed, path, match.Value); } else if (!result.ContainsKey("uid")) { OPSLogger.LogUserError(LogCode.ECMA2Yaml_YamlHeader_ParseFailed, path, match.Value); } else { var uid = result["uid"].ToString(); result.Remove("uid"); if (rval.ContainsKey(uid)) { OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_Uid_Duplicated, path, uid); } else { rval[uid] = result; } } } } } return(rval); }
private TypedContent GetTypedContent(XElement ele, string filePath) { var cref = ele.Attribute("cref").Value; // Bug 211134: Ci should throw warning if exception cref is not prefixed with type (T:) if (cref.IndexOf(':') <= 0) { OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_CrefTypePrefixMissing, filePath, cref, filePath); } return(new TypedContent { CommentId = cref, Description = NormalizeDocsElement(GetInnerXml(ele)), Uid = cref.Substring(cref.IndexOf(':') + 1).Replace('+', '.') }); }
private FrameworkIndex LoadFrameworks(string folder) { var frameworkFolder = Path.Combine(folder, "FrameworksIndex"); FrameworkIndex frameworkIndex = new FrameworkIndex() { DocIdToFrameworkDict = new Dictionary <string, List <string> >(), FrameworkAssemblies = new Dictionary <string, Dictionary <string, AssemblyInfo> >(), AllFrameworks = new HashSet <string>() }; foreach (var fxFile in ListFiles(frameworkFolder, "*.xml").OrderBy(f => Path.GetFileNameWithoutExtension(f.AbsolutePath))) { XDocument fxDoc = XDocument.Load(fxFile.AbsolutePath); var fxName = fxDoc.Root.Attribute("Name").Value; frameworkIndex.AllFrameworks.Add(fxName); foreach (var nsElement in fxDoc.Root.Elements("Namespace")) { var ns = nsElement.Attribute("Name").Value; frameworkIndex.DocIdToFrameworkDict.AddWithKey("N:" + ns, fxName); foreach (var tElement in nsElement.Elements("Type")) { var t = tElement.Attribute("Id").Value; frameworkIndex.DocIdToFrameworkDict.AddWithKey(t, fxName); foreach (var mElement in tElement.Elements("Member")) { var m = mElement.Attribute("Id").Value; frameworkIndex.DocIdToFrameworkDict.AddWithKey(m, fxName); } } } var assemblyNodes = fxDoc.Root.Element("Assemblies")?.Elements("Assembly")?.Select(ele => new AssemblyInfo() { Name = ele.Attribute("Name")?.Value, Version = ele.Attribute("Version")?.Value }).ToList(); if (assemblyNodes != null) { frameworkIndex.FrameworkAssemblies.Add(fxName, assemblyNodes.ToDictionary(a => a.Name, a => a)); } else { OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_Moniker_EmptyAssembly, null, fxFile.AbsolutePath); } } return(frameworkIndex); }
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); }
private Models.Type LoadType(FileItem typeFile) { string xmlContent = _fileAccessor.ReadAllText(typeFile.RelativePath); xmlContent = xmlContent.Replace("TextAntiAliasingQuality property.</summary>", "TextAntiAliasingQuality property.</summary>"); xmlContent = xmlContent.Replace("DefaultValue('�')</AttributeName>", "DefaultValue('\\0')</AttributeName>"); xmlContent = xmlContent.Replace("\0", "\\0"); XDocument tDoc = XDocument.Parse(xmlContent, LoadOptions.PreserveWhitespace); XElement tRoot = tDoc.Root; if (tRoot.Name.LocalName != "Type") { return(null); } Models.Type t = new Models.Type(); t.Name = tRoot.Attribute("Name").Value.Replace('+', '.'); t.FullName = tRoot.Attribute("FullName").Value.Replace('+', '.'); t.SourceFileLocalPath = typeFile.AbsolutePath; //TypeSignature t.Signatures = new VersionedSignatures(tRoot.Elements("TypeSignature")); t.Modifiers = t.Signatures.CombinedModifiers; t.DocId = t.Signatures.DocId; //AssemblyInfo t.AssemblyInfo = tRoot.Elements("AssemblyInfo")?.SelectMany(a => ParseAssemblyInfo(a)).ToList(); //TypeParameters var tpElement = tRoot.Element("TypeParameters"); if (tpElement != null) { t.TypeParameters = ParameterBase.LoadVersionedParameters <TypeParameter>(tpElement.Elements("TypeParameter")); } //Parameters var pElement = tRoot.Element("Parameters"); if (pElement != null) { t.Parameters = ParameterBase.LoadVersionedParameters <Parameter>(pElement.Elements("Parameter")); } var rvalElement = tRoot.Element("ReturnValue"); if (rvalElement != null) { t.ReturnValueType = MonikerizeReturnValue(rvalElement); } //BaseTypeName t.BaseTypes = LoadBaseType(tRoot.Element("Base")); //Interfaces var interfacesElement = tRoot.Element("Interfaces"); if (interfacesElement != null) { t.Interfaces = interfacesElement.Elements("Interface") .Select(i => new VersionedString(LoadFrameworkAlternate(i), i?.Element("InterfaceName")?.Value)) .ToList(); } //Attributes var attrs = tRoot.Element("Attributes"); if (attrs != null) { t.Attributes = attrs.Elements("Attribute").Select(a => LoadAttribute(a)).ToList(); } //TypeForwardingChain var forwardingChain = tRoot.Element("TypeForwardingChain"); if (forwardingChain != null) { var fwds = forwardingChain.Elements("TypeForwarding").Select(fwd => LoadTypeForwarding(fwd)).ToList(); t.TypeForwardingChain = new TypeForwardingChain(fwds); } //Members var membersElement = tRoot.Element("Members"); if (membersElement != null) { t.Members = membersElement.Elements("Member")?.Select(m => LoadMember(t, m)).ToList(); t.Members.Sort((m1, m2) => { if (m1.IsEII == m2.IsEII) { return(string.Compare(m1.Name, m2.Name)); } else { return(m1.IsEII ? 1 : -1); //non-EII first, EII later } }); if (t.Members != null) { foreach (var m in t.Members) { m.SourceFileLocalPath = typeFile.AbsolutePath; } } t.Overloads = membersElement.Elements("MemberGroup")?.Select(m => LoadMemberGroup(t, m)).ToList(); if (t.Overloads != null) { var distinctList = new List <Member>(); foreach (var og in t.Overloads.GroupBy(o => o.Name)) { if (og.Count() > 1) { OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_MemberGroup_Duplicated, typeFile.AbsolutePath, og.Key); } og.First().SourceFileLocalPath = typeFile.AbsolutePath; distinctList.Add(og.First()); } t.Overloads = distinctList; } } //Docs t.Docs = LoadDocs(tRoot.Element("Docs"), typeFile.AbsolutePath); //MemberType t.ItemType = InferTypeOfType(t); if (t.ItemType == ItemType.Enum && t.Members?.Count > 0) { foreach (var m in t.Members) { if (!string.IsNullOrEmpty(m.Docs.Remarks)) { OPSLogger.LogUserSuggestion(LogCode.ECMA2Yaml_Enum_NoRemarks, typeFile.AbsolutePath); } } } // Metadata LoadMetadata(t, tRoot); return(t); }