コード例 #1
0
ファイル: TextureDictionary.cs プロジェクト: D3fau4/image2gnf
        /// <summary>
        /// Converts the given texture dictionary to a field texture archive, and returns a new texture dictionary filled with dummy textures for each texture in the given texture dictionary.
        /// </summary>
        /// <param name="textureDictionary"></param>
        /// <param name="archiveFilePath"></param>
        /// <returns></returns>
        public static TextureDictionary ConvertToFieldTextureArchive(TextureDictionary textureDictionary, string archiveFilePath, bool usePS4Format = false)
        {
            var archiveBuilder = new ArchiveBuilder();

            // Create bgTexArcData00.txt
            var fieldTextureArchiveDataInfoStream = new MemoryStream();

            using (var streamWriter = new StreamWriter(fieldTextureArchiveDataInfoStream, Encoding.Default, 4096, true))
            {
                streamWriter.WriteLine("1,");
                streamWriter.WriteLine($"{textureDictionary.Count},");
            }

            archiveBuilder.AddFile("bgTexArcData00.txt", fieldTextureArchiveDataInfoStream);

            // Convert textures
            foreach (var texture in textureDictionary.Textures)
            {
                var textureInfo      = TextureInfo.GetTextureInfo(texture);
                var texturePixelData = TextureUtilities.GetPixelData(texture);

                // Create field texture & save it
                Stream textureStream = new MemoryStream();
                if (!usePS4Format)
                {
                    var fieldTexture = new FieldTexturePS3(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                           ( short )textureInfo.Height, texturePixelData);
                    fieldTexture.Save(textureStream);
                }
                else
                {
                    var fieldTexture = new GNFTexture(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                      ( short )textureInfo.Height, texturePixelData, false);
                    fieldTexture.Save(textureStream);
                }

                archiveBuilder.AddFile(texture.Name, textureStream);
            }

            // Finally build archive file
            archiveBuilder.BuildFile(archiveFilePath);

            // Dummy out textures in texture dictionary
            var newTextureDictionary = new TextureDictionary(textureDictionary.Version);

            foreach (var texture in textureDictionary.Textures)
            {
                newTextureDictionary.Add(Texture.CreateDefaultTexture(texture.Name));
            }

            return(newTextureDictionary);
        }
コード例 #2
0
        public void CalculateOffsetTest()
        {
            using (Stream stream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm"))
            {
                var originalPackage = RpmPackageReader.Read(stream);

                using (var payloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                    using (var cpio = new CpioFile(payloadStream, false))
                    {
                        ArchiveBuilder    builder = new ArchiveBuilder(new PlistFileAnalyzer());
                        RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer());
                        var entries = builder.FromCpio(cpio);
                        var files   = creator.CreateFiles(entries);

                        // Core routine to populate files and dependencies
                        RpmPackage package  = new RpmPackage();
                        var        metadata = new PublicRpmMetadata(package);
                        metadata.Name    = "libplist";
                        metadata.Version = "2.0.1.151";
                        metadata.Arch    = "x86_64";
                        metadata.Release = "1.1";

                        creator.AddPackageProvides(metadata);
                        creator.AddLdDependencies(metadata);

                        metadata.Files = files;
                        creator.AddRpmDependencies(metadata, null);

                        PlistMetadata.ApplyDefaultMetadata(metadata);

                        metadata.Vendor              = "obs://build.opensuse.org/home:qmfrederik";
                        metadata.Description         = "libplist is a library for manipulating Apple Binary and XML Property Lists";
                        metadata.Url                 = "http://www.libimobiledevice.org/";
                        metadata.Size                = 0x26e6d;
                        metadata.ImmutableRegionSize = -976;

                        creator.CalculateHeaderOffsets(package);

                        foreach (var record in originalPackage.Header.Records)
                        {
                            if (record.Key == IndexTag.RPMTAG_HEADERIMMUTABLE)
                            {
                                continue;
                            }

                            this.AssertTagOffsetEqual(record.Key, originalPackage, package);
                        }

                        this.AssertTagOffsetEqual(IndexTag.RPMTAG_HEADERIMMUTABLE, originalPackage, package);
                    }
            }
        }
コード例 #3
0
        private static TestRun CreateTestRun(XmlElementHelper xmlElementHelper)
        {
            const string testdataDirectory = "TestData\\Noark5\\DocumentfilesControl\\FilesWithDocumentedChecksums";

            Archive testArchive = new ArchiveBuilder()
                                  .WithArchiveType(ArchiveType.Noark5)
                                  .WithWorkingDirectoryRoot(testdataDirectory)
                                  .Build();

            TestRun testRun = xmlElementHelper.RunEventsOnTest(new N5_30_DocumentFilesChecksumControl(testArchive));

            return(testRun);
        }
コード例 #4
0
        private static TestRun CreateTestRun(string workingDirectory)
        {
            Archive archive = new ArchiveBuilder()
                              .WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot(workingDirectory)
                              .WithWorkingDirectoryExternalContent(workingDirectory + "\\content")
                              .Build();

            var validateNumberOfDocumentfiles = new ValidateNumberOfDocumentfiles();

            validateNumberOfDocumentfiles.Test(archive);

            return(validateNumberOfDocumentfiles.GetTestRun());
        }
コード例 #5
0
        public void HasSeverealDisposalsExecutedWithinSeveralArchiveParts()
        {
            XmlElementHelper helper = new XmlElementHelper()
                                      .Add("arkiv",
                                           new XmlElementHelper()
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_1")
                                                .Add("utfoertKassasjon", string.Empty)
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("utfoertKassasjon", string.Empty)))))))
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_2")
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("utfoertKassasjon", string.Empty))))))));

            // Creating a test archive stating that it should contain executed disposals
            var testArchive = new ArchiveBuilder().WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot("TestData\\Noark5\\MetaDataTesting\\BooleansTrue").Build();

            TestRun testRun = helper.RunEventsOnTest(new N5_45_NumberOfDisposalsExecuted(testArchive));

            testRun.Results.First().Message.Should().Be("Totalt: 3");
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Totalt: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Totalt: 1"
                                                 ));
            testRun.Results.Count.Should().Be(3);
        }
コード例 #6
0
        private static TestRun CreateTestRun(string workingDirectory)
        {
            Archive archive = new ArchiveBuilder()
                              .WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot(workingDirectory)
                              .WithWorkingDirectoryExternalContent(workingDirectory)
                              .Build();

            var validateXmlWithSchema = new ValidateXmlWithSchema();

            validateXmlWithSchema.Test(archive);

            return(validateXmlWithSchema.GetTestRun());
        }
コード例 #7
0
        public void FromDirectoryWithAppHost()
        {
            ArchiveBuilder builder = new ArchiveBuilder();
            var            entries = builder.FromDirectory("archive", "demo", "/opt/demo", Array.Empty <ITaskItem>());

            Assert.Equal(3, entries.Count);

            var readme = entries[0];

            Assert.Equal("root", readme.Group);
            Assert.Equal(1L, readme.Inode);
            Assert.False(readme.IsAscii);
            Assert.Equal(string.Empty, readme.LinkTo);
            Assert.Equal(LinuxFileMode.S_IROTH | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IRUSR | LinuxFileMode.S_IFREG, readme.Mode);
            Assert.Equal("root", readme.Owner);
            Assert.False(readme.RemoveOnUninstall);
            Assert.Equal(Path.Combine("archive", "README.md"), readme.SourceFilename);
            Assert.Equal("/opt/demo/README.md", readme.TargetPath);
            Assert.Equal("/opt/demo/README.md", readme.TargetPathWithFinalSlash);
            Assert.Equal(ArchiveEntryType.None, readme.Type);

            var script = entries[1];

            Assert.Equal("root", script.Group);
            Assert.Equal(2L, script.Inode);
            Assert.False(script.IsAscii);
            Assert.Equal(string.Empty, script.LinkTo);
            Assert.Equal(LinuxFileMode.S_IROTH | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IRUSR | LinuxFileMode.S_IFREG, script.Mode);
            Assert.Equal("root", script.Owner);
            Assert.False(script.RemoveOnUninstall);
            Assert.Equal(Path.Combine("archive", "script.sh"), script.SourceFilename);
            Assert.Equal("/opt/demo/script.sh", script.TargetPath);
            Assert.Equal("/opt/demo/script.sh", script.TargetPathWithFinalSlash);
            Assert.Equal(ArchiveEntryType.None, script.Type);

            var symlink = entries[2];

            Assert.Equal("root", symlink.Group);
            Assert.Equal(3L, symlink.Inode);
            Assert.False(symlink.IsAscii);
            Assert.Equal("/opt/demo/demo", symlink.LinkTo);
            Assert.Equal(LinuxFileMode.S_IXOTH | LinuxFileMode.S_IROTH | LinuxFileMode.S_IXGRP | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IXUSR | LinuxFileMode.S_IWUSR | LinuxFileMode.S_IRUSR | LinuxFileMode.S_IFLNK, symlink.Mode);
            Assert.Equal("root", symlink.Owner);
            Assert.False(symlink.RemoveOnUninstall);
            Assert.Null(symlink.SourceFilename);
            Assert.Equal("/usr/local/bin/demo", symlink.TargetPath);
            Assert.Equal("/usr/local/bin/demo", symlink.TargetPathWithFinalSlash);
            Assert.Equal(ArchiveEntryType.None, symlink.Type);
        }
コード例 #8
0
        private string CreateMetsFile(ArchiveMetadata metadata)
        {
            string workingDirectory = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\TestData\\Metadata\\DiasMetsCreator";

            Archive archive = new ArchiveBuilder()
                              .WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot(workingDirectory)
                              .Build();

            new DiasMetsCreator().CreateAndSaveFile(archive, metadata);

            string metsFilePath = Path.Combine(workingDirectory, "dias-mets.xml");

            return(metsFilePath);
        }
コード例 #9
0
        public void ShouldSaveCreatedDiasMetsFileToDisk()
        {
            string workingDirectory = $"{AppDomain.CurrentDomain.BaseDirectory}\\TestData\\Metadata\\DiasMetsCreator";

            Archive archive = new ArchiveBuilder()
                              .WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot(workingDirectory)
                              .Build();

            new DiasMetsCreator().CreateAndSaveFile(archive, ArchiveMetadata);

            string metsFilePath = Path.Combine(workingDirectory, "dias-mets.xml");

            File.Exists(metsFilePath).Should().BeTrue();
        }
コード例 #10
0
        private string CreateMetsFile(ArchiveMetadata metadata)
        {
            string workingDirectory = $"{AppDomain.CurrentDomain.BaseDirectory}\\TestData\\Metadata\\DiasMetsCreator";

            Archive archive = new ArchiveBuilder()
                              .WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot(workingDirectory)
                              .Build();

            new DiasMetsCreator().CreateAndSaveFile(archive, metadata);

            string metsFilePath = Path.Combine(workingDirectory, "dias-mets.xml");

            return(metsFilePath);
        }
コード例 #11
0
ファイル: InfoXmlCreatorTest.cs プロジェクト: palm72/arkade5
        public void ShouldSaveCreatedInfoXmlFileToDisk()
        {
            string workingDirectory = $"{AppDomain.CurrentDomain.BaseDirectory}\\TestData\\Metadata\\InfoXmlCreator";

            Archive archive = new ArchiveBuilder()
                              .WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot(workingDirectory)
                              .Build();

            new InfoXmlCreator().CreateAndSaveFile(archive, ArchiveMetadata);

            string infoXmlFilePath = archive.GetInfoXmlFileName().FullName;

            File.Exists(infoXmlFilePath).Should().BeTrue();
        }
コード例 #12
0
        public void FromDirectoryWithMetadataTest()
        {
            ArchiveBuilder builder = new ArchiveBuilder();

            Dictionary <string, string> metadata = new Dictionary <string, string>()
            {
                { "CopyToPublishDirectory", "Always" },
                { "LinuxPath", "/bin/script.sh" },
                { "LinuxFileMode", "755" },
            };

            var taskItem  = new TaskItem("script.sh", metadata);
            var taskItems = new ITaskItem[] { taskItem };
            var entries   = builder.FromDirectory("archive", "/opt/demo", taskItems);

            Assert.Equal(2, entries.Count);

            var readme = entries[0];

            Assert.Equal("root", readme.Group);
            Assert.Equal(1L, readme.Inode);
            Assert.False(readme.IsAscii);
            Assert.Equal(string.Empty, readme.LinkTo);
            Assert.Equal(LinuxFileMode.S_IROTH | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IRUSR | LinuxFileMode.S_IFREG, readme.Mode);
            Assert.Equal("root", readme.Owner);
            Assert.False(readme.RemoveOnUninstall);
            Assert.Equal("archive\\README.md", readme.SourceFilename);
            Assert.Equal("/opt/demo/README.md", readme.TargetPath);
            Assert.Equal("/opt/demo/README.md", readme.TargetPathWithFinalSlash);
            Assert.Equal(ArchiveEntryType.None, readme.Type);

            var script = entries[1];

            Assert.Equal("root", script.Group);
            Assert.Equal(2L, script.Inode);
            Assert.False(script.IsAscii);
            Assert.Equal(string.Empty, script.LinkTo);

            // -rwxr-xr-x
            Assert.Equal(LinuxFileMode.S_IXOTH | LinuxFileMode.S_IROTH | LinuxFileMode.S_IXGRP | LinuxFileMode.S_IRGRP | LinuxFileMode.S_IXUSR | LinuxFileMode.S_IWUSR | LinuxFileMode.S_IRUSR, script.Mode);
            Assert.Equal("root", script.Owner);
            Assert.False(script.RemoveOnUninstall);
            Assert.Equal("archive\\script.sh", script.SourceFilename);
            Assert.Equal("/bin/script.sh", script.TargetPath);
            Assert.Equal("/bin/script.sh", script.TargetPathWithFinalSlash);
            Assert.Equal(ArchiveEntryType.None, script.Type);
        }
コード例 #13
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Archive>((path) => Data.Save(path));
            RegisterReplaceHandler <Archive>((path) => new Archive(path));
            RegisterAddHandler <Stream>((path) => Nodes.Add(DataViewNodeFactory.Create(path)));
            RegisterModelUpdateHandler(() =>
            {
                var builder = new ArchiveBuilder();

                foreach (DataViewNode node in Nodes)
                {
                    builder.AddFile(node.Text, ModuleExportUtilities.CreateStream(node.Data));
                }

                return(builder.Build());
            });
        }
コード例 #14
0
        public override ExitCode Execute()
        {
            string outputArchive = AdditionalArgs[1];
            string mimeType      = (AdditionalArgs.Count == 3) ? AdditionalArgs[3] : Archive.GuessMimeType(outputArchive);

            var    digest          = new ManifestDigest(AdditionalArgs[0]);
            string?sourceDirectory = ImplementationStore.GetPath(digest);

            if (sourceDirectory == null)
            {
                throw new ImplementationNotFoundException(digest);
            }

            using var builder = ArchiveBuilder.Create(outputArchive, mimeType);
            Handler.RunTask(new ReadDirectory(sourceDirectory, builder));

            return(ExitCode.OK);
        }
コード例 #15
0
        public void CreatePackageMetadata()
        {
            using (Stream stream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm"))
            {
                var originalPackage = RpmPackageReader.Read(stream);

                using (var payloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                    using (var cpio = new CpioFile(payloadStream, false))
                    {
                        ArchiveBuilder    builder = new ArchiveBuilder(new PlistFileAnalyzer());
                        RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer());
                        var entries = builder.FromCpio(cpio);
                        var files   = creator.CreateFiles(entries);

                        // Core routine to populate files and dependencies
                        RpmPackage package  = new RpmPackage();
                        var        metadata = new PublicRpmMetadata(package);
                        metadata.Name    = "libplist";
                        metadata.Version = "2.0.1.151";
                        metadata.Arch    = "x86_64";
                        metadata.Release = "1.1";

                        creator.AddPackageProvides(metadata);
                        creator.AddLdDependencies(metadata);

                        metadata.Files = files;
                        creator.AddRpmDependencies(metadata, null);

                        PlistMetadata.ApplyDefaultMetadata(metadata);

                        metadata.Size = 0x26e6d;
                        metadata.ImmutableRegionSize = -976;

                        foreach (var record in originalPackage.Header.Records)
                        {
                            this.AssertTagEqual(record.Key, originalPackage, package);
                        }
                    }
            }
        }
コード例 #16
0
ファイル: Archives.cs プロジェクト: gregdivis/Aeon
        public void BuildArchive()
        {
            using var builder = new ArchiveBuilder();
            foreach (var fileName in Directory.EnumerateFiles(@"C:\DOS\16\KEEN4"))
            {
                builder.AddFile(fileName, Path.GetFileName(fileName));
            }

            using var outputStream = new MemoryStream();
            builder.Write(outputStream);

            outputStream.Position = 0;
            using var reader      = new ArchiveFile(outputStream);
            foreach (var fileName in Directory.EnumerateFiles(@"C:\DOS\16\KEEN4"))
            {
                using (var f = File.OpenRead(fileName))
                    using (var a = reader.OpenItem(Path.GetFileName(fileName)))
                    {
                        Assert.IsTrue(StreamsEqual(f, a));
                    }
            }
        }
コード例 #17
0
ファイル: ArchiveViewNode.cs プロジェクト: TekkaGB/GFD-Studio
        protected override void InitializeCore()
        {
            RegisterExportHandler <Archive>((path) => Data.Save(path));
            RegisterReplaceHandler <Archive>((path) => new Archive(path));
            RegisterAddHandler <Stream>((path) => AddChildNode(DataViewNodeFactory.Create(path)));
            RegisterModelUpdateHandler(() =>
            {
                var builder = new ArchiveBuilder();

                foreach (DataViewNode node in Nodes)
                {
                    builder.AddFile(node.Text, ModuleExportUtilities.CreateStream(node.Data));
                }

                return(builder.Build());
            });
            RegisterCustomHandler("Export", "All", () =>
            {
                var dialog = new VistaFolderBrowserDialog();
                {
                    if (dialog.ShowDialog() != true)
                    {
                        return;
                    }

                    foreach (DataViewNode node in Nodes)
                    {
                        // Hack for field texture archives: prefer DDS output format
                        Type type = null;
                        if (node.DataType == typeof(FieldTexturePS3) || node.DataType == typeof(GNFTexture))
                        {
                            type = typeof(DDSStream);
                        }

                        node.Export(Path.Combine(dialog.SelectedPath, node.Text), type);
                    }
                }
            });
        }
コード例 #18
0
        public void ShouldRaiseWarningWithDocumentedUpcomingDisposalsFalseAndActualUpcomingDisposalsTrue()
        {
            XmlElementHelper helper = new XmlElementHelper()
                                      .Add("arkiv",
                                           new XmlElementHelper()
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_1")
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("kassasjon", string.Empty))))))));


            // Creating a test archive stating that it should not contain any disposal resolutions:
            var testArchive = new ArchiveBuilder().WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot("TestData\\Noark5\\MetaDataTesting\\BooleansFalse").Build();

            TestRun testRun = helper.RunEventsOnTest(new N5_44_NumberOfDisposalResolutions(testArchive));

            testRun.Results.First().Message.Should().Be("Totalt: 1");
            testRun.Results.Should()
            .Contain(r => r.Message.Equals("Kassasjonsvedtak i dokumentbeskrivelse - Antall: 1"));

            testRun.Results.Should().Contain(r =>
                                             r.IsError() && r.Message.Equals(
                                                 "Det er angitt at uttrekket ikke skal inneholde kassasjonsvedtak, men kassasjonsvedtak ble funnet"
                                                 ) && r.Location.ToString().Equals("arkivuttrekk.xml"));

            testRun.Results.Count.Should().Be(3);
        }
コード例 #19
0
        public void ShouldRaiseWarningWithDocumentedRestrictionsFalseAndActualRestrictionsTrue()
        {
            XmlElementHelper helper = new XmlElementHelper()
                                      .Add("arkiv",
                                           new XmlElementHelper()
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_1")
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("skjerming", string.Empty))))))));


            // Creating a test archive stating that it should not contain any restrictions:
            var testArchive = new ArchiveBuilder().WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot("TestData/Noark5/MetaDataTesting/BooleansFalse").Build();

            TestRun testRun = helper.RunEventsOnTest(new NumberOfRestrictions(testArchive));

            testRun.Results.Should()
            .Contain(r => r.Message.Equals("Skjerminger i dokumentbeskrivelse - Antall: 1"));

            testRun.Results.Should().Contain(r =>
                                             r.IsError() && r.Message.Equals(
                                                 "Det er angitt at uttrekket ikke skal inneholde skjerminger, men skjerminger ble funnet"
                                                 ) && r.Location.ToString().Equals("arkivuttrekk.xml"));

            testRun.Results.Count.Should().Be(2);
        }
コード例 #20
0
        public void ShouldRaiseWarningWithDocumentedExecutedDisposalsFalseAndActualExecutedDisposalsTrue()
        {
            XmlElementHelper helper = new XmlElementHelper()
                                      .Add("arkiv",
                                           new XmlElementHelper()
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_1")
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("utfoertKassasjon", string.Empty))))))));


            // Creating a test archive stating that it should not contain any executed disposals
            var testArchive = new ArchiveBuilder().WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot("TestData\\Noark5\\MetaDataTesting\\BooleansFalse").Build();

            TestRun testRun = helper.RunEventsOnTest(new N5_45_NumberOfDisposalsExecuted(testArchive));

            testRun.Results.First().Message.Should().Be("Totalt: 1");
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Totalt: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Det er dokumentert at uttrekket ikke skal omfatte utførte kassasjoner, men utførte kassasjoner ble funnet"
                                                 ));
            testRun.Results.Count.Should().Be(3);
        }
コード例 #21
0
        public static void HandlerItem(bool dev, PublishDirInfo item)
        {
            var rpmPath = GetPackPath(dev, item, FileEx.RPM);

            //var cpioPath = GetPackPath(item, FileEx.CPIO);

            using var targetStream = File.Open(rpmPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            //using var cpioStream = File.Open(cpioPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            using var cpioStream = new MemoryStream();

            ArchiveBuilder2 archiveBuilder2 = new()
            {
                Log = TaskLoggingHelper.Instance,
            };
            ArchiveBuilder archiveBuilder = archiveBuilder2;

            var archiveEntries = archiveBuilder.FromDirectory(
                item.Path,
                Constants.HARDCODED_APP_NAME,
                LinuxPackConstants.Prefix,
                Array.Empty <ITaskItem>());

            LinuxPackConstants.AddFileNameDesktop(archiveBuilder2, archiveEntries);

            //archiveEntries.AddRange(archiveBuilder.FromLinuxFolders(this.LinuxFolders));

            archiveEntries = archiveEntries
                             .OrderBy(e => e.TargetPathWithFinalSlash, StringComparer.Ordinal)
                             .ToList();

            CpioFileCreator cpioCreator = new CpioFileCreator();

            cpioCreator.FromArchiveEntries(
                archiveEntries,
                cpioStream);
            cpioStream.Position = 0;

            // Prepare the list of dependencies
            List <PackageDependency> dependencies = new List <PackageDependency>();

            if (item.DeploymentMode == DeploymentMode.FDE)
            {
                dependencies.Add(new PackageDependency {
                    Name = LinuxPackConstants.aspnetcore_runtime_6_0
                });
            }

            //if (this.RpmDotNetDependencies != null)
            //{
            //    dependencies.AddRange(
            //        this.RpmDotNetDependencies.Select(
            //            d => GetPackageDependency(d)));
            //}

            //if (this.RpmDependencies != null)
            //{
            //    dependencies.AddRange(
            //        this.RpmDependencies.Select(
            //            d => GetPackageDependency(d)));
            //}

            RpmPackageCreator rpmCreator = new RpmPackageCreator();

            rpmCreator.CreatePackage(
                archiveEntries,
                cpioStream,
                LinuxPackConstants.PackageName,
                Utils.GetVersion(dev),
                RpmTask.GetPackageArchitecture(item.Name),
                LinuxPackConstants.Release,
                LinuxPackConstants.CreateUser,
                LinuxPackConstants.UserName,
                LinuxPackConstants.InstallService,
                LinuxPackConstants.ServiceName,
                LinuxPackConstants.RpmVendor,
                LinuxPackConstants.Description,
                LinuxPackConstants.Url,
                LinuxPackConstants.Prefix,
                LinuxPackConstants.PreInstallScript,
                LinuxPackConstants.PostInstallScript,
                LinuxPackConstants.PreRemoveScript,
                LinuxPackConstants.PostRemoveScript,
                dependencies,
                null !,
                privateKey !,
                targetStream);
        }
コード例 #22
0
        public void CreatePackageBinaryTest()
        {
            var pgpSignatureData = File.ReadAllBytes("Rpm/RpmSigTag_Pgp.bin");
            var rsaSignatureData = File.ReadAllBytes("Rpm/RpmSigTag_Rsa.bin");

            var signer = new DummySigner();

            signer.Add("D72D1E8A9326431472A1E39E1B7916AD07CCC31B", rsaSignatureData);
            signer.Add("A0A33779FBBED565A15FA85BAFBD1473E00F1257", pgpSignatureData);
            signer.Add("5E24172F773FEB67FC0BF4831BB4E8A75B4554EF", pgpSignatureData);

            using (Stream stream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm"))
                using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateBinaryTest.rpm", FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    var originalPackage         = RpmPackageReader.Read(stream);
                    List <ArchiveEntry> archive = null;

                    using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                        using (CpioFile cpio = new CpioFile(decompressedPayloadStream, leaveOpen: false))
                        {
                            ArchiveBuilder builder = new ArchiveBuilder();
                            archive = builder.FromCpio(cpio);
                        }

                    using (var compressedPayloadStream = RpmPayloadReader.GetCompressedPayloadStream(originalPackage))
                    {
                        RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer());
                        creator.CreatePackage(
                            archive,
                            compressedPayloadStream,
                            "libplist",
                            "2.0.1.151",
                            "x86_64",
                            "1.1",
                            false,
                            null,
                            false,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            (metadata) => PlistMetadata.ApplyDefaultMetadata(metadata),
                            signer,
                            targetStream,
                            includeVersionInName: true,
                            payloadIsCompressed: true);
                    }
                }

            using (var originalStream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm"))
                using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateBinaryTest.rpm", FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    var originalPackage = RpmPackageReader.Read(originalStream);
                    var package         = RpmPackageReader.Read(targetStream);

                    RpmDumper.Dump(originalPackage, "RpmPackageCreatorTests_CreateBinaryTest_original.txt");
                    RpmDumper.Dump(package, "RpmPackageCreatorTests_CreateBinaryTest_reconstructed.txt");

                    var metadata  = new RpmMetadata(package);
                    var signature = new RpmSignature(package);

                    foreach (var record in originalPackage.Signature.Records)
                    {
                        this.AssertTagEqual(record.Key, originalPackage, package);
                    }

                    originalStream.Position = 0;
                    targetStream.Position   = 0;

                    int    index          = 0;
                    byte[] originalBuffer = new byte[1024];
                    byte[] targetBuffer   = new byte[1024];

                    while (originalStream.Position < originalStream.Length)
                    {
                        originalStream.Read(originalBuffer, 0, originalBuffer.Length);
                        targetStream.Read(targetBuffer, 0, targetBuffer.Length);

                        Assert.Equal(originalBuffer, targetBuffer);

                        index += originalBuffer.Length;
                    }
                }
        }
コード例 #23
0
        public void CreatePackageTest()
        {
            var          krgen            = PgpSigner.GenerateKeyRingGenerator("dotnet", "dotnet");
            var          secretKeyRing    = krgen.GenerateSecretKeyRing();
            var          privateKey       = secretKeyRing.GetSecretKey().ExtractPrivateKey("dotnet".ToCharArray());
            var          publicKey        = secretKeyRing.GetPublicKey();
            const string preInstScript    = "echo preinst\n";
            const string postInstScript   = "echo postinst\n";
            const string preRemoveScript  = "echo preremove\n";
            const string postRemoveScript = "echo postremove\n";
            const string nameString       = "libplist";
            const string versionString    = "2.0.1.151";
            const string releaseString    = "1.1";
            const string archString       = "x86_64";

            using (Stream stream = File.OpenRead($"Rpm/{nameString}-{versionString}-{releaseString}.{archString}.rpm"))
                using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateTest.rpm", FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    var originalPackage         = RpmPackageReader.Read(stream);
                    List <ArchiveEntry> archive = null;

                    using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                        using (CpioFile cpio = new CpioFile(decompressedPayloadStream, leaveOpen: false))
                        {
                            ArchiveBuilder builder = new ArchiveBuilder();
                            archive = builder.FromCpio(cpio);
                        }

                    using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                        using (var payloadStream = new MemoryStream())
                        {
                            decompressedPayloadStream.CopyTo(payloadStream);
                            payloadStream.Position = 0;

                            RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer());
                            creator.CreatePackage(
                                archive,
                                payloadStream,
                                nameString,
                                versionString,
                                archString,
                                releaseString,
                                false,
                                null,
                                false,
                                null,
                                null,
                                preInstScript,
                                postInstScript,
                                preRemoveScript,
                                postRemoveScript,
                                null,
                                (metadata) => PlistMetadata.ApplyDefaultMetadata(metadata),
                                privateKey,
                                targetStream);
                        }
                }

            using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateTest.rpm", FileMode.Open, FileAccess.Read, FileShare.None))
            {
                var package = RpmPackageReader.Read(targetStream);

                var metadata = new RpmMetadata(package);
                Assert.Equal(metadata.Version, versionString);
                Assert.Equal(metadata.Name, nameString);
                Assert.Equal(metadata.Arch, archString);
                Assert.Equal(metadata.Release, releaseString);
                Assert.StartsWith(preInstScript, metadata.PreIn);
                Assert.StartsWith(postInstScript, metadata.PostIn);
                Assert.StartsWith(preRemoveScript, metadata.PreUn);
                Assert.StartsWith(postRemoveScript, metadata.PostUn);
                var signature = new RpmSignature(package);

                Assert.True(signature.Verify(publicKey));
            }
        }
コード例 #24
0
        public void CalculateSignatureTest()
        {
            using (Stream stream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm"))
            {
                var originalPackage = RpmPackageReader.Read(stream);

                RpmPackageCreator    creator = new RpmPackageCreator(new PlistFileAnalyzer());
                Collection <RpmFile> files;

                using (var payloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                    using (var cpio = new CpioFile(payloadStream, false))
                    {
                        ArchiveBuilder builder = new ArchiveBuilder(new PlistFileAnalyzer());
                        var            entries = builder.FromCpio(cpio);
                        files = creator.CreateFiles(entries);
                    }

                // Core routine to populate files and dependencies
                RpmPackage package  = new RpmPackage();
                var        metadata = new PublicRpmMetadata(package);
                metadata.Name    = "libplist";
                metadata.Version = "2.0.1.151";
                metadata.Arch    = "x86_64";
                metadata.Release = "1.1";

                creator.AddPackageProvides(metadata);
                creator.AddLdDependencies(metadata);

                metadata.Files = files;
                creator.AddRpmDependencies(metadata, null);

                PlistMetadata.ApplyDefaultMetadata(metadata);

                creator.CalculateHeaderOffsets(package);

                // Make sure the header is really correct
                using (Stream originalHeaderStream = new SubStream(
                           originalPackage.Stream,
                           originalPackage.HeaderOffset,
                           originalPackage.PayloadOffset - originalPackage.HeaderOffset,
                           leaveParentOpen: true,
                           readOnly: true))
                    using (Stream headerStream = creator.GetHeaderStream(package))
                    {
                        byte[] originalData = new byte[originalHeaderStream.Length];
                        originalHeaderStream.Read(originalData, 0, originalData.Length);

                        byte[] data = new byte[headerStream.Length];
                        headerStream.Read(data, 0, data.Length);

                        int      delta     = 0;
                        int      dataDelta = 0;
                        IndexTag tag;
                        for (int i = 0; i < data.Length; i++)
                        {
                            if (originalData[i] != data[i])
                            {
                                delta     = i;
                                dataDelta = delta - package.Header.Records.Count * Marshal.SizeOf <IndexHeader>();
                                tag       = package.Header.Records.OrderBy(r => r.Value.Header.Offset).Last(r => r.Value.Header.Offset <= dataDelta).Key;

                                break;
                            }
                        }

                        Assert.Equal(originalData, data);
                    }

                var krgen         = PgpSigner.GenerateKeyRingGenerator("dotnet", "dotnet");
                var secretKeyRing = krgen.GenerateSecretKeyRing();
                var privateKey    = secretKeyRing.GetSecretKey().ExtractPrivateKey("dotnet".ToCharArray());

                using (var payload = RpmPayloadReader.GetCompressedPayloadStream(originalPackage))
                {
                    // Header should be OK now (see previous test), so now get the signature block and the
                    // trailer
                    creator.CalculateSignature(package, privateKey, payload);
                    creator.CalculateSignatureOffsets(package);

                    foreach (var record in originalPackage.Signature.Records)
                    {
                        if (record.Key == SignatureTag.RPMTAG_HEADERSIGNATURES)
                        {
                            continue;
                        }

                        this.AssertTagEqual(record.Key, originalPackage, package);
                    }

                    this.AssertTagEqual(SignatureTag.RPMTAG_HEADERSIGNATURES, originalPackage, package);
                }
            }
        }
コード例 #25
0
        public static void HandlerItem(bool dev, PublishDirInfo item)
        {
            var debPath = GetPackPath(dev, item, FileEx.DEB);
            //var debTarPath = GetPackPath(item, FileEx.DEB_TAR);
            var debTarXzPath = GetPackPath(dev, item, FileEx.DEB_TAR_XZ);

            using var targetStream = File.Open(debPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            //using var tarStream = File.Open(debTarPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            using var tarStream = new MemoryStream();

            ArchiveBuilder2 archiveBuilder2 = new()
            {
                Log = TaskLoggingHelper.Instance,
            };
            ArchiveBuilder archiveBuilder = archiveBuilder2;

            var archiveEntries = archiveBuilder.FromDirectory(
                item.Path,
                Constants.HARDCODED_APP_NAME,
                LinuxPackConstants.Prefix,
                Array.Empty <ITaskItem>());

            LinuxPackConstants.AddFileNameDesktop(archiveBuilder2, archiveEntries);

            //archiveEntries.AddRange(archiveBuilder.FromLinuxFolders(this.LinuxFolders));
            DebTask.EnsureDirectories(archiveEntries);

            archiveEntries = archiveEntries
                             .OrderBy(e => e.TargetPathWithFinalSlash, StringComparer.Ordinal)
                             .ToList();

            TarFileCreator.FromArchiveEntries(archiveEntries, tarStream);
            tarStream.Position = 0;

            // Prepare the list of dependencies
            List <string> dependencies = new List <string>();

            if (item.DeploymentMode == DeploymentMode.FDE)
            {
                dependencies.Add(LinuxPackConstants.aspnetcore_runtime_6_0);
            }

            //if (this.DebDependencies != null)
            //{
            //    var debDependencies = this.DebDependencies.Select(d => d.ItemSpec).ToArray();

            //    dependencies.AddRange(debDependencies);
            //}

            //if (this.DebDotNetDependencies != null)
            //{
            //    var debDotNetDependencies = this.DebDotNetDependencies.Select(d => d.ItemSpec).ToArray();

            //    dependencies.AddRange(debDotNetDependencies);
            //}

            // Prepare the list of recommended dependencies
            List <string> recommends = new List <string>();

            //if (this.DebRecommends != null)
            //{
            //    recommends.AddRange(this.DebRecommends.Select(d => d.ItemSpec));
            //}

            // XZOutputStream class has low quality (doesn't even know it's current position,
            // needs to be disposed to finish compression, etc),
            // So we are doing compression in a separate step
            using (var tarXzStream = File.Open(debTarXzPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                using (var xzStream = new XZOutputStream(tarXzStream, XZOutputStream.DefaultThreads, XZOutputStream.DefaultPreset, true))
                {
                    tarStream.CopyTo(xzStream);
                }

            using (var tarXzStream = File.Open(debTarXzPath, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                var pkg = DebPackageCreator.BuildDebPackage(
                    archiveEntries,
                    LinuxPackConstants.PackageName,
                    LinuxPackConstants.Description,
                    LinuxPackConstants.DebMaintainer,
                    Utils.GetVersion(dev),
                    DebTask.GetPackageArchitecture(item.Name),
                    LinuxPackConstants.CreateUser,
                    LinuxPackConstants.UserName,
                    LinuxPackConstants.InstallService,
                    LinuxPackConstants.ServiceName,
                    LinuxPackConstants.Prefix,
                    //LinuxPackConstants.DebSection,
                    "utils",
                    LinuxPackConstants.DebPriority,
                    LinuxPackConstants.DebHomepage,
                    LinuxPackConstants.PreInstallScript,
                    LinuxPackConstants.PostInstallScript,
                    LinuxPackConstants.PreRemoveScript,
                    LinuxPackConstants.PostRemoveScript,
                    dependencies,
                    recommends,
                    null !);

                DebPackageCreator.WriteDebPackage(
                    archiveEntries,
                    tarXzStream,
                    targetStream,
                    pkg);
            }

            File.Delete(debTarXzPath);
        }
コード例 #26
0
        public void SetFilesTest()
        {
            using (Stream stream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm"))
            {
                var originalPackage = RpmPackageReader.Read(stream);
                var package         = new RpmPackage();

                using (var payloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage))
                    using (var cpio = new CpioFile(payloadStream, false))
                    {
                        ArchiveBuilder    builder = new ArchiveBuilder(new PlistFileAnalyzer());
                        RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer());
                        var entries = builder.FromCpio(cpio);
                        var files   = creator.CreateFiles(entries);

                        var metadata = new PublicRpmMetadata(package);
                        metadata.Name    = "libplist";
                        metadata.Version = "2.0.1.151";
                        metadata.Arch    = "x86_64";
                        metadata.Release = "1.1";

                        creator.AddPackageProvides(metadata);
                        creator.AddLdDependencies(metadata);

                        metadata.Files = files;
                        creator.AddRpmDependencies(metadata, null);

                        this.AssertTagEqual(IndexTag.RPMTAG_FILESIZES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEMODES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILERDEVS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEMTIMES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEDIGESTS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILELINKTOS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEFLAGS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEUSERNAME, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEGROUPNAME, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEVERIFYFLAGS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEDEVICES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEINODES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILELANGS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILECOLORS, originalPackage, package);

                        this.AssertTagEqual(IndexTag.RPMTAG_FILECLASS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_CLASSDICT, originalPackage, package);

                        this.AssertTagEqual(IndexTag.RPMTAG_BASENAMES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_DIRINDEXES, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_DIRNAMES, originalPackage, package);

                        // The require and provides records contain file dependencies, as well as package dependencies.
                        // That's why there's a call to AddLdDependencies and AddRpmDependencies, to make sure
                        // these dependencies are written out in order.
                        this.AssertTagEqual(IndexTag.RPMTAG_REQUIRENAME, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_REQUIREFLAGS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_REQUIREVERSION, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_PROVIDENAME, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_PROVIDEFLAGS, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_REQUIREVERSION, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEDEPENDSN, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_FILEDEPENDSX, originalPackage, package);
                        this.AssertTagEqual(IndexTag.RPMTAG_DEPENDSDICT, originalPackage, package);
                    }
            }
        }
コード例 #27
0
        public void HasSeverealRestrictionsOnSeveralArchiveParts()
        {
            XmlElementHelper helper = new XmlElementHelper()
                                      .Add("arkiv",
                                           new XmlElementHelper()
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_1")
                                                .Add("skjerming", string.Empty)
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("skjerming", string.Empty)
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("skjerming", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("skjerming", string.Empty)
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("skjerming", string.Empty))))
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("skjerming", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("skjerming", string.Empty)))))))
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_2")
                                                .Add("skjerming", string.Empty)
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("skjerming", string.Empty)
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("skjerming", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("skjerming", string.Empty)
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("skjerming", string.Empty))))
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("skjerming", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("skjerming", string.Empty))))))));

            // Creating a test archive stating that it should contain restrictions:
            var testArchive = new ArchiveBuilder().WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot("TestData\\Noark5\\MetaDataTesting\\BooleansTrue").Build();

            TestRun testRun = helper.RunEventsOnTest(new N5_42_NumberOfRestrictions(testArchive));


            testRun.Results.First().Message.Should().Be("Totalt: 14");
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Skjerminger i arkivdel - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Skjerminger i klasse - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Skjerminger i mappe - Antall: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Skjerminger i registrering - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Skjerminger i dokumentbeskrivelse - Antall: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Skjerminger i arkivdel - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Skjerminger i klasse - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Skjerminger i mappe - Antall: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Skjerminger i registrering - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Skjerminger i dokumentbeskrivelse - Antall: 2"
                                                 ));
            testRun.Results.Count.Should().Be(11);
        }
コード例 #28
0
        public void HasSeverealDisposalResolutionsOnSeveralArchiveParts()
        {
            XmlElementHelper helper = new XmlElementHelper()
                                      .Add("arkiv",
                                           new XmlElementHelper()
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_1")
                                                .Add("kassasjon", string.Empty)
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("kassasjon", string.Empty)
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("kassasjon", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("kassasjon", string.Empty)
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("kassasjon", string.Empty))))
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("kassasjon", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("kassasjon", string.Empty)))))))
                                           .Add("arkivdel",
                                                new XmlElementHelper()
                                                .Add("systemID", "someArchivePartSystemId_2")
                                                .Add("kassasjon", string.Empty)
                                                .Add("klassifikasjonssystem",
                                                     new XmlElementHelper()
                                                     .Add("klasse",
                                                          new XmlElementHelper()
                                                          .Add("kassasjon", string.Empty)
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("kassasjon", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("kassasjon", string.Empty)
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("kassasjon", string.Empty))))
                                                          .Add("mappe",
                                                               new XmlElementHelper()
                                                               .Add("kassasjon", string.Empty)
                                                               .Add("registrering",
                                                                    new XmlElementHelper()
                                                                    .Add("dokumentbeskrivelse",
                                                                         new XmlElementHelper()
                                                                         .Add("kassasjon", string.Empty))))))));

            // Creating a test archive stating that it should contain disposal resolutions:
            var testArchive = new ArchiveBuilder().WithArchiveType(ArchiveType.Noark5)
                              .WithWorkingDirectoryRoot("TestData/Noark5/MetaDataTesting/BooleansTrue").Build();

            TestRun testRun = helper.RunEventsOnTest(new NumberOfDisposalResolutions(testArchive));

            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Kassasjonsvedtak i arkivdel - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Kassasjonsvedtak i klasse - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Kassasjonsvedtak i mappe - Antall: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Kassasjonsvedtak i registrering - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_1 - Kassasjonsvedtak i dokumentbeskrivelse - Antall: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Kassasjonsvedtak i arkivdel - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Kassasjonsvedtak i klasse - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Kassasjonsvedtak i mappe - Antall: 2"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Kassasjonsvedtak i registrering - Antall: 1"
                                                 ));
            testRun.Results.Should().Contain(r => r.Message.Equals(
                                                 "Arkivdel (systemID): someArchivePartSystemId_2 - Kassasjonsvedtak i dokumentbeskrivelse - Antall: 2"
                                                 ));
            testRun.Results.Count.Should().Be(10);
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: gregdivis/Aeon
        public static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: aeonpack <AeonConfig> <PackageName>");
                return(1);
            }

            var archiveBuilder = new ArchiveBuilder();

            var config = AeonConfiguration.Load(args[0]);

            archiveBuilder.AddFile(GetArchiveConfigStream(config), "Archive.AeonConfig");

            int isoIndex = 1;

            foreach (var drive in config.Drives)
            {
                var driveConfig = drive.Value;
                if (!string.IsNullOrEmpty(driveConfig.HostPath))
                {
                    int hostPathLength = driveConfig.HostPath.Length;
                    if (!driveConfig.HostPath.EndsWith('\\') && !driveConfig.HostPath.EndsWith('/'))
                    {
                        hostPathLength++;
                    }

                    var drivePrefix = drive.Key.ToUpperInvariant() + ":\\";

                    foreach (var sourceFileName in Directory.EnumerateFiles(driveConfig.HostPath, "*", SearchOption.AllDirectories))
                    {
                        var destPath = getArchivePath(sourceFileName);
                        if (destPath != null)
                        {
                            Console.WriteLine($"Adding {sourceFileName} => {destPath}...");
                            archiveBuilder.AddFile(sourceFileName, destPath);
                        }
                    }

                    string getArchivePath(string srcPath)
                    {
                        var relativePath = srcPath.Substring(hostPathLength).Trim('\\', '/');
                        var pathParts    = relativePath.Split(Path.DirectorySeparatorChar);

                        if (!pathParts.All(Valid83PathRegex.IsMatch))
                        {
                            return(null);
                        }

                        return(drivePrefix + relativePath.ToUpperInvariant());
                    }
                }
                else if (!string.IsNullOrWhiteSpace(drive.Value.ImagePath))
                {
                    archiveBuilder.AddFile(drive.Value.ImagePath, $"Image{isoIndex}.iso");
                    isoIndex++;
                }
                else
                {
                    throw new InvalidDataException();
                }
            }

            Console.WriteLine($"Writing {args[1]}...");
            using var outputStream = File.Create(args[1]);
            Console.CursorVisible  = false;
            archiveBuilder.Write(outputStream, new BuilderProgress(archiveBuilder.DataCount));
            Console.CursorVisible = true;

            return(0);
        }