示例#1
0
        private async Task <bool?> IsPackageIdenticalOnFeedAsync(
            string item,
            PackageIndex packageIndex,
            ISleetFileSystem source,
            FlatContainer flatContainer,
            SleetLogger log)
        {
            using (var package = new PackageArchiveReader(item))
            {
                var id = await package.GetIdentityAsync(CancellationToken);

                if (await packageIndex.Exists(id))
                {
                    using (Stream remoteStream = await source
                                                 .Get(flatContainer.GetNupkgPath(id))
                                                 .GetStream(log, CancellationToken))
                        using (var remote = new MemoryStream())
                        {
                            await remoteStream.CopyToAsync(remote);

                            byte[] existingBytes = remote.ToArray();
                            byte[] localBytes    = File.ReadAllBytes(item);

                            return(existingBytes.SequenceEqual(localBytes));
                        }
                }
                return(null);
            }
        }
示例#2
0
        public async Task Symbols_ValidationVerifyExtraSymbolsPackageInIndexCausesFailure()
        {
            using (var testContext = new SleetTestContext())
            {
                var context = testContext.SleetContext;
                context.SourceSettings.SymbolsEnabled = true;
                var service = new Symbols(context);

                // Corrupt feed
                var index = new PackageIndex(context);

                var pkgA = new TestNupkg("a", "1.0.0");
                pkgA.Files.Clear();
                pkgA.Nuspec.IsSymbolPackage = true;
                pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes());
                var pkgAZip   = pkgA.Save(testContext.Packages);
                var pkgAInput = testContext.GetPackageInput(pkgAZip);

                await index.AddSymbolsPackageAsync(pkgAInput);

                // Validate
                var messages = await service.ValidateAsync();

                var hasErrors = messages.Any(e => e.Level == LogLevel.Error);

                hasErrors.Should().BeTrue();
            }
        }
示例#3
0
        public async Task Symbols_AddSymbolsPackageWithNoValidSymbolsVerifyFeed()
        {
            using (var testContext = new SleetTestContext())
            {
                var context = testContext.SleetContext;
                context.SourceSettings.SymbolsEnabled = true;
                var symbols       = new Symbols(context);
                var packageIndex  = new PackageIndex(context);
                var catalog       = new Catalog(context);
                var autoComplete  = new AutoComplete(context);
                var flatContainer = new FlatContainer(context);
                var registrations = new Registrations(context);
                var search        = new Search(context);

                // Create package
                var pkgA = new TestNupkg("a", "1.0.0");
                pkgA.Nuspec.IsSymbolPackage = true;
                var zip      = pkgA.Save(testContext.Packages);
                var pkgInput = testContext.GetPackageInput(zip);

                // Init
                var success = await InitCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    enableCatalog : true,
                    enableSymbols : true,
                    log : testContext.SleetContext.Log,
                    token : CancellationToken.None);

                // Push
                success &= await PushCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    new List <string>() { zip.FullName },
                    force : false,
                    skipExisting : false,
                    log : testContext.SleetContext.Log);

                // Validate
                success &= await ValidateCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    testContext.SleetContext.Log);

                success.Should().BeTrue();

                // The nupkg should exist, but there should not be any assets added.
                (await symbols.GetSymbolsPackagesAsync()).Should().BeEmpty();
                (await packageIndex.GetSymbolsPackagesAsync()).Should().NotBeEmpty();

                // Verify nupkg exists
                var nupkgPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "a.1.0.0.symbols.nupkg");
                File.Exists(nupkgPath).Should().BeTrue();

                // Verify package details
                var detailsPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "package.json");
                File.Exists(detailsPath).Should().BeTrue();
            }
        }
示例#4
0
        public async Task InitializeAsync()
        {
            await Workflow.RSessions.TrySwitchBrokerAsync(GetType().Name);

            await PackageIndex.BuildIndexAsync();

            await FunctionIndex.BuildIndexAsync();
        }
示例#5
0
        public async Task AddRemove_AddAndDeletePackagesAsync()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage1 = new TestNupkg("packageA", "1.0.0");
                        var testPackage2 = new TestNupkg("packageA", "2.0.0");
                        var testPackage3 = new TestNupkg("packageB", "2.0.0");

                        var zipFile1 = testPackage1.Save(packagesFolder.Root);
                        var zipFile2 = testPackage2.Save(packagesFolder.Root);
                        var zipFile3 = testPackage3.Save(packagesFolder.Root);

                        var toDelete = new List <PackageIdentity>()
                        {
                            new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), new PackageIdentity("packageB", NuGetVersion.Parse("2.0.0"))
                        };

                        // Act
                        // run commands
                        await InitCommand.InitAsync(context);

                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log);

                        await DeleteCommand.DeletePackagesAsync(context.LocalSettings, context.Source, toDelete, string.Empty, false, context.Log);

                        var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                        // read outputs
                        var packageIndex  = new PackageIndex(context);
                        var indexPackages = await packageIndex.GetPackagesAsync();

                        // Assert
                        Assert.True(validateOutput);
                        Assert.Equal(1, indexPackages.Count);
                        Assert.Equal("packageA", indexPackages.First().Id);
                        Assert.Equal("2.0.0", indexPackages.First().Version.ToNormalizedString());
                    }
        }
        public void IndexCacheConsidersModifiedTime()
        {
            string packageIndexFile = $"{nameof(IndexCacheConsidersModifiedTime)}.json";

            PackageIndex packageIndex = new PackageIndex();

            packageIndex.Packages.Add("MyPackage", new PackageInfo());

            packageIndex.Packages.Should().HaveCount(1);
            packageIndex.Packages.Should().ContainKey("MyPackage");

            packageIndex.Save(packageIndexFile);

            DateTime originalModifiedTime = File.GetLastWriteTimeUtc(packageIndexFile);

            string[] packageIndexFiles = new[] { packageIndexFile };

            packageIndex = PackageIndex.Load(packageIndexFiles);
            packageIndex.Packages.Should().HaveCount(1);
            packageIndex.Packages.Should().ContainKey("MyPackage");

            packageIndex = new PackageIndex();
            packageIndex.Packages.Add("MyPackage", new PackageInfo());
            packageIndex.Packages.Add("MyPackage2", new PackageInfo());

            packageIndex.Packages.Should().HaveCount(2);
            packageIndex.Packages.Should().ContainKey("MyPackage");
            packageIndex.Packages.Should().ContainKey("MyPackage2");

            packageIndex.Save(packageIndexFile);

            // force the same modified time, but should be different size
            File.SetLastWriteTimeUtc(packageIndexFile, originalModifiedTime);
            packageIndex = PackageIndex.Load(packageIndexFiles);

            packageIndex.Packages.Should().HaveCount(2);
            packageIndex.Packages.Should().ContainKey("MyPackage");
            packageIndex.Packages.Should().ContainKey("MyPackage2");

            // now change the content so that it has the same size, but different modified time
            long previousLength = new FileInfo(packageIndexFile).Length;

            packageIndex.Packages.Remove("MyPackage2");
            packageIndex.Packages.Add("MyPackage3", new PackageInfo());
            packageIndex.Save(packageIndexFile);
            var newFileInfo = new FileInfo(packageIndexFile);

            newFileInfo.Length.Should().Be(previousLength);

            // ensure we have a different modified time
            File.SetLastWriteTimeUtc(packageIndexFile, new DateTime(originalModifiedTime.Ticks + 100));
            packageIndex = PackageIndex.Load(packageIndexFiles);

            packageIndex.Packages.Should().HaveCount(2);
            packageIndex.Packages.Should().ContainKey("MyPackage");
            packageIndex.Packages.Should().ContainKey("MyPackage3");
        }
示例#7
0
        public void PackageDescriptionTest()
        {
            RToolsSettings.Current = new TestRToolsSettings();

            IEnumerable <IPackageInfo> basePackages = PackageIndex.BasePackages;

            IPackageInfo pi = PackageIndex.GetPackageByName("base");

            pi.Description.Should().Be("Base R functions.");
        }
示例#8
0
        public async Task BuildPackageIndexTest()
        {
            string[] packageNames =
            {
                "base",
                "boot",
                "class",
                "cluster",
                "codetools",
                "compiler",
                "datasets",
                "foreign",
                "graphics",
                "grDevices",
                "grid",
                "KernSmooth",
                "lattice",
                "MASS",
                "Matrix",
                "methods",
                "mgcv",
                "nlme",
                "nnet",
                "parallel",
                "rpart",
                "spatial",
                "splines",
                "stats",
                "stats4",
                "survival",
                "tcltk",
                "tools",
                "translations",
                "utils",
            };

            IPackageIndex packageIndex;

            using (var host = new IntelliSenseRSession(_coreShell, _workflowProvider)) {
                await host.StartSessionAsync();

                var functionIndex = new FunctionIndex(_coreShell, null, host);
                packageIndex = new PackageIndex(_workflowProvider, _coreShell, host, functionIndex);
                await packageIndex.BuildIndexAsync();
            }

            foreach (var name in packageNames)
            {
                IPackageInfo pi = await packageIndex.GetPackageInfoAsync(name);

                pi.Should().NotBeNull();
                pi.Name.Should().Be(name);
            }
        }
示例#9
0
        public void BuildPackageIndexTest()
        {
            IEnumerable <IPackageInfo> basePackages = PackageIndex.BasePackages.AsList();

            string[] packageNames =
            {
                "base",
                "boot",
                "class",
                "cluster",
                "codetools",
                "compiler",
                "datasets",
                "foreign",
                "graphics",
                "grDevices",
                "grid",
                "KernSmooth",
                "lattice",
                "MASS",
                "Matrix",
                "methods",
                "mgcv",
                "nlme",
                "nnet",
                "parallel",
                "rpart",
                "spatial",
                "splines",
                "stats",
                "stats4",
                "survival",
                "tcltk",
                "tools",
                "translations",
                "utils",
            };

            string installPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
                @"R\R-3.2.2\library");

            foreach (var name in packageNames)
            {
                IPackageInfo info = basePackages.FirstOrDefault(x => x.Name == name);
                info.Should().NotBeNull();

                IPackageInfo pi1 = PackageIndex.GetPackageByName(info.Name);
                pi1.Should().NotBeNull();

                pi1.Name.Should().Be(info.Name);
            }
        }
示例#10
0
        /// <summary>
        /// Retrieves name of the package in 'package::' statement
        /// so intellisense can show list of functions available
        /// in the specific package.
        /// </summary>
        private IEnumerable <IPackageInfo> GetSpecificPackage(RCompletionContext context)
        {
            List <IPackageInfo> packages = new List <IPackageInfo>();
            ITextSnapshot       snapshot = context.TextBuffer.CurrentSnapshot;
            int colons = 0;

            for (int i = context.Position - 1; i >= 0; i--, colons++)
            {
                char ch = snapshot[i];
                if (ch != ':')
                {
                    break;
                }
            }

            if (colons > 1 && colons < 4)
            {
                string packageName = string.Empty;
                int    start       = 0;
                int    end         = context.Position - colons;

                for (int i = end - 1; i >= 0; i--)
                {
                    char ch = snapshot[i];
                    if (char.IsWhiteSpace(ch))
                    {
                        start = i + 1;
                        break;
                    }
                }

                if (start < end)
                {
                    packageName = snapshot.GetText(Span.FromBounds(start, end));
                    if (packageName.Length > 0)
                    {
                        if (colons == 3)
                        {
                            context.InternalFunctions = true;
                        }

                        IPackageInfo package = PackageIndex.GetPackageByName(packageName);
                        if (package != null)
                        {
                            packages.Add(package);
                        }
                    }
                }
            }

            return(packages);
        }
示例#11
0
        public CreateTrimDependencyGroupsTests(ITestOutputHelper output)
        {
            _log    = new Log(output);
            _engine = new TestBuildEngine(_log);


            var          packageIndexPath = $"packageIndex.{Guid.NewGuid()}.json";
            PackageIndex index            = new PackageIndex();

            index.MergeFrameworkLists(FrameworkListsPath);
            index.Save(packageIndexPath);
            packageIndexes = new[] { new TaskItem(packageIndexPath) };
        }
示例#12
0
        public async Task PackageDescriptionTest()
        {
            PackageIndex packageIndex;

            using (var host = new IntelliSenseRSession(_coreShell, _workflowProvider)) {
                await host.StartSessionAsync();

                var functionIndex = new FunctionIndex(_coreShell, null, host);
                packageIndex = new PackageIndex(_workflowProvider, _coreShell, host, functionIndex);
                await packageIndex.BuildIndexAsync();
            }
            IPackageInfo pi = await packageIndex.GetPackageInfoAsync("base");

            pi.Description.Should().Be("Base R functions.");
        }
示例#13
0
        public async Task CacheTest(bool cached)
        {
            if (!cached)
            {
                PackageIndex.ClearCache();
            }

            var content = @"x <- as.matrix(x)";
            var session = await TriggerSessionAsync(content, 13);

            var parametersInfo = session.Ast.GetSignatureInfoFromBuffer(session.EditorBuffer.CurrentSnapshot, 10);

            session.ApplicableSpan.Should().NotBeNull();
            session.QuickInfoContent.Should().ContainSingle()
            .Which.ToString().Should().StartWith("as.matrix(x, ...)");
        }
示例#14
0
        public async Task PackageDescriptionTest()
        {
            RToolsSettings.Current = new TestRToolsSettings();
            PackageIndex packageIndex;

            using (var host = new IntelliSenseRSession(_shell, _sessionProvider, _workflowProvider)) {
                await host.CreateSessionAsync();

                var functionIndex = new FunctionIndex(_shell, null, host);
                packageIndex = new PackageIndex(_shell, host, functionIndex);
                await packageIndex.BuildIndexAsync();
            }
            IPackageInfo pi = await packageIndex.GetPackageInfoAsync("base");

            pi.Description.Should().Be("Base R functions.");
        }
示例#15
0
        public async Task PushCommand_GivenAEmptyFolderVerifyAutoInit()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var root = Path.Combine(target.Root, "a/b/feed");
                        Directory.CreateDirectory(root);

                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage     = new TestNupkg("packageA", "1.0.0");
                        var packageIdentity = new PackageIdentity(testPackage.Nuspec.Id, NuGetVersion.Parse(testPackage.Nuspec.Version));

                        var zipFile = testPackage.Save(packagesFolder.Root);

                        // Act
                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                        var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                        // read outputs
                        var packageIndex  = new PackageIndex(context);
                        var indexPackages = await packageIndex.GetPackagesAsync();

                        // Assert
                        Assert.Equal(1, indexPackages.Count);
                    }
        }
示例#16
0
        public async Task Symbols_AddSymbolsPackageWithSymbolsOffVerifySkipped()
        {
            using (var testContext = new SleetTestContext())
            {
                var context = testContext.SleetContext;
                context.SourceSettings.SymbolsEnabled = true;

                // Create package
                var pkgA = new TestNupkg("a", "1.0.0");
                pkgA.Files.Clear();
                pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes());
                pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes());
                pkgA.Nuspec.IsSymbolPackage = true;
                var zip      = pkgA.Save(testContext.Packages);
                var pkgInput = testContext.GetPackageInput(zip);

                // Init
                var success = await InitCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    enableCatalog : true,
                    enableSymbols : false,
                    log : testContext.SleetContext.Log,
                    token : CancellationToken.None);

                // Push
                success &= await PushCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    new List <string>() { zip.FullName },
                    force : false,
                    skipExisting : false,
                    log : testContext.SleetContext.Log);

                success.Should().BeTrue();

                var packageIndex = new PackageIndex(context);
                (await packageIndex.IsEmpty()).Should().BeTrue();

                var testLogger = (TestLogger)testContext.SleetContext.Log;
                testLogger.GetMessages().Should().Contain("to push symbols packages enable the symbols server on this feed");
            }
        }
示例#17
0
        public async Task <ISet <PackageIdentity> > GetPackageIdentitiesAsync()
        {
            var context = new SleetContext
            {
                LocalSettings = GetSettings(),
                Log           = new SleetLogger(Log),
                Source        = GetAzureFileSystem(),
                Token         = CancellationToken
            };

            context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                context.Source,
                context.Log,
                context.Token);

            var packageIndex = new PackageIndex(context);

            return(await packageIndex.GetPackagesAsync());
        }
示例#18
0
        public async Task InstallPackageTest()
        {
            await Workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo(), null, 50000);

            var completionSets = new List <CompletionSet>();

            for (int i = 0; i < 2; i++)
            {
                try {
                    await Workflow.Packages.UninstallPackageAsync("abc", null);

                    EventsPump.DoEvents(1000);
                } catch (RException) { }

                await PackageIndex.BuildIndexAsync();

                completionSets.Clear();
                RCompletionTestUtilities.GetCompletions(Services, "abc::", 5, completionSets);

                completionSets.Should().ContainSingle();
                // Try again one more time
                if (completionSets[0].Completions.Count == 0)
                {
                    break;
                }
            }
            completionSets[0].Completions.Should().BeEmpty();

            try {
                await Workflow.RSession.ExecuteAsync("install.packages('abc')", REvaluationKind.Mutating);

                EventsPump.DoEvents(1000);
            } catch (RException) { }

            await PackageIndex.BuildIndexAsync();

            completionSets.Clear();
            RCompletionTestUtilities.GetCompletions(Services, "abc::", 5, completionSets);

            completionSets.Should().ContainSingle();
            completionSets[0].Completions.Should().NotBeEmpty();
        }
示例#19
0
        public async Task <IEditorScript> StartScript(ICoreShell coreShell, string text, string filename, string contentType, IRSessionProvider sessionProvider)
        {
            var coreEditor = await InUI(() => new CoreEditor(coreShell, text, filename, contentType));

            var containerDisposable = await AddToHost(coreEditor.Control);

            if (sessionProvider != null)
            {
                IntelliSenseRSession.HostStartTimeout = 10000;
                HostScript = new RHostScript(sessionProvider);

                PackageIndex = coreShell.GetService <IPackageIndex>();
                await PackageIndex.BuildIndexAsync();

                FunctionIndex = coreShell.GetService <IFunctionIndex>();
                await FunctionIndex.BuildIndexAsync();
            }

            return(new EditorScript(coreShell, coreEditor, containerDisposable));
        }
示例#20
0
        public async Task <ISet <PackageIdentity> > GetPackageIdentitiesAsync()
        {
            using (var fileCache = CreateFileCache())
            {
                var context = new SleetContext
                {
                    LocalSettings = GetSettings(),
                    Log           = new SleetLogger(Log, NuGet.Common.LogLevel.Verbose),
                    Source        = GetAzureFileSystem(fileCache),
                    Token         = CancellationToken
                };
                context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                    context.Source,
                    context.Log,
                    context.Token);

                var packageIndex = new PackageIndex(context);

                return(await packageIndex.GetPackagesAsync());
            }
        }
示例#21
0
        /// <summary>
        /// Retrieves list of packages declared in the file via 'library' statements
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private IEnumerable <IPackageInfo> GetAllFilePackages(RCompletionContext context)
        {
            List <IPackageInfo> packages = new List <IPackageInfo>();

            LoadedPackagesProvider?.Initialize();

            IEnumerable <string> loadedPackages   = LoadedPackagesProvider?.GetPackageNames() ?? Enumerable.Empty <string>();
            IEnumerable <string> filePackageNames = context.AstRoot.GetFilePackageNames();
            IEnumerable <string> allPackageNames  = Enumerable.Union(_preloadPackages, Enumerable.Union(filePackageNames, loadedPackages));

            foreach (string packageName in allPackageNames)
            {
                IPackageInfo p = PackageIndex.GetPackageByName(packageName);
                // May be null if user mistyped package name in the library()
                // statement or package is not installed.
                if (p != null)
                {
                    packages.Add(p);
                }
            }

            return(packages);
        }
示例#22
0
        public async Task InstallPackageTest()
        {
            using (var script = new RHostScript(Workflow.RSessions)) {
                var completionSets = new List <CompletionSet>();
                for (int i = 0; i < 2; i++)
                {
                    try {
                        await script.Session.ExecuteAsync("remove.packages('abc')", REvaluationKind.Mutating);
                    } catch (RException) { }

                    await PackageIndex.BuildIndexAsync();

                    completionSets.Clear();
                    GetCompletions("abc::", 5, completionSets);

                    completionSets.Should().ContainSingle();
                    // Try again one more time
                    if (completionSets[0].Completions.Count == 0)
                    {
                        break;
                    }
                }
                completionSets[0].Completions.Should().BeEmpty();

                try {
                    await script.Session.ExecuteAsync("install.packages('abc')", REvaluationKind.Mutating);
                } catch (RException) { }

                await PackageIndex.BuildIndexAsync();

                completionSets.Clear();
                GetCompletions("abc::", 5, completionSets);

                completionSets.Should().ContainSingle();
                completionSets[0].Completions.Should().NotBeEmpty();
            }
        }
示例#23
0
        public async Task QuickInfoSourceTest01(bool cached)
        {
            if (!cached)
            {
                PackageIndex.ClearCache();
            }
            string  content = @"x <- as.matrix(x)";
            AstRoot ast     = RParser.Parse(content);

            int                  caretPosition    = 15; // in arguments
            ITextBuffer          textBuffer       = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            QuickInfoSource      quickInfoSource  = new QuickInfoSource(textBuffer, _editorShell);
            QuickInfoSessionMock quickInfoSession = new QuickInfoSessionMock(textBuffer, caretPosition);
            List <object>        quickInfoContent = new List <object>();

            quickInfoSession.TriggerPoint = new SnapshotPoint(textBuffer.CurrentSnapshot, caretPosition);
            var applicableSpan = await quickInfoSource.AugmentQuickInfoSessionAsync(ast, caretPosition, quickInfoSession, quickInfoContent);

            ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, textBuffer.CurrentSnapshot, 10);

            applicableSpan.Should().NotBeNull();
            quickInfoContent.Should().ContainSingle()
            .Which.ToString().Should().StartWith("as.matrix(x, ..., data, nrow, ncol, byrow, dimnames, rownames.force)");
        }
示例#24
0
        public override void SaveAs(Stream s)
        {
            BinaryWriter w = new BinaryWriter(s);
            w.Write(header);

            List<uint> lT = new List<uint>();
            List<uint> lG = new List<uint>();
            List<uint> lIh = new List<uint>();
            this.Index.ForEach(x =>
            {
                if (!lT.Contains(x.ResourceType)) lT.Add(x.ResourceType);
                if (!lG.Contains(x.ResourceGroup)) lG.Add(x.ResourceGroup);
                if (!lIh.Contains((uint)(x.Instance >> 32))) lIh.Add((uint)(x.Instance >> 32));
            });

            uint indexType = (uint)(lIh.Count <= 1 ? 0x04 : 0x00) | (uint)(lG.Count <= 1 ? 0x02 : 0x00) | (uint)(lT.Count <= 1 ? 0x01 : 0x00);


            PackageIndex newIndex = new PackageIndex(indexType);
            foreach (IResourceIndexEntry ie in this.Index)
            {
                if (ie.IsDeleted) continue;

                ResourceIndexEntry newIE = (ie as ResourceIndexEntry).Clone();
                ((List<IResourceIndexEntry>)newIndex).Add(newIE);
                byte[] value = packedChunk(ie as ResourceIndexEntry);

                newIE.Chunkoffset = (uint)s.Position;
                w.Write(value);
                w.Flush();

                if (value.Length < newIE.Memsize)
                {
                    // Move to TS4
                    //newIE.Compressed = 0xffff;
                    newIE.Compressed = 0x5A42;
                    newIE.Filesize = (uint)value.Length;
                }
                else
                {
                    newIE.Compressed = 0x0000;
                    newIE.Filesize = newIE.Memsize;
                }
            }
            long indexpos = s.Position;
            newIndex.Save(w);
            setIndexcount(w, newIndex.Count);
            setIndexsize(w, newIndex.Size);
            setIndexposition(w, (int)indexpos);
            setUnused4(w, unused4);
            s.Flush();
        }
示例#25
0
        private async Task <bool> PushAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            LocalSettings   settings   = GetSettings();
            AzureFileSystem fileSystem = GetAzureFileSystem();
            SleetLogger     log        = new SleetLogger(Log);

            var packagesToPush = items.ToList();

            if (!options.AllowOverwrite && options.PassIfExistingItemIdentical)
            {
                var context = new SleetContext
                {
                    LocalSettings = settings,
                    Log           = log,
                    Source        = fileSystem,
                    Token         = CancellationToken
                };
                context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                    context.Source,
                    context.Log,
                    context.Token);

                var flatContainer = new FlatContainer(context);

                var packageIndex = new PackageIndex(context);

                // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet.
                for (int i = packagesToPush.Count - 1; i >= 0; i--)
                {
                    string item = packagesToPush[i];

                    bool?identical = await IsPackageIdenticalOnFeedAsync(
                        item,
                        packageIndex,
                        context.Source,
                        flatContainer,
                        log);

                    if (identical == null)
                    {
                        continue;
                    }

                    packagesToPush.RemoveAt(i);

                    if (identical == true)
                    {
                        Log.LogMessage(
                            MessageImportance.Normal,
                            "Package exists on the feed, and is verified to be identical. " +
                            $"Skipping upload: '{item}'");
                    }
                    else
                    {
                        Log.LogError(
                            "Package exists on the feed, but contents are different. " +
                            $"Upload failed: '{item}'");
                    }
                }

                if (!packagesToPush.Any())
                {
                    Log.LogMessage("After skipping idempotent uploads, no items need pushing.");
                    return(true);
                }
            }

            return(await PushCommand.RunAsync(
                       settings,
                       fileSystem,
                       packagesToPush,
                       options.AllowOverwrite,
                       skipExisting : false,
                       log : log));
        }
示例#26
0
        public async Task AddRemove_AddAndRemovePackageAsync()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var zipFile = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                            {
                                Zip     = zip,
                                Package = new PackageArchiveReader(zip)
                            };

                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.0", string.Empty, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                            var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity);

                            var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id);

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            var searchPackages = await search.GetPackagesAsync();

                            var autoCompletePackages = await autoComplete.GetPackageIds();

                            // Assert
                            Assert.True(validateOutput);
                            Assert.Equal(2, catalogEntries.Count);
                            Assert.Equal(0, catalogExistingEntries.Count);
                            Assert.Equal(0, regPackages.Count);
                            Assert.Equal(0, indexPackages.Count);
                            Assert.Equal(0, searchPackages.Count);
                            Assert.Equal(0, autoCompletePackages.Count);

                            Assert.Equal("packageA", catalogLatest.Id);
                            Assert.Equal("1.0.0", catalogLatest.Version.ToIdentityString());
                            Assert.Equal(SleetOperation.Remove, catalogLatest.Operation);
                        }
                    }
        }
示例#27
0
        public async Task GivenThatIRemoveAllPackagesWithTheCatalogDisabledVerifyItSucceeds()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        context.SourceSettings.CatalogEnabled = false;

                        var testPackage1 = new TestNupkg("packageA", "1.0.1");
                        var testPackage2 = new TestNupkg("packageA", "1.0.2");
                        var testPackage3 = new TestNupkg("packageA", "1.0.3");

                        var zipFile1 = testPackage1.Save(packagesFolder.Root);
                        var zipFile2 = testPackage2.Save(packagesFolder.Root);
                        var zipFile3 = testPackage3.Save(packagesFolder.Root);

                        var catalog      = new Catalog(context);
                        var registration = new Registrations(context);
                        var packageIndex = new PackageIndex(context);
                        var search       = new Search(context);
                        var autoComplete = new AutoComplete(context);

                        // Act
                        // run commands
                        await InitCommand.InitAsync(context);

                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log);

                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log);

                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile3.FullName }, false, false, context.Log);

                        await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.3", "", false, context.Log);

                        await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.1", "", false, context.Log);

                        await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.2", "", false, context.Log);

                        var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                        // read outputs
                        var catalogEntries = await catalog.GetIndexEntriesAsync();

                        var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                        var regPackages = await registration.GetPackagesByIdAsync("packageA");

                        var indexPackages = await packageIndex.GetPackagesAsync();

                        var searchPackages = await search.GetPackagesAsync();

                        var autoCompletePackages = await autoComplete.GetPackageIds();

                        // Assert
                        validateOutput.Should().BeTrue("the feed is valid");
                        catalogEntries.Should().BeEmpty("the catalog is disabled");
                        catalogExistingEntries.Should().BeEmpty("the catalog is disabled");
                        regPackages.Should().BeEmpty("all packages were removed");
                        indexPackages.Should().BeEmpty("all packages were removed");
                        searchPackages.Should().BeEmpty("all packages were removed");
                        autoCompletePackages.Should().BeEmpty("all packages were removed");
                    }
        }
示例#28
0
        public async Task GivenThatIAddAPackageWithTheCatalogDisabledVerifyItSucceeds()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        context.SourceSettings.CatalogEnabled = false;

                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var zipFile = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                            {
                                Zip     = zip,
                                Package = new PackageArchiveReader(zip)
                            };

                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                            var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity);

                            var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id);

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            var searchPackages = await search.GetPackagesAsync();

                            var autoCompletePackages = await autoComplete.GetPackageIds();

                            var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(input.Identity);

                            // Assert
                            validateOutput.Should().BeTrue("the feed is valid");
                            catalogEntries.Should().BeEmpty("the catalog is disabled");
                            catalogExistingEntries.Should().BeEmpty("the catalog is disabled");
                            regPackages.Should().BeEquivalentTo(new[] { input.Identity });
                            indexPackages.Should().BeEquivalentTo(new[] { input.Identity });
                            searchPackages.Should().BeEquivalentTo(new[] { input.Identity });
                            autoCompletePackages.Should().BeEquivalentTo(new[] { input.Identity.Id });

                            catalogLatest.Should().BeNull();
                            catalogEntry["version"].ToString().Should().Be("1.0.0");
                            catalogEntry["sleet:operation"].ToString().Should().Be("add");
                        }
                    }
        }
示例#29
0
        public async Task Feed_VerifyBaseUriIsAppliedToLocal(string baseUriString)
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log = new TestLogger();

                        var fileSystemRoot = UriUtility.CreateUri(target.Root);
                        var baseUri        = new Uri(baseUriString);

                        var fileSystem = new PhysicalFileSystem(cache, fileSystemRoot, baseUri);
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true,
                                SymbolsEnabled = true
                            }
                        };

                        var testPackage = new TestNupkg("packageA", "1.0.0");
                        var zipFile     = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                            {
                                Zip     = zip,
                                Package = new PackageArchiveReader(zip)
                            };

                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                            var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity);

                            var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id);

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            var searchPackages = await search.GetPackagesAsync();

                            var autoCompletePackages = await autoComplete.GetPackageIds();

                            // Assert
                            Assert.True(validateOutput);
                            Assert.Equal(1, catalogEntries.Count);
                            Assert.Equal(1, catalogExistingEntries.Count);
                            Assert.Equal(1, regPackages.Count);
                            Assert.Equal(1, indexPackages.Count);
                            Assert.Equal(1, searchPackages.Count);
                            Assert.Equal(1, autoCompletePackages.Count);

                            // Walk json to check for bad urls
                            await TestUtility.WalkJsonAsync(target.Root, (file, json, toCheck) =>
                            {
                                // Check only URLs found
                                if (toCheck.IndexOf("://") > -1)
                                {
                                    var cleanUriSchema = toCheck.Replace(":///", string.Empty).Replace("://", string.Empty);

                                    var doubleSlash = cleanUriSchema.IndexOf("//") > -1;
                                    Assert.False(doubleSlash, toCheck);
                                }
                            });
                        }
                    }
        }
示例#30
0
        public async Task Symbols_ForcePushPackageShouldNotAffectOtherType(bool isSymbols)
        {
            using (var testContext = new SleetTestContext())
            {
                var context = testContext.SleetContext;
                context.SourceSettings.SymbolsEnabled = true;

                // Create package
                var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0"));
                var pkgA     = new TestNupkg("a", "1.0.0");
                pkgA.Files.Clear();
                pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes());
                pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes());
                var zip      = pkgA.Save(testContext.Packages);
                var pkgInput = testContext.GetPackageInput(zip);

                var symPkgA = new TestNupkg("a", "1.0.0");
                symPkgA.Files.Clear();
                symPkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes());
                symPkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes());
                symPkgA.Nuspec.IsSymbolPackage = true;
                var symZip      = symPkgA.Save(testContext.Packages);
                var symPkgInput = testContext.GetPackageInput(symZip);

                var forcePushZip = zip.FullName;

                if (isSymbols)
                {
                    forcePushZip = symZip.FullName;
                }

                // Init
                var success = await InitCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    enableCatalog : true,
                    enableSymbols : true,
                    log : testContext.SleetContext.Log,
                    token : CancellationToken.None);

                // Push
                success &= await PushCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    new List <string>() { zip.FullName, symZip.FullName },
                    force : false,
                    skipExisting : false,
                    log : testContext.SleetContext.Log);

                // Force push
                success &= await PushCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    new List <string>() { forcePushZip },
                    force : true,
                    skipExisting : false,
                    log : testContext.SleetContext.Log);

                // Validate
                success &= await ValidateCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    log : testContext.SleetContext.Log);

                success.Should().BeTrue();

                // Both packages should exist, force should not delete one or the other.
                var index = new PackageIndex(context);
                (await index.Exists(identity)).Should().BeTrue();
                (await index.SymbolsExists(identity)).Should().BeTrue();
            }
        }
示例#31
0
        public async Task Symbols_AddSymbolsPackageVerifyFeed()
        {
            using (var testContext = new SleetTestContext())
            {
                var context = testContext.SleetContext;
                context.SourceSettings.SymbolsEnabled = true;
                var symbols       = new Symbols(context);
                var packageIndex  = new PackageIndex(context);
                var catalog       = new Catalog(context);
                var autoComplete  = new AutoComplete(context);
                var flatContainer = new FlatContainer(context);
                var registrations = new Registrations(context);
                var search        = new Search(context);

                // Create package
                var pkgA = new TestNupkg("a", "1.0.0");
                pkgA.Files.Clear();
                pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes());
                pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes());
                pkgA.Nuspec.IsSymbolPackage = true;
                var zip      = pkgA.Save(testContext.Packages);
                var pkgInput = testContext.GetPackageInput(zip);

                // Init
                var success = await InitCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    enableCatalog : true,
                    enableSymbols : true,
                    log : testContext.SleetContext.Log,
                    token : CancellationToken.None);

                // Push
                success &= await PushCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    new List <string>() { zip.FullName },
                    force : false,
                    skipExisting : false,
                    log : testContext.SleetContext.Log);

                // Validate
                success &= await ValidateCommand.RunAsync(
                    testContext.SleetContext.LocalSettings,
                    testContext.SleetContext.Source,
                    testContext.SleetContext.Log);

                success.Should().BeTrue();

                // Exists under symbols
                (await symbols.GetSymbolsPackagesAsync()).Should().NotBeEmpty();
                (await packageIndex.GetSymbolsPackagesAsync()).Should().NotBeEmpty();

                // Does not exist in non-symbols
                (await symbols.GetPackagesAsync()).Should().BeEmpty();
                (await packageIndex.GetPackagesAsync()).Should().BeEmpty();

                // Verify it does not appear in other services
                (await catalog.GetPackagesAsync()).Should().BeEmpty();
                (await autoComplete.GetPackageIds()).Should().BeEmpty();
                (await flatContainer.GetPackagesByIdAsync("a")).Should().BeEmpty();
                (await registrations.GetPackagesByIdAsync("a")).Should().BeEmpty();
                (await search.GetPackagesAsync()).Should().BeEmpty();

                // Verify nupkg exists
                var nupkgPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "a.1.0.0.symbols.nupkg");
                File.Exists(nupkgPath).Should().BeTrue();

                // Verify package details
                var detailsPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "package.json");
                File.Exists(detailsPath).Should().BeTrue();
            }
        }