Пример #1
0
        public void CreateBundleTest()
        {
            //Arrange
            Bundler      bundle         = new Bundler();
            const string outputFileName = @"TestBundle.p7m";

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Path.Combine(Directory.GetCurrentDirectory()
                                 , _incominganchors)
                    , Path.Combine(Directory.GetCurrentDirectory()
                                   , outputFileName));

            byte[] cmsdata = bundle.Create(resourceProvider);

            //Assert (Using agent bundler resolver code)
            Assert.Null(Record.Exception(() => resourceProvider.StoreBundle(cmsdata)));
            byte[]       p7BData      = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;

            Assert.Null(Record.Exception(() => anchorBundle = new AnchorBundle(p7BData)));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);
        }
Пример #2
0
        /// Generate a bundle containind the (embeddable) files in sourceDir
        public static string GenerateBundle(Bundler bundler, string sourceDir, string outputDir, bool copyExludedFiles = true)
        {
            // Convert sourceDir to absolute path
            sourceDir = Path.GetFullPath(sourceDir);

            // Get all files in the source directory and all sub-directories.
            string[] sources = Directory.GetFiles(sourceDir, searchPattern: "*", searchOption: SearchOption.AllDirectories);

            // Sort the file names to keep the bundle construction deterministic.
            Array.Sort(sources, StringComparer.Ordinal);

            List <FileSpec> fileSpecs = new List <FileSpec>(sources.Length);

            foreach (var file in sources)
            {
                fileSpecs.Add(new FileSpec(file, Path.GetRelativePath(sourceDir, file)));
            }

            var singleFile = bundler.GenerateBundle(fileSpecs);

            if (copyExludedFiles)
            {
                foreach (var spec in fileSpecs)
                {
                    if (spec.Excluded)
                    {
                        var outputFilePath = Path.Combine(outputDir, spec.BundleRelativePath);
                        Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
                        File.Copy(spec.SourcePath, outputFilePath, true);
                    }
                }
            }

            return(singleFile);
        }
Пример #3
0
        public void CreateBundleWithMetadataTest()
        {
            //Arrange
            Bundler      bundle         = new Bundler();
            const string outputFileName = @"TestBundleWithMetadata.p7b";

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(Path.Combine(Directory.GetCurrentDirectory()
                                                      , _incominganchors),
                                         Path.Combine(Directory.GetCurrentDirectory(), outputFileName)
                                         , null
                                         , @"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>");

            byte[] cmsdata = bundle.Create(resourceProvider);

            //Assert (Using agent bundler resolver code)
            Assert.Null(Record.Exception(() => resourceProvider.StoreBundle(cmsdata)));
            byte[]       p7BData      = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;

            Assert.Null(Record.Exception(() => anchorBundle = new AnchorBundle(p7BData)));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.NotNull(anchorBundle.Metadata);
            Assert.Equal(@"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>", anchorBundle.Metadata);
        }
Пример #4
0
        public void TestWithMultipleDuplicateEntriesFails()
        {
            var fixture = sharedTestState.TestFixture.Copy();

            var hostName   = BundleHelper.GetHostName(fixture);
            var bundleDir  = BundleHelper.GetBundleDir(fixture);
            var targetOS   = BundleHelper.GetTargetOS(fixture.CurrentRid);
            var targetArch = BundleHelper.GetTargetArch(fixture.CurrentRid);

            // Generate a file specification with duplicate entries
            var fileSpecs = new List <FileSpec>();

            fileSpecs.Add(new FileSpec(BundleHelper.GetHostPath(fixture), BundleHelper.GetHostName(fixture)));
            string appPath = BundleHelper.GetAppPath(fixture);

            fileSpecs.Add(new FileSpec(appPath, "rel/app.repeat.dll"));
            fileSpecs.Add(new FileSpec(appPath, "rel/app.repeat.dll"));
            string systemLibPath = Path.Join(BundleHelper.GetPublishPath(fixture), "System.dll");

            fileSpecs.Add(new FileSpec(appPath, "rel/system.repeat.dll"));
            fileSpecs.Add(new FileSpec(systemLibPath, "rel/system.repeat.dll"));

            Bundler bundler = new Bundler(hostName, bundleDir.FullName, targetOS: targetOS, targetArch: targetArch);

            Assert.Throws <ArgumentException>(() => bundler.GenerateBundle(fileSpecs))
            .Message
            .Should().Contain("rel/system.repeat.dll")
            .And.NotContain("rel/app.repeat.dll")
            .And.Contain(appPath)
            .And.Contain(systemLibPath);
        }
Пример #5
0
        protected override void ProcessRecord()
        {
            try
            {
                Bundler bundle = new Bundler();

                IResourceProvider resourceProvider =
                    new FileResourceProvider(
                        Name
                        , Output
                        , Ignore
                        , Metadata);
                bundle.Create(resourceProvider);

                byte[] p7BData = bundle.Create(resourceProvider);

                WriteObject(p7BData);
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "Export-Bundle",
                        ErrorCategory.NotSpecified,
                        Name
                        )
                    );
            }
        }
        /// <summary>
        /// Updates the web portal bundle files. This controls which files are bundled and sent to the client browser.
        /// </summary>
        /// <param name="bundler">The bundler instance.</param>
        /// <returns>A task which is complete when the bundles are updated.</returns>
        public async virtual Task UpdateBundles(Bundler bundler)
        {
            if (bundler == null)
            {
                throw new ArgumentNullException("bundler", "null bundler passed in");
            }

            bundler.Clear();

            Assets startUpAssets = await this.AggregateStartupAssets();

            Assets nonStartUpAssets = await this.AggregateNonStartupAssets();

            // build the start up javascript and css files and bundle them
            List <string> startupClasses = new List <string>(startUpAssets.JavaScript);
            List <string> startupStyles  = new List <string>(startUpAssets.Css);

            bundler.BundleStartupAssets(startupClasses.ToArray(), startupStyles.ToArray());

            // build the non startup files and bundle them
            List <string> nonStartupClasses = new List <string>(nonStartUpAssets.JavaScript);
            List <string> nonStartupStyles  = new List <string>(nonStartUpAssets.Css);

            bundler.BundleNonStartupAssets(nonStartupClasses.ToArray(), nonStartupStyles.ToArray());
        }
Пример #7
0
        public async Task TsBundleSuccess()
        {
            // Arrange
            var entrys = new List <BundleEntry>()
            {
                new BundleEntry()
                {
                    InputFiles = new string[] { rootFolder + "home.ts" }, OutputFile = rootFolder + "resultBundle.ts"
                },
                new BundleEntry()
                {
                    InputFiles = new string[] { rootFolder + "IMenuInfluential.ts", rootFolder + "IMenuItemEventable.ts", rootFolder + "menu.ts", rootFolder + "search.ts", rootFolder + "site.ts" },
                    OutputFile = rootFolder + "resultBundle2.ts"
                }
            };
            var expectedBundles = await GetExpectedBundles();

            // Act
            await Bundler.BundleAsync(entrys);

            var resultBundles = await GetResultBundles(entrys);

            // Assert
            Assert.Equal(expectedBundles, resultBundles);
        }
Пример #8
0
        protected override void ExecuteCore()
        {
            OSPlatform targetOS = RuntimeIdentifier.StartsWith("win") ? OSPlatform.Windows :
                                  RuntimeIdentifier.StartsWith("osx") ? OSPlatform.OSX : OSPlatform.Linux;

            BundleOptions options = BundleOptions.BundleAllContent;

            options |= IncludeSymbols ? BundleOptions.BundleSymbolFiles : BundleOptions.None;

            var bundler = new Bundler(AppHostName, OutputDir, options, targetOS, new Version(TargetFrameworkVersion), ShowDiagnosticOutput);

            var fileSpec = new List <FileSpec>(FilesToBundle.Length);

            foreach (var item in FilesToBundle)
            {
                fileSpec.Add(new FileSpec(sourcePath: item.ItemSpec,
                                          bundleRelativePath: item.GetMetadata(MetadataKeys.RelativePath)));
            }

            bundler.GenerateBundle(fileSpec);

            // Certain files are excluded from the bundle, based on BundleOptions.
            // For example:
            //    Native files and contents files are excluded by default.
            //    hostfxr and hostpolicy are excluded until singlefilehost is available.
            // Return the set of excluded files in ExcludedFiles, so that they can be placed in the publish directory.

            ExcludedFiles = FilesToBundle.Zip(fileSpec, (item, spec) => (spec.Excluded) ? item : null).Where(x => x != null).ToArray();
        }
Пример #9
0
        public void BundlerTest_WithOutOptimizers()
        {
            var bundler = new Bundler();
            var result  = bundler.BundleToString(@"C:\Users\DONO\Source\Workspaces\Verdicter\Verdicter\SpaBundlerTests\Content\Main.html");

            Assert.IsTrue(result != null);
        }
Пример #10
0
        public void BundlerTest_InterferenceWithTypescript()
        {
            var bundler = new Bundler();
            var result  = bundler.BundleToString(@"C:\Users\DONO\Source\Workspaces\Verdicter\Verdicter\SpaBundlerTests\Content\Main.html");

            Assert.IsTrue(result.Contains("<reference path=\"Scripts/test.js\" />"));
        }
Пример #11
0
        protected override void ProcessRecord()
        {
            try
            {
                Bundler bundle = new Bundler();

                IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Name
                    , Output
                    , Ignore
                    , Metadata);
                bundle.Create(resourceProvider);

                byte[] p7BData = bundle.Create(resourceProvider);

                WriteObject(p7BData);
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "Export-Bundle",
                        ErrorCategory.NotSpecified,
                        Name
                        )
                 );
            }
        }
Пример #12
0
        public void TestWithAdditionalContentAfterBundleMetadata()
        {
            var fixture = sharedTestState.TestFixture.Copy();

            var hostName  = BundleHelper.GetHostName(fixture);
            var bundleDir = BundleHelper.GetBundleDir(fixture);

            var    bundler    = new Bundler(hostName, bundleDir.FullName);
            string singleFile = bundler.GenerateBundle(BundleHelper.GetPublishPath(fixture));

            using (var file = File.OpenWrite(singleFile))
            {
                file.Position = file.Length;
                var blob = Encoding.UTF8.GetBytes("Mock signature at the end of the bundle");
                file.Write(blob, 0, blob.Length);
            }

            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World!");
        }
Пример #13
0
        public void CreateBundleWithMetadataTest()
        {
            //Arrange
            Bundler bundle = new Bundler();
            const string outputFileName = @"TestBundleWithMetadata.p7b";

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(Path.Combine(Directory.GetCurrentDirectory()
                                                  , @"Certificates\nhind\IncomingAnchors"),
                                     Path.Combine(Directory.GetCurrentDirectory(), outputFileName)
                                     , null
                                     , @"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>");
            byte[] cmsdata = bundle.Create(resourceProvider);

            //Assert (Using agent bundler resolver code)
            Assert.DoesNotThrow(() => resourceProvider.StoreBundle(cmsdata));
            byte[] p7BData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(p7BData));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.NotNull(anchorBundle.Metadata);
            Assert.Equal(@"<TrustBundle><Profile>The Good Guys</Profile><DistributionPoint>http://bundler.lab/testComunity/pack.p7b</DistributionPoint></TrustBundle>", anchorBundle.Metadata);

        }
        public void Bundle_Is_Extracted()
        {
            var fixture = sharedTestState.SingleFileTestFixture.Copy();

            UseSingleFileSelfContainedHost(fixture);
            Bundler bundler           = BundleHelper.BundleApp(fixture, out string singleFile, BundleOptions.BundleAllContent);
            var     extractionBaseDir = BundleHelper.GetExtractionRootDir(fixture);

            Command.Create(singleFile, "executing_assembly_location trusted_platform_assemblies assembly_location System.Console")
            .CaptureStdOut()
            .CaptureStdErr()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractionBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            // Validate that the main assembly is running from disk (and not from bundle)
            .And.HaveStdOutContaining("ExecutingAssembly.Location: " + extractionBaseDir.FullName)
            // Validate that TPA contains at least one framework assembly from the extraction directory
            .And.HaveStdOutContaining("System.Runtime.dll")
            // Validate that framework assembly is actually loaded from the extraction directory
            .And.HaveStdOutContaining("System.Console location: " + extractionBaseDir.FullName);

            var extractionDir  = BundleHelper.GetExtractionDir(fixture, bundler);
            var bundleFiles    = BundleHelper.GetBundleDir(fixture).GetFiles().Select(file => file.Name).ToArray();
            var publishedFiles = Directory.GetFiles(BundleHelper.GetPublishPath(fixture), searchPattern: "*", searchOption: SearchOption.AllDirectories)
                                 .Select(file => Path.GetFileName(file))
                                 .Except(bundleFiles)
                                 .ToArray();

            extractionDir.Should().HaveFiles(publishedFiles);
        }
Пример #15
0
        private void Run(TestProjectFixture fixture, string publishDir, string singleFileDir)
        {
            var dotnet   = fixture.SdkDotnet;
            var hostName = Path.GetFileName(fixture.TestProject.AppExe);

            // Run the App normally
            Command.Create(Path.Combine(publishDir, hostName))
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Wow! We now say hello to the big world and you.");

            // Bundle to a single-file
            Bundler bundler    = new Bundler(hostName, singleFileDir);
            string  singleFile = bundler.GenerateBundle(publishDir);

            // Extract the file
            Extractor extractor = new Extractor(singleFile, singleFileDir);

            extractor.ExtractFiles();

            // Run the extracted app
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Wow! We now say hello to the big world and you.");
        }
Пример #16
0
        public void TestFilesNotBundled(bool embedPDBs)
        {
            var fixture = sharedTestState.TestFixture.Copy();

            var    hostName    = BundleHelper.GetHostName(fixture);
            var    appName     = Path.GetFileNameWithoutExtension(hostName);
            string publishPath = BundleHelper.GetPublishPath(fixture);
            var    bundleDir   = BundleHelper.GetBundleDir(fixture);

            // Make up a app.runtimeconfig.dev.json file in the publish directory.
            File.Copy(Path.Combine(publishPath, $"{appName}.runtimeconfig.json"),
                      Path.Combine(publishPath, $"{appName}.runtimeconfig.dev.json"));

            var singleFile = new Bundler(hostName, bundleDir.FullName, embedPDBs).GenerateBundle(publishPath);

            bundleDir.Should().OnlyHaveFiles(new string[] { hostName });

            new Extractor(singleFile, bundleDir.FullName).ExtractFiles();

            bundleDir.Should().NotHaveFile($"{appName}.runtimeconfig.dev.json");
            if (!embedPDBs)
            {
                bundleDir.Should().NotHaveFile($"{appName}.pdb");
            }
        }
Пример #17
0
        public void TestWithExactDuplicateEntriesPasses()
        {
            var fixture = sharedTestState.TestFixture.Copy();

            var hostName   = BundleHelper.GetHostName(fixture);
            var bundleDir  = BundleHelper.GetBundleDir(fixture);
            var targetOS   = BundleHelper.GetTargetOS(fixture.CurrentRid);
            var targetArch = BundleHelper.GetTargetArch(fixture.CurrentRid);

            // Generate a file specification with duplicate entries
            var fileSpecs = new List <FileSpec>();

            fileSpecs.Add(new FileSpec(BundleHelper.GetHostPath(fixture), BundleHelper.GetHostName(fixture)));
            string appPath = BundleHelper.GetAppPath(fixture);

            fileSpecs.Add(new FileSpec(appPath, "rel/app.repeat.dll"));
            fileSpecs.Add(new FileSpec(appPath, "rel/app.repeat.dll"));
            string systemLibPath = Path.Join(BundleHelper.GetPublishPath(fixture), "System.dll");

            fileSpecs.Add(new FileSpec(systemLibPath, "rel/system.repeat.dll"));
            fileSpecs.Add(new FileSpec(systemLibPath, "rel/system.repeat.dll"));

            Bundler bundler = new Bundler(hostName, bundleDir.FullName, targetOS: targetOS, targetArch: targetArch);

            bundler.GenerateBundle(fileSpecs);

            // Exact duplicates are not duplicated in the bundle
            bundler.BundleManifest.Files.Where(entry => entry.RelativePath.Equals("rel/app.repeat.dll")).Single().Type.Should().Be(FileType.Assembly);
            bundler.BundleManifest.Files.Where(entry => entry.RelativePath.Equals("rel/system.repeat.dll")).Single().Type.Should().Be(FileType.Assembly);
        }
Пример #18
0
        public void CreateBundleTest()
        {
            //Arrange
            Bundler bundle = new Bundler();
            const string outputFileName = @"TestBundle.p7m";

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Path.Combine(Directory.GetCurrentDirectory()
                    , @"Certificates\nhind\IncomingAnchors")
                    , Path.Combine(Directory.GetCurrentDirectory()
                    , outputFileName));
            byte[] cmsdata = bundle.Create(resourceProvider);

            //Assert (Using agent bundler resolver code)
            Assert.DoesNotThrow(() => resourceProvider.StoreBundle(cmsdata));
            byte[] p7BData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(p7BData));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);
            
            
        }
Пример #19
0
        protected override void ProcessRecord()
        {
            try
            {

                Bundler bundle = new Bundler();

                ISignProvider signProvider =
                    new FileSignerProvider(
                        Name,
                        PassKey);


                byte[] p7BData = _bundle as byte[];
                byte[] p7MData = bundle.Sign(p7BData, signProvider);

                WriteObject(p7MData);
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "Export-Bundle",
                        ErrorCategory.NotSpecified,
                        Name
                        )
                    );
            }
        }
Пример #20
0
        protected override void ProcessRecord()
        {
            try
            {
                Bundler bundle = new Bundler();

                ISignProvider signProvider =
                    new FileSignerProvider(
                        Name,
                        PassKey);


                byte[] p7BData = _bundle as byte[];
                byte[] p7MData = bundle.Sign(p7BData, signProvider);

                WriteObject(p7MData);
            }
            catch (Exception e)
            {
                WriteError(
                    new ErrorRecord(
                        e,
                        "Export-Bundle",
                        ErrorCategory.NotSpecified,
                        Name
                        )
                    );
            }
        }
Пример #21
0
        public void CreateSignedBundleTest()
        {
            //Arrange
            Bundler      bundle         = new Bundler();
            const string outputFileName = @"TestBundleWithMetadata.p7m";

            var secString = new SecureString();

            foreach (var secchar in "passw0rd!".ToCharArray())
            {
                secString.AppendChar(secchar);
            }

            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), _incominganchors)
                    , Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            ISignProvider signProvider =
                new FileSignerProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), _privateRedmondPfx),
                    secString);

            byte[] cmsdata = bundle.Create(resourceProvider, signProvider);

            //Assert (Using agent bundler resolver code)
            Assert.Null(Record.Exception(() => resourceProvider.StoreBundle(cmsdata)));
            byte[]       p7BData      = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;

            Assert.Null(Record.Exception(() => anchorBundle = new AnchorBundle(p7BData, true)));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);
        }
Пример #22
0
            public SharedTestState()
            {
                TestFixture = PreparePublishedSelfContainedTestProject("StandaloneApp");

                DefaultBundledAppFixture        = TestFixture.Copy();
                DefaultBundledAppBundler        = BundleSelfContainedApp(DefaultBundledAppFixture, out var singleFile, BundleOptions.BundleNativeBinaries);
                DefaultBundledAppExecutablePath = singleFile;
            }
Пример #23
0
 public SalesForcePackager(DiffCollector differ, Bundler bundler, FilePackager packager, PackageXmlGenerator manifestGenerator, IFileSystem fs, IOutput output)
 {
     _differ            = differ;
     _bundler           = bundler;
     _packager          = packager;
     _manifestGenerator = manifestGenerator;
     _fs     = fs;
     _output = output;
 }
Пример #24
0
        public void CreateWithInvalidMetaDataTest(string metatdata)
        {
            Bundler bundle = new Bundler();

            Assert.Throws <XmlSchemaValidationException>(() =>
                                                         bundle.Create(
                                                             new FileResourceProvider(Path.Combine(Directory.GetCurrentDirectory(), _incominganchors)
                                                                                      , Path.Combine(Directory.GetCurrentDirectory(), @"TestBundle.p7b")
                                                                                      , null
                                                                                      , metatdata))
                                                         );
        }
Пример #25
0
        // Bundle to a single-file
        // In several tests, the single-file bundle is created explicitly using Bundle API
        // instead of the SDK via /p:PublishSingleFile=true.
        // This is necessary when the test needs the latest changes in the AppHost,
        // which may not (yet) be available in the SDK.
        //
        // Currently, AppHost can only handle bundles if all content is extracted to disk on startup.
        // Therefore, the BundleOption is BundleAllContent by default.
        // The default should be BundleOptions.None once host/runtime no longer requires full-extraction.
        public static string BundleApp(TestProjectFixture fixture,
                                       BundleOptions options          = BundleOptions.BundleAllContent,
                                       Version targetFrameworkVersion = null)
        {
            var    hostName    = GetHostName(fixture);
            string publishPath = GetPublishPath(fixture);
            var    bundleDir   = GetBundleDir(fixture);

            var    bundler    = new Bundler(hostName, bundleDir.FullName, options, targetFrameworkVersion: targetFrameworkVersion);
            string singleFile = GenerateBundle(bundler, publishPath);

            return(singleFile);
        }
Пример #26
0
        protected override void ExecuteCore()
        {
            var bundler  = new Bundler(AppHostName, OutputDir, IncludeSymbols, ShowDiagnosticOutput);
            var fileSpec = new List <FileSpec>(FilesToBundle.Length);

            foreach (var item in FilesToBundle)
            {
                fileSpec.Add(new FileSpec(sourcePath: item.ItemSpec,
                                          bundleRelativePath: item.GetMetadata(MetadataKeys.RelativePath)));
            }

            bundler.GenerateBundle(fileSpec);
        }
Пример #27
0
        public void CreateWithBadMetaDataTest(string metatdata)
        {
            Bundler bundle = new Bundler();

            Assert.Throws <XmlException>(() =>
                                         bundle.Create(
                                             new FileResourceProvider(Path.Combine(Directory.GetCurrentDirectory()
                                                                                   , @"Certificates\nhind\IncomingAnchors")
                                                                      , Path.Combine(Directory.GetCurrentDirectory(), @"TestBundle.p7b")
                                                                      , null
                                                                      , metatdata))
                                         );
        }
        /// <summary>
        /// Updates the web portal bundle files.
        /// </summary>
        /// <param name="bundler">The bundler instance.</param>
        /// <returns>A task which is complete when the bundles are updated.</returns>
        public override async Task UpdateBundles(Bundler bundler)
        {
            if (this.isBundlesGenerated)
            {
                // only generate the bundles once since they will remain constant across the web application's life span
                return;
            }

            // call the standard bundling implementation
            await base.UpdateBundles(bundler).ConfigureAwait(false);

            this.isBundlesGenerated = true;
        }
Пример #29
0
        /// <summary>
        /// Updates the web portal bundle files.
        /// </summary>
        /// <param name="bundler">The bundler instance.</param>
        /// <returns>A task which is complete when the bundles are updated.</returns>
        public override void UpdateBundles(Bundler bundler)
        {
            if (isBundlesGenerated)
            {
                // only generate the bundles once since they will remain constant across the web application's life span
                return;
            }

            // call the standard bundling implementation
            base.UpdateBundles(bundler);

            isBundlesGenerated = true;
        }
Пример #30
0
        public async Task RunAsync()
        {
            _Log.Info("(+) => included references");
            _Log.Info("(-) => ignored references");
            _Log.Info("(~) => identified package rerferences");

            _Log.Info("");

            _Log.Info($"analyzing assemblies in");

            foreach (var path in _Config.Assemblies.SourcePaths)
            {
                _Log.Info($"  {path}");
            }



            var folder     = new AssemblySource(_Config.Assemblies.Sources, _Config.Assemblies.ExcludePatterns);
            var assemblies = await folder.GetAssembliesAsync();

            var orderedByLeastReferences = assemblies.OrderBy(x => x.KnownReferences.Count());

            _Log.Info("");
            Echo(orderedByLeastReferences);

            _Log.Info("");
            _Log.Info("deriving bundles / pacakges");
            _Log.Info("");

            var bundler = new Bundler(_Config);
            var bundles = bundler.GetBundles(orderedByLeastReferences);

            Echo(bundles);

            _Config.NuSpecDirectory.Create();

            var writer = new NuSpecWriter(_Config);

            _Log.Info($"writing nuspec files to : {_Config.NuSpecDirectory}");

            foreach (var bundle in bundles)
            {
                var target        = new FileInfo(Path.Combine(_Config.NuSpecDirectory.FullName, $"{bundle.PackageFullName}.nuspec"));
                var nuspecContent = writer.GetNuSpec(bundle);

                _Log.Info($"  {target.Name}");
                File.WriteAllText(target.FullName, nuspecContent);
            }

            _Log.Info($"created {bundles.Count()} nuspec(s)");
        }
Пример #31
0
        private void Bundle_extraction_is_reused()
        {
            var    fixture     = sharedTestState.TestFixture.Copy();
            var    hostName    = BundleHelper.GetHostName(fixture);
            var    appName     = Path.GetFileNameWithoutExtension(hostName);
            string publishPath = BundleHelper.GetPublishPath(fixture);

            // Publish the bundle
            var    bundleDir  = BundleHelper.GetBundleDir(fixture);
            var    bundler    = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
            string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

            // Create a directory for extraction.
            var extractBaseDir = BundleHelper.GetExtractDir(fixture);

            // Run the bunded app for the first time, and extract files to
            // $DOTNET_BUNDLE_EXTRACT_BASE_DIR/<app>/bundle-id
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            string extractPath = Path.Combine(extractBaseDir.FullName, appName, bundler.BundleManifest.BundleID);
            var    extractDir  = new DirectoryInfo(extractPath);

            extractDir.Refresh();
            DateTime firstWriteTime = extractDir.LastWriteTimeUtc;

            while (DateTime.Now == firstWriteTime)
            {
                Thread.Sleep(1);
            }

            // Run the bundled app again (reuse extracted files)
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            extractDir.Should().NotBeModifiedAfter(firstWriteTime);
        }
Пример #32
0
        protected override void ExecuteCore()
        {
            BundleOptions options  = BundleOptions.BundleAllContent | (IncludeSymbols ? BundleOptions.BundleSymbolFiles : BundleOptions.None);
            var           bundler  = new Bundler(AppHostName, OutputDir, options, diagnosticOutput: ShowDiagnosticOutput);
            var           fileSpec = new List <FileSpec>(FilesToBundle.Length);

            foreach (var item in FilesToBundle)
            {
                fileSpec.Add(new FileSpec(sourcePath: item.ItemSpec,
                                          bundleRelativePath: item.GetMetadata(MetadataKeys.RelativePath)));
            }

            bundler.GenerateBundle(fileSpec);
        }
Пример #33
0
        private void Bundle_extraction_can_recover_missing_files()
        {
            var    fixture     = sharedTestState.TestFixture.Copy();
            var    hostName    = BundleHelper.GetHostName(fixture);
            var    appName     = Path.GetFileNameWithoutExtension(hostName);
            string publishPath = BundleHelper.GetPublishPath(fixture);

            // Publish the bundle
            var    bundleDir  = BundleHelper.GetBundleDir(fixture);
            var    bundler    = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
            string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

            // Compute bundled files
            List <string> bundledFiles = bundler.BundleManifest.Files.Select(file => file.RelativePath).ToList();

            // Create a directory for extraction.
            var    extractBaseDir = BundleHelper.GetExtractDir(fixture);
            string extractPath    = Path.Combine(extractBaseDir.FullName, appName, bundler.BundleManifest.BundleID);
            var    extractDir     = new DirectoryInfo(extractPath);

            // Run the bunded app for the first time, and extract files to
            // $DOTNET_BUNDLE_EXTRACT_BASE_DIR/<app>/bundle-id
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            bundledFiles.ForEach(file => File.Delete(Path.Combine(extractPath, file)));

            extractDir.Should().Exist();
            extractDir.Should().NotHaveFiles(bundledFiles);

            // Run the bundled app again (recover deleted files)
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            extractDir.Should().HaveFiles(bundledFiles);
        }
Пример #34
0
        private void BundleRun(TestProjectFixture fixture, string publishDir, string singleFileDir)
        {
            var hostName = BundleHelper.GetHostName(fixture);

            // Run the App normally
            RunTheApp(Path.Combine(publishDir, hostName));

            // Bundle to a single-file
            Bundler bundler    = new Bundler(hostName, singleFileDir);
            string  singleFile = bundler.GenerateBundle(publishDir);

            // Run the extracted app
            RunTheApp(singleFile);
        }
Пример #35
0
 public void CreateWithInvalidMetaDataTest(string metatdata)
 {
     Bundler bundle = new Bundler();
     
     Assert.Throws<XmlSchemaValidationException>(() =>
                                 bundle.Create(
                                     new FileResourceProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Certificates\nhind\IncomingAnchors")
                                     , Path.Combine(Directory.GetCurrentDirectory(), @"TestBundle.p7b")
                                     , null
                                     , metatdata))
         );
 }
Пример #36
0
        public void CreateSignedBundleTest()
        {
            //Arrange
            Bundler bundle = new Bundler();
            const string outputFileName = @"TestBundleWithMetadata.p7m";

            var secString = new SecureString();
            foreach (var secchar in "passw0rd!".ToCharArray())
            {
                secString.AppendChar(secchar);
            }


            //Act
            IResourceProvider resourceProvider =
                new FileResourceProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"Certificates\nhind\IncomingAnchors")
                    , Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            ISignProvider signProvider =
                new FileSignerProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"Certificates\redmond\Private\redmond.pfx"),
                    secString);
            byte[] cmsdata = bundle.Create(resourceProvider, signProvider);

            //Assert (Using agent bundler resolver code)
            Assert.DoesNotThrow(() => resourceProvider.StoreBundle(cmsdata));
            byte[] p7BData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), outputFileName));
            AnchorBundle anchorBundle = null;
            Assert.DoesNotThrow(() => anchorBundle = new AnchorBundle(p7BData, true));
            Assert.True(!anchorBundle.Certificates.IsNullOrEmpty());
            Assert.Equal(4, anchorBundle.Certificates.Count);
            Assert.Null(anchorBundle.Metadata);


        }