public void TestSingleVhdWithCustomSize()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "app-attach", "custom-size"));

            var appAttachManager = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());
            var vhdPath1         = Path.Combine(targetDirectory.FullName, "output1.vhd");
            var vhdPath2         = Path.Combine(targetDirectory.FullName, "output2.vhd");

            try
            {
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPath1, 0, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPath2, 50, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            Assert.IsTrue(File.Exists(vhdPath1));
            Assert.IsTrue(File.Exists(vhdPath2));

            var fileSize1 = new FileInfo(vhdPath1).Length;
            var fileSize2 = new FileInfo(vhdPath2).Length;

            Assert.AreEqual(50, (int)fileSize2 / 1024 / 1024);
            Assert.Greater(fileSize2, fileSize1, "Custom size 50MB must product a bigger package than the auto-size of a relatively small package.");
        }
示例#2
0
        private static async Task <int> Run(AppAttachVerb arg)
        {
            var console = new ConsoleImpl(Console.Out, Console.Error);
            IAppAttachManager appAttachManager = new AppAttachManager(new SigningManager());
            var executor = new AppAttachVerbExecutor(arg, appAttachManager, console);
            var exitCode = await executor.Execute().ConfigureAwait(false);

            Environment.ExitCode = exitCode;
            return(exitCode);
        }
示例#3
0
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length > 0 && args[0] == "--selfElevate")
                {
                    Logger.Debug("Preparing to start the pipe server...");

                    IConfigurationService configurationService = new LocalConfigurationService();
                    ISigningManager       signingManager       = new SigningManager(MsixHeroGistTimeStampFeed.CreateCached());
                    IAppAttachManager     appAttachManager     = new AppAttachManager(signingManager, configurationService);
                    IAppxVolumeManager    appxVolumeManager    = new AppxVolumeManager();
                    IRegistryManager      registryManager      = new RegistryManager();
                    IAppxPackageManager   appxPackageManager   = new AppxPackageManager();
                    IAppxPackageQuery     appxPackageQuery     = new AppxPackageQuery(registryManager, configurationService);
                    IAppxPackageInstaller appxPackageInstaller = new AppxPackageInstaller();
                    IAppxPackageRunner    appxPackageRunner    = new AppxPackageRunner();
                    IAppxLogManager       appxLogManager       = new AppxLogManager();

                    var receivers = new ISelfElevationProxyReceiver[]
                    {
                        new AppAttachManagerProxyReceiver(appAttachManager),
                        new AppxPackageManagerProxyReceiver(appxPackageManager),
                        new AppxPackageQueryProxyReceiver(appxPackageQuery),
                        new AppxPackageInstallerProxyReceiver(appxPackageInstaller),
                        new AppxPackageRunnerProxyReceiver(appxPackageRunner),
                        new AppxLogManagerProxyReceiver(appxLogManager),
                        new AppxVolumeManagerProxyReceiver(appxVolumeManager),
                        new RegistryManagerProxyReceiver(registryManager),
                        new SigningManagerProxyReceiver(signingManager)
                    };

                    var server = new Server(receivers);
                    server.Start().GetAwaiter().GetResult();
                    Console.ReadKey();
                }
                else
                {
                    Logger.Fatal("Unsupported command line arguments, terminating...");
                    Environment.ExitCode = 1;
                }
            }
            catch (AggregateException e)
            {
                Logger.Fatal(e.GetBaseException(), "Fatal exception, the program will be closed.");
            }
            catch (Exception e)
            {
                Logger.Fatal(e, "Fatal exception, the program will be closed.");
            }

            Logger.Info("Waiting for the user to press a key...");
            Console.ReadKey();
        }
        public void TestSingleVhdWithJsonAndExtraFiles()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "app-attach", "scripts-json"));

            var appAttachManager   = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());
            var vhdPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "output.vhd");
            var vhdPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "output.vhd");
            var vhdPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "output.vhd");
            var vhdPathBoth        = Path.Combine(targetDirectory.FullName, "both", "output.vhd");

            try
            {
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathNothing, 0, AppAttachVolumeType.Vhd, false, false, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathScripts, 0, AppAttachVolumeType.Vhd, false, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathCertificate, 0, AppAttachVolumeType.Vhd, true, false, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathBoth, 0, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            var cerPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "output.cer");
            var cerPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "output.cer");
            var cerPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "output.cer");
            var cerPathBoth        = Path.Combine(targetDirectory.FullName, "both", "output.cer");

            var scriptPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "stage.ps1");
            var scriptPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "stage.ps1");
            var scriptPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "stage.ps1");
            var scriptPathBoth        = Path.Combine(targetDirectory.FullName, "both", "stage.ps1");

            var jsonPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "app-attach.json");
            var jsonPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "app-attach.json");
            var jsonPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "app-attach.json");
            var jsonPathBoth        = Path.Combine(targetDirectory.FullName, "both", "app-attach.json");

            Assert.False(File.Exists(cerPathNothing));
            Assert.False(File.Exists(cerPathScripts));
            Assert.True(File.Exists(cerPathCertificate));
            Assert.True(File.Exists(cerPathBoth));

            Assert.False(File.Exists(scriptPathNothing));
            Assert.True(File.Exists(scriptPathScripts));
            Assert.False(File.Exists(scriptPathCertificate));
            Assert.True(File.Exists(scriptPathBoth));

            Assert.True(File.Exists(jsonPathNothing));
            Assert.True(File.Exists(jsonPathScripts));
            Assert.True(File.Exists(jsonPathCertificate));
            Assert.True(File.Exists(jsonPathBoth));
        }
        public void TestMultipleFiles()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = Path.Combine(Environment.CurrentDirectory, "app-attach", "multiple");
            var targetVhd       = Path.Combine(targetDirectory, "vhd");
            var targetVhdx      = Path.Combine(targetDirectory, "vhdx");
            var targetCim       = Path.Combine(targetDirectory, "cim");

            var baseSourceFolder = Path.Combine(Environment.CurrentDirectory, "copied");

            Directory.CreateDirectory(baseSourceFolder);

            var sourceFiles = new[] { "pkg1.msix", "pkg2.msix", "pkg3.msix" }.Select(f => Path.Combine(baseSourceFolder, f)).ToArray();

            foreach (var src in sourceFiles)
            {
                msixHeroPackage.CopyTo(src, true);
            }

            var appAttachManager = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());

            try
            {
                appAttachManager.CreateVolumes(sourceFiles, targetVhd, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolumes(sourceFiles, targetVhdx, AppAttachVolumeType.Vhdx, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolumes(sourceFiles, targetCim, AppAttachVolumeType.Cim, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            Assert.True(File.Exists(Path.Combine(targetVhd, "pkg1.vhd")));
            Assert.True(File.Exists(Path.Combine(targetVhd, "pkg2.vhd")));
            Assert.True(File.Exists(Path.Combine(targetVhd, "pkg3.vhd")));

            Assert.True(File.Exists(Path.Combine(targetVhdx, "pkg1.vhdx")));
            Assert.True(File.Exists(Path.Combine(targetVhdx, "pkg2.vhdx")));
            Assert.True(File.Exists(Path.Combine(targetVhdx, "pkg3.vhdx")));

            Assert.True(Directory.Exists(Path.Combine(targetCim, "pkg1")));
            Assert.True(Directory.Exists(Path.Combine(targetCim, "pkg2")));
            Assert.True(Directory.Exists(Path.Combine(targetCim, "pkg3")));
        }
        public void TestSingleNonVhd()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "app-attach", "single"));

            var appAttachManager = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());
            var vhdxPath         = Path.Combine(targetDirectory.FullName, "output.vhdx");
            var cimPath          = Path.Combine(targetDirectory.FullName, "output.cim");

            try
            {
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdxPath, 0, AppAttachVolumeType.Vhdx, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, cimPath, 0, AppAttachVolumeType.Cim, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            Assert.IsTrue(File.Exists(vhdxPath));
            Assert.IsTrue(File.Exists(cimPath));
        }