Esempio n. 1
0
 public bool IsMatchFor(ApiEntry apiEntry)
 {
     if (apiEntry == null)
     {
         return(false);
     }
     return(string.Equals(AssemblyName, apiEntry.AssemblyName, StringComparison.OrdinalIgnoreCase) && _regex.IsMatch(apiEntry.WhitelistKey));
 }
Esempio n. 2
0
        public bool IsWhitelisted(MemberInfo memberInfo)
        {
            if (!IsWhitelisted(memberInfo.DeclaringType.Assembly))
            {
                return(false);
            }
            var typeKey = ApiEntry.Create(memberInfo, null);

            return(_entries.Any(key => key.IsMatchFor(typeKey)));
        }
Esempio n. 3
0
        public bool IsWhitelisted(Type type)
        {
            var typeKey = ApiEntry.Create(type, null);

            if (typeKey == null)
            {
                return(false);
            }
            return(_entries.Any(key => key.IsMatchFor(typeKey)));
        }
Esempio n. 4
0
        public async Task Scan(string whitelistCacheFileName)
        {
            await Task.Run(() =>
            {
                var whitelist      = Whitelist.Load(whitelistCacheFileName);
                var spaceEngineers = new SpaceEngineers();
                var installPath    = Path.Combine(spaceEngineers.GetInstallPath(), "bin64");
                MDKUtilityFramework.Load(installPath);
                var dllFiles = Directory.EnumerateFiles(installPath, "*.dll", SearchOption.TopDirectoryOnly)
                               .ToList();

                foreach (var dllFile in dllFiles)
                {
                    Visit(whitelist, dllFile);
                }

                foreach (var assemblyGroup in _members.GroupBy(m => m.DeclaringType.Assembly))
                {
                    var assemblyPath = new Uri(assemblyGroup.Key.CodeBase).LocalPath;
                    var xmlFileName  = Path.ChangeExtension(assemblyPath, "xml");
                    XDocument documentation;
                    if (File.Exists(xmlFileName))
                    {
                        documentation = XDocument.Load(xmlFileName);
                    }
                    else
                    {
                        documentation = null;
                    }
                    foreach (var typeGroup in assemblyGroup.GroupBy(m => m.DeclaringType))
                    {
                        var typeEntry = ApiEntry.Create(typeGroup.Key, documentation);
                        _entries.Add(typeEntry);
                        foreach (var member in typeGroup)
                        {
                            var entry = ApiEntry.Create(member, documentation);
                            _entries.Add(entry);
                        }
                    }
                }

                foreach (var entry in _entries)
                {
                    entry.ResolveLinks(_entries);
                }
            });
        }
Esempio n. 5
0
        ApiEntry CreateEntry(MemberInfo memberInfo)
        {
            var entry = ApiEntry.Create(this, _whitelist, memberInfo);

            if (entry == null)
            {
                return(null);
            }

            string docFileName = null;

            if (memberInfo is Type type)
            {
                if (type.IsGenericType)
                {
                    type = type.GetGenericTypeDefinition();
                }
                docFileName = Path.ChangeExtension(new Uri(type.Assembly.CodeBase).LocalPath, "xml");
            }
            else
            {
                type = memberInfo.DeclaringType;
                if (type?.IsGenericType ?? false)
                {
                    type = type.GetGenericTypeDefinition();
                }
                var codeBase = type?.Assembly.CodeBase;
                if (codeBase != null)
                {
                    docFileName = Path.ChangeExtension(new Uri(codeBase).LocalPath, "xml");
                }
            }

            if (docFileName != null)
            {
                if (!_documentationCache.TryGetValue(docFileName, out var documentation))
                {
                    _documentationCache[docFileName] = documentation = File.Exists(docFileName) ? XDocument.Load(docFileName) : null;
                }
                var doc = documentation?.XPathSelectElement($"/doc/members/member[@name='{entry.XmlDocKey}']");
                entry.Documentation = XmlDoc.Generate(doc);
            }

            return(entry);
        }
 public bool IsAdditionalEntry(ApiEntry entry)
 {
     return(_entries.Contains(entry));
 }