async Task LoadExceptionList()
 {
     classes.Add("System.Exception");
     try {
         Microsoft.CodeAnalysis.Compilation compilation    = null;
         Microsoft.CodeAnalysis.ProjectId   dummyProjectId = null;
         if (IdeApp.ProjectOperations.CurrentSelectedProject != null)
         {
             compilation = await TypeSystemService.GetCompilationAsync(IdeApp.ProjectOperations.CurrentSelectedProject);
         }
         if (compilation == null)
         {
             //no need to unload this assembly context, it's not cached.
             dummyProjectId = Microsoft.CodeAnalysis.ProjectId.CreateNewId("GetExceptionsProject");
             compilation    = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create("GetExceptions")
                              .AddReferences(MetadataReferenceCache.LoadReference(dummyProjectId, System.Reflection.Assembly.GetAssembly(typeof(object)).Location))                                                        //corlib
                              .AddReferences(MetadataReferenceCache.LoadReference(dummyProjectId, System.Reflection.Assembly.GetAssembly(typeof(Uri)).Location));                                                          //System.dll
         }
         var exceptionClass = compilation.GetTypeByMetadataName("System.Exception");
         foreach (var t in compilation.GlobalNamespace.GetAllTypes().Where((arg) => arg.IsDerivedFromClass(exceptionClass)))
         {
             classes.Add(t.GetFullMetadataName());
         }
         if (dummyProjectId != null)
         {
             MetadataReferenceCache.RemoveReferences(dummyProjectId);
         }
     } catch (Exception e) {
         LoggingService.LogError("Failed to obtain exceptions list in breakpoint dialog.", e);
     }
     await Runtime.RunInMainThread(() => {
         entryExceptionType.SetCodeCompletionList(classes.ToList());
     });
 }
        void LoadExceptionList()
        {
            classes.Add("System.Exception");
            if (IdeApp.ProjectOperations.CurrentSelectedProject != null)
            {
                var compilation    = TypeSystemService.GetCompilationAsync(IdeApp.ProjectOperations.CurrentSelectedProject).Result;
                var exceptionClass = compilation.GetTypeByMetadataName("System.Exception");
                foreach (var t in compilation.GlobalNamespace.GetAllTypes().Where((arg) => arg.IsDerivedFromClass(exceptionClass)))
                {
                    classes.Add(t.GetFullMetadataName());
                }
            }
            else
            {
                //no need to unload this assembly context, it's not cached.
                var dummyProjectId = Microsoft.CodeAnalysis.ProjectId.CreateNewId("GetExceptionsProject");
                var compilation    = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create("GetExceptions")
                                     .AddReferences(MetadataReferenceCache.LoadReference(dummyProjectId, System.Reflection.Assembly.GetAssembly(typeof(object)).Location))                                               //corlib
                                     .AddReferences(MetadataReferenceCache.LoadReference(dummyProjectId, System.Reflection.Assembly.GetAssembly(typeof(Uri)).Location));                                                 //System.dll

                var exceptionClass = compilation.GetTypeByMetadataName("System.Exception");
                foreach (var t in compilation.GlobalNamespace.GetAllTypes().Where((arg) => arg.IsDerivedFromClass(exceptionClass)))
                {
                    classes.Add(t.GetFullMetadataName());
                }
                MetadataReferenceCache.RemoveReferences(dummyProjectId);
            }
            entryExceptionType.SetCodeCompletionList(classes.ToList());
        }
Ejemplo n.º 3
0
 private static IEnumerable <FeedPackage> ParsePage(XDocument doc, string id, MetadataReferenceCache metadataCache)
 {
     return(doc.Root.Name == _xnameEntry
                         ? new List <FeedPackage> {
         ParsePackage(id, doc.Root, metadataCache)
     }
                         : doc.Root.Elements(_xnameEntry).Select(x => ParsePackage(id, x, metadataCache)));
 }
Ejemplo n.º 4
0
        MetadataReference LoadMetadataReference(string path)
        {
            var projectId = Microsoft.CodeAnalysis.ProjectId.CreateNewId("WebFormsTypeContext");
            var reference = MetadataReferenceCache.LoadReference(projectId, path);

            MetadataReferenceCache.RemoveReferences(projectId);

            return(reference);
        }
        public void MetadataReferenceCache_CachesObjectCorrectly()
        {
            //// Arrange
            var objectToCache = new ObjectCacheTest();

            var cache = new MetadataReferenceCache();

            //// Act 1
            var stringCachedBefore = cache.GetString(ObjectCacheTest.TestStringCachedBefore);
            var stringCachedOnce   = ObjectCacheTest.TestStringCachedOnce;

            //// Assert 1

            // Assert that all equal objects that will be cached should be:
            // 1 - Equal.
            // 2 - Not the same reference.

            // Strings
            Assert.NotSame(objectToCache.StringCachedBefore, stringCachedBefore);
            Assert.Equal(objectToCache.StringCachedBefore, stringCachedBefore);

            Assert.NotSame(objectToCache.StringCachedDuring1, objectToCache.StringCachedDuring2);
            Assert.Equal(objectToCache.StringCachedDuring1, objectToCache.StringCachedDuring2);

            Assert.NotSame(objectToCache.StringCachedOnce, stringCachedOnce);
            Assert.Equal(objectToCache.StringCachedOnce, stringCachedOnce);

            // Versions
            Assert.NotSame(objectToCache.VersionCachedDuring1, objectToCache.VersionCachedDuring2);
            Assert.Equal(objectToCache.VersionCachedDuring1, objectToCache.VersionCachedDuring2);

            //// Act 2
            var cachedObject           = cache.GetObject(objectToCache);
            var cachedStringCachedOnce = cache.GetString(stringCachedOnce);

            //// Assert 2

            // Assert that all equal objects that were cached should be:
            // 1 - Equal to their original value.
            // 2 - The same reference.

            // Strings
            Assert.Same(objectToCache.StringCachedBefore, stringCachedBefore);
            Assert.Equal(objectToCache.StringCachedBefore, ObjectCacheTest.TestStringCachedBefore);

            Assert.Same(objectToCache.StringCachedDuring1, objectToCache.StringCachedDuring2);
            Assert.Equal(objectToCache.StringCachedDuring1, ObjectCacheTest.TestStringCachedDuring);

            Assert.Same(objectToCache.StringCachedOnce, cachedStringCachedOnce);
            Assert.Equal(objectToCache.StringCachedOnce, ObjectCacheTest.TestStringCachedOnce);

            // Check that uncached fields are untouched.
            Assert.Equal(objectToCache.DateTimeNeverCached, ObjectCacheTest.TestDateTimeNeverCached);
        }
        public void MetadataReferenceCache_ParsesVersion()
        {
            // Arrange
            var version = new NuGetVersion(3, 2, 1);

            var cache = new MetadataReferenceCache();

            // Act
            var cachedVersion = cache.GetVersion(version.ToString());

            // Assert
            Assert.Equal(version, cachedVersion);
        }
        public void AssertMetadataReferenceCache_CachesStringMethodCorrectly()
        {
            // Arrange
            var objectToCache = new ObjectCacheTest();
            var cache         = new MetadataReferenceCache();

            // Act
            var cachedObject = cache.GetObject(objectToCache);

            // Assert
            Assert.True(ReferenceEquals(cachedObject, objectToCache));
            Assert.Equal(objectToCache.StringCachedBefore, ObjectCacheTest.TestStringCachedBefore);
            Assert.Equal(cache.CachableMethodTypes.Count(), 1);
            Assert.Equal(cache.CachableMethodTypes.Single().Key.Name, "MetadataReferenceCache");
            Assert.Equal(cache.CachableMethodTypes.Single().Value.Name, "GetString");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Finds all entries on the page and parses them
        /// </summary>
        public static IEnumerable <V2FeedPackageInfo> ParsePage(XDocument doc)
        {
            MetadataReferenceCache metadataCache = new MetadataReferenceCache();

            if (doc.Root.Name == _xnameEntry)
            {
                return(new List <V2FeedPackageInfo> {
                    ParsePackage(doc.Root, metadataCache)
                });
            }
            else
            {
                return(doc.Root.Elements(_xnameEntry)
                       .Select(x => ParsePackage(x, metadataCache)));
            }
        }
        public void MetadataReferenceCache_ReturnsCachedVersion()
        {
            // Arrange
            var version1 = "3.2.1";
            var version2 = "3.2.1";

            var cache = new MetadataReferenceCache();

            // Act
            var cachedVersion1 = cache.GetVersion(version1);
            var cachedVersion2 = cache.GetVersion(version2);

            // Assert
            Assert.Equal(version1, version2);
            Assert.Same(cachedVersion1, cachedVersion2);
        }
        public void MetadataReferenceCache_ReturnsCachedParsedVersion()
        {
            // Arrange
            var version        = new NuGetVersion(3, 2, 1);
            var versionString1 = version.ToString();
            var versionString2 = version.ToString();

            var cache = new MetadataReferenceCache();

            // Act
            var cachedVersion1 = cache.GetVersion(versionString1);
            var cachedVersion2 = cache.GetVersion(versionString2);

            // Assert
            Assert.Equal(versionString1, versionString2);
            Assert.NotSame(versionString1, versionString2);
            Assert.Same(cachedVersion1, cachedVersion2);
        }
        public void MetadataReferenceCache_ReturnsNonNormalizedVersion()
        {
            // Arrange
            var version1 = "1.0";
            var version2 = "1.0.0";
            var version3 = "1.0.0.0";

            var cache = new MetadataReferenceCache();

            // Act
            var cachedVersion1 = cache.GetVersion(version1);
            var cachedVersion2 = cache.GetVersion(version2);
            var cachedVersion3 = cache.GetVersion(version3);

            // Assert
            Assert.Equal("1.0", cachedVersion1.ToString());
            Assert.Equal("1.0.0", cachedVersion2.ToString());
            Assert.Equal("1.0.0.0", cachedVersion3.ToString());
        }
        public void MetadataReferenceCache_ReturnsCachedString()
        {
            // Arrange
            var hello = "hello";
            var there = " there";

            // Using StringBuilder because if assigning to "hello there" directly results in a constant that is an equal reference.
            var string1 = new StringBuilder().Append(hello).Append(there).ToString();
            var string2 = new StringBuilder().Append(hello).Append(there).ToString();

            var cache = new MetadataReferenceCache();

            // Act
            var cachedString1 = cache.GetString(string1);
            var cachedString2 = cache.GetString(string2);

            // Assert
            Assert.Equal(string1, string2);
            Assert.NotSame(string1, string2);
            Assert.Same(cachedString1, cachedString2);
        }
 public ReferenceSet(MetadataReferenceCache cache)
 {
     _cache = cache;
 }
 public MetadataFileReferenceResolver(string baseDir)
 {
     _baseDir = baseDir;
     _cache   = new MetadataReferenceCache((path, properties) =>
                                           MetadataReference.CreateFromFile(path, properties));
 }
Ejemplo n.º 15
0
        private static V2FeedPackageInfo ParsePackage(XElement element, MetadataReferenceCache metadataCache)
        {
            var properties   = element.Element(_xnameProperties);
            var idElement    = properties.Element(_xnameId);
            var titleElement = element.Element(_xnameTitle);

            // If 'Id' element exist, use its value as accurate package Id
            // Otherwise, use the value of 'title' if it exist
            // Use the given Id as final fallback if all elements above don't exist
            string       identityId    = metadataCache.GetString(idElement?.Value ?? titleElement?.Value);
            string       versionString = properties.Element(_xnameVersion).Value;
            NuGetVersion version       = metadataCache.GetVersion(metadataCache.GetString(versionString));
            string       downloadUrl   = metadataCache.GetString(element.Element(_xnameContent).Attribute("src").Value);

            string title          = metadataCache.GetString(titleElement?.Value);
            string summary        = metadataCache.GetString(GetString(element, _xnameSummary));
            string description    = metadataCache.GetString(GetString(properties, _xnameDescription));
            string iconUrl        = metadataCache.GetString(GetString(properties, _xnameIconUrl));
            string licenseUrl     = metadataCache.GetString(GetString(properties, _xnameLicenseUrl));
            string projectUrl     = metadataCache.GetString(GetString(properties, _xnameProjectUrl));
            string reportAbuseUrl = metadataCache.GetString(GetString(properties, _xnameReportAbuseUrl));
            string tags           = metadataCache.GetString(GetString(properties, _xnameTags));
            string dependencies   = metadataCache.GetString(GetString(properties, _xnameDependencies));

            string downloadCount            = metadataCache.GetString(GetString(properties, _xnameDownloadCount));
            bool   requireLicenseAcceptance = StringComparer.OrdinalIgnoreCase.Equals(bool.TrueString, GetString(properties, _xnameRequireLicenseAcceptance));

            string packageHash          = metadataCache.GetString(GetString(properties, _xnamePackageHash));
            string packageHashAlgorithm = metadataCache.GetString(GetString(properties, _xnamePackageHashAlgorithm));

            NuGetVersion minClientVersion = null;

            var minClientVersionString = GetString(properties, _xnameMinClientVersion);

            if (!string.IsNullOrEmpty(minClientVersionString))
            {
                if (NuGetVersion.TryParse(minClientVersionString, out minClientVersion))
                {
                    minClientVersion = metadataCache.GetVersion(minClientVersionString);
                }
            }

            DateTimeOffset?created    = GetDate(properties, _xnameCreated);
            DateTimeOffset?lastEdited = GetDate(properties, _xnameLastEdited);
            DateTimeOffset?published  = GetDate(properties, _xnamePublished);

            IEnumerable <string> owners  = null;
            IEnumerable <string> authors = null;

            var authorNode = element.Element(_xnameAuthor);

            if (authorNode != null)
            {
                authors = authorNode.Elements(_xnameName).Select(e => metadataCache.GetString(e.Value));
            }

            return(new V2FeedPackageInfo(new PackageIdentity(identityId, version), title, summary, description, authors,
                                         owners, iconUrl, licenseUrl, projectUrl, reportAbuseUrl, tags, created, lastEdited, published,
                                         dependencies, requireLicenseAcceptance, downloadUrl, downloadCount, packageHash, packageHashAlgorithm,
                                         minClientVersion));
        }
Ejemplo n.º 16
0
    public async Task <bool> MoveNextAsync()
    {
        var metadataCache = new MetadataReferenceCache();

        if (_currentPage == null)
        {
            _currentPage = _isSearchAvailable
                ? await _feedParser.GetSearchPageAsync(_searchTerm, _filter, _skip, _take, _logger, _token)
                : await _feedParser.GetPackagesPageAsync(_searchTerm, _filter, _skip, _take, _logger, _token);


            var results = _allVersions?
                          _currentPage.Items.GroupBy(p => p.Id)
                          .Select(group => group.OrderByDescending(p => p.Version)).SelectMany(pg => pg)
                          .Select(
                package =>
                V2FeedUtilities.CreatePackageSearchResult(package, metadataCache, _filter,
                                                          (V2FeedParser)_feedParser, _logger, _token)).Where(p => _filter.IncludeDelisted || p.IsListed)
            :
                          _currentPage.Items.GroupBy(p => p.Id)
                          .Select(group => group.OrderByDescending(p => p.Version).First())
                          .Select(
                package =>
                V2FeedUtilities.CreatePackageSearchResult(package, metadataCache, _filter,
                                                          (V2FeedParser)_feedParser, _logger, _token)).Where(p => _filter.IncludeDelisted || p.IsListed);


            var enumerator = results.GetEnumerator();
            _currentEnumerator = enumerator;
            return(_currentEnumerator.MoveNext());
        }
        else
        {
            if (!_currentEnumerator.MoveNext())
            {
                if (_currentPage.Items.Count != _take) // Last page not filled completely, no more pages left
                {
                    return(false);
                }
                _skip       += _take;
                _currentPage = _isSearchAvailable
                                    ? await _feedParser.GetSearchPageAsync(_searchTerm, _filter, _skip, _take, _logger, _token)
                                    : await _feedParser.GetPackagesPageAsync(_searchTerm, _filter, _skip, _take, _logger, _token);

                var results = _allVersions ?
                              _currentPage.Items.GroupBy(p => p.Id)
                              .Select(group => group.OrderByDescending(p => p.Version)).SelectMany(pg => pg)
                              .Select(
                    package =>
                    V2FeedUtilities.CreatePackageSearchResult(package, metadataCache, _filter,
                                                              (V2FeedParser)_feedParser, _logger, _token)).Where(p => _filter.IncludeDelisted || p.IsListed)
                :
                              _currentPage.Items.GroupBy(p => p.Id)
                              .Select(group => group.OrderByDescending(p => p.Version).First())
                              .Select(
                    package =>
                    V2FeedUtilities.CreatePackageSearchResult(package, metadataCache, _filter,
                                                              (V2FeedParser)_feedParser, _logger, _token)).Where(p => _filter.IncludeDelisted || p.IsListed);

                var enumerator = results.GetEnumerator();
                _currentEnumerator = enumerator;
                return(_currentEnumerator.MoveNext());
            }
            else
            {
                return(true);
            }
        }
    }
Ejemplo n.º 17
0
        private static FeedPackage ParsePackage(string id, XElement element, MetadataReferenceCache metadataCache)
        {
            var properties               = element.Element(_xnameProperties);
            var idElement                = properties.Element(_xnameId);
            var titleElement             = element.Element(_xnameTitle);
            var identityId               = metadataCache.GetString(idElement?.Value ?? titleElement?.Value ?? id);
            var versionString            = properties.Element(_xnameVersion).Value;
            var downloadUrl              = metadataCache.GetString(element.Element(_xnameContent).Attribute("src").Value);
            var title                    = metadataCache.GetString(titleElement?.Value);
            var summary                  = metadataCache.GetString(GetString(element, _xnameSummary));
            var description              = metadataCache.GetString(GetString(properties, _xnameDescription));
            var iconUrl                  = metadataCache.GetString(GetString(properties, _xnameIconUrl));
            var licenseUrl               = metadataCache.GetString(GetString(properties, _xnameLicenseUrl));
            var projectUrl               = metadataCache.GetString(GetString(properties, _xnameProjectUrl));
            var reportAbuseUrl           = metadataCache.GetString(GetString(properties, _xnameReportAbuseUrl));
            var tags                     = metadataCache.GetString(GetString(properties, _xnameTags));
            var dependencies             = metadataCache.GetString(GetString(properties, _xnameDependencies));
            var downloadCount            = metadataCache.GetString(GetString(properties, _xnameDownloadCount));
            var requireLicenseAcceptance = StringComparer.OrdinalIgnoreCase.Equals(bool.TrueString, GetString(properties, _xnameRequireLicenseAcceptance));
            var packageHash              = metadataCache.GetString(GetString(properties, _xnamePackageHash));
            var packageHashAlgorithm     = metadataCache.GetString(GetString(properties, _xnamePackageHashAlgorithm));
            var copyright                = metadataCache.GetString(GetString(properties, _xnameCopyright));
            var galleryDetailsUrl        = metadataCache.GetString(GetString(properties, _xnameGalleryDetailsUrl));
            var releaseNotes             = metadataCache.GetString(GetString(properties, _xnameReleaseNotes));
            var minClientVersionString   = GetString(properties, _xnameMinClientVersion);
            var created                  = GetDate(properties, _xnameCreated);
            var published                = GetDate(properties, _xnamePublished);
            var lastUpdated              = GetDate(properties, _xnameLastUpdated);
            var lastEdited               = GetDate(properties, _xnameLastEdited);
            var isAbsoluteLatestVersion  = StringComparer.OrdinalIgnoreCase.Equals(bool.TrueString, GetString(properties, _xnameIsAbsoluteLatestVersion));
            var isLatestVersion          = StringComparer.OrdinalIgnoreCase.Equals(bool.TrueString, GetString(properties, _xnameIsLatestVersion));
            var isPrerelease             = StringComparer.OrdinalIgnoreCase.Equals(bool.TrueString, GetString(properties, _xnameIsPrelease));
            var language                 = metadataCache.GetString(GetString(properties, _xnameLanguage));
            var licenseNames             = metadataCache.GetString(GetString(properties, _xnameLicenseNames));
            var licenseReportUrl         = metadataCache.GetString(GetString(properties, _xnameLicenseReportUrl));
            var packageUrl               = metadataCache.GetString(GetString(properties, _xnamePackageUrl));
            var packageSize              = GetLong(properties, _xnamePackageSize);
            var versionDownloadCount     = GetInt(properties, _xnameVersionDownloadCount);

            string authors    = null;
            var    authorNode = element.Element(_xnameAuthor);

            if (authorNode != null)
            {
                authors = string.Join(" ", authorNode.Elements(_xnameName).Select(e => metadataCache.GetString(e.Value)));
            }

            return(new FeedPackage
            {
                Authors = authors,
                Copyright = copyright,
                Created = created,
                Dependencies = dependencies,
                Description = description,
                DownloadCount = int.TryParse(downloadCount, out int d) ? d : 0,
                DownloadUrl = downloadUrl,
                GalleryDetailsUrl = galleryDetailsUrl,
                IconUrl = iconUrl,
                Id = identityId,
                IsAbsoluteLatestVersion = isAbsoluteLatestVersion,
                IsLatestVersion = isLatestVersion,
                IsPreRelease = isPrerelease,
                Language = language,
                LastUpdated = lastUpdated,
                LastEdited = lastEdited,
                LicenseNames = licenseNames,
                LicenseReportUrl = licenseReportUrl,
                LicenseUrl = licenseUrl,
                MinClientVersion = minClientVersionString,
                PackageHash = packageHash,
                PackageHashAlgorithm = packageHashAlgorithm,
                ProjectUrl = projectUrl,
                PackageSize = packageSize,
                PackageUrl = packageUrl,
                Published = published,
                ReleaseNotes = releaseNotes,
                ReportAbuseUrl = reportAbuseUrl,
                RequireLicenseAcceptance = requireLicenseAcceptance,
                Summary = summary,
                Tags = tags,
                Title = title,
                Version = versionString,
                VersionDownloadCount = versionDownloadCount
            });