Exemplo n.º 1
0
        public async void CreateCollectorDownloadAndDelete()
        {
            // Determine the latest supported version
            var collectorVersionInts = (await PortalClient.GetAllCollectorVersionsAsync(
                                            new Filter <CollectorVersion>
            {
                FilterItems = new List <FilterItem <CollectorVersion> >
                {
                    new Eq <CollectorVersion>(nameof(CollectorVersion.IsStable), true),
                }
            }
                                            ).ConfigureAwait(false))
                                       .Select(cv => (cv.MajorVersion * 1000) + cv.MinorVersion)
                                       .OrderByDescending(v => v)
                                       .ToList();

            Assert.NotNull(collectorVersionInts);
            Assert.NotEmpty(collectorVersionInts);

            var collectorVersionInt = collectorVersionInts[0];

            // Create the collector
            var collector = await PortalClient.CreateAsync(new CollectorCreationDto { Description = "UNIT TEST" }).ConfigureAwait(false);

            var tempFileInfo = new FileInfo(Path.GetTempPath() + Guid.NewGuid().ToString());

            try
            {
                await PortalClient.DownloadCollector(
                    collector.Id,
                    tempFileInfo,
                    CollectorPlatformAndArchitecture.Win64,
                    CollectorDownloadType.Bootstrap,
                    CollectorSize.Medium,
                    collectorVersionInt).ConfigureAwait(false);
            }
            finally
            {
                // No need to do this as the collector has not been registered
                // await DefaultPortalClient.DeleteAsync(collector).ConfigureAwait(false);
                tempFileInfo.Delete();

                // Remove the collector from the API
                await PortalClient.DeleteAsync(collector).ConfigureAwait(false);
            }
        }