Exemplo n.º 1
0
        public static ArchiveMetadata Create(MetadataExamplePurpose purpose)
        {
            var metadataExample = new ArchiveMetadata
            {
                Id    = "UUID:12345-12345-12345-12345-12345-12345",
                Label = "Some system name (2017 - 2020)",
                ArchiveDescription = "Some archive description",
                AgreementNumber    = "XX 00-0000/0000; 0000-00-00",
                ArchiveCreators    = new List <MetadataEntityInformationUnit>
                {
                    CreateMetadataEntityInformationUnit('1'),
                    CreateMetadataEntityInformationUnit('2')
                },
                Transferer = CreateMetadataEntityInformationUnit('3'),
                Producer   = CreateMetadataEntityInformationUnit('4'),
                Owners     = new List <MetadataEntityInformationUnit>
                {
                    CreateMetadataEntityInformationUnit('5'),
                    CreateMetadataEntityInformationUnit('6')
                },
                Recipient = "Some recipient",
                System    = new MetadataSystemInformationUnit
                {
                    Name        = "Some system name",
                    Version     = "v1.0.0",
                    Type        = "Noark5",
                    TypeVersion = "v3.1"
                },
                ArchiveSystem = new MetadataSystemInformationUnit
                {
                    Name        = "Some archive system name",
                    Version     = "v2.0.0",
                    Type        = "Noark4",
                    TypeVersion = "N/A" // To be ignored by MetsCreator
                },
                PackageType      = PackageType.SubmissionInformationPackage,
                FileDescriptions = new List <FileDescription>
                {
                    new FileDescription
                    {
                        Id             = 1,
                        Name           = "someDirectory\\someFileName.pdf",
                        Extension      = "pdf",
                        Sha256Checksum = "3B29DFCC4286E50B180AF8F21904C86F8AA42A23C4055C3A71D0512F9AE3886F",
                        Size           = 2325452,
                        CreationTime   = new DateTime(2017, 06, 30)
                    }
                },
                StartDate      = new DateTime(2017, 01, 01),
                EndDate        = new DateTime(2020, 01, 01),
                ExtractionDate = new DateTime(2023, 01, 01),
            };

            if (purpose == MetadataExamplePurpose.UserExample)
            {
                AdjustForUserExample(metadataExample);
            }

            return(metadataExample);
        }
Exemplo n.º 2
0
        internal ArchiveFileModel(ArchiveMetadata metadata, ArchivedFolder rootFolder, ImmutableArray <int> sections, ImmutableList <ArchivedFile> files)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            if (rootFolder == null)
            {
                throw new ArgumentNullException(nameof(rootFolder));
            }

            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            if (sections.IsDefault)
            {
                throw new ArgumentNullException(nameof(sections));
            }

            if (sections.Length != metadata.DecoderSections.Length + 1)
            {
                throw new InternalFailureException();
            }

            this.Metadata      = metadata;
            this.RootFolder    = rootFolder;
            this.mSectionFiles = files;
            this.mSections     = sections;
        }
Exemplo n.º 3
0
 public static void HandleLabelPlaceholder(ArchiveMetadata metadata)
 {
     if (metadata.Label != null && metadata.Label.Equals(ArkadeConstants.MetadataStandardLabelPlaceholder))
     {
         metadata.Label = ComposeStandardLabel(metadata.System.Name, metadata.StartDate, metadata.EndDate);
     }
 }
Exemplo n.º 4
0
        private static void CreateAltRecordIDs(metsTypeMetsHdr metsHdr, ArchiveMetadata metadata)
        {
            var altRecordIDs = new List <metsTypeMetsHdrAltRecordID>();

            if (!string.IsNullOrEmpty(metadata.ArchiveDescription))
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID
                {
                    TYPESpecified = true,
                    TYPE          = metsTypeMetsHdrAltRecordIDTYPE.DELIVERYSPECIFICATION,
                    Value         = metadata.ArchiveDescription
                });
            }

            if (!string.IsNullOrEmpty(metadata.AgreementNumber))
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID
                {
                    TYPESpecified = true,
                    TYPE          = metsTypeMetsHdrAltRecordIDTYPE.SUBMISSIONAGREEMENT,
                    Value         = metadata.AgreementNumber
                });
            }

            if (altRecordIDs.Any())
            {
                metsHdr.altRecordID = altRecordIDs.ToArray();
            }
        }
Exemplo n.º 5
0
 private static void LoadMetsHdrAltRecordIDs(ArchiveMetadata archiveMetadata,
                                             metsTypeMetsHdrAltRecordID[] metsHdrAltRecordIds)
 {
     LoadArchiveDescription(archiveMetadata, metsHdrAltRecordIds);
     LoadAgreementNumber(archiveMetadata, metsHdrAltRecordIds);
     LoadStartDate(archiveMetadata, metsHdrAltRecordIds);
     LoadEndDate(archiveMetadata, metsHdrAltRecordIds);
 }
Exemplo n.º 6
0
        private static void LoadEndDate(ArchiveMetadata archiveMetadata,
                                        IEnumerable <metsTypeMetsHdrAltRecordID> metsHdrAltRecordIds)
        {
            string dateValue = metsHdrAltRecordIds.FirstOrDefault(a =>
                                                                  a.TYPE == metsTypeMetsHdrAltRecordIDTYPE.ENDDATE)?.Value;

            archiveMetadata.EndDate = LoadDateOrNull(dateValue);
        }
Exemplo n.º 7
0
        private static ArchiveMetadata CreateExampleData()
        {
            var metadataExample = new ArchiveMetadata
            {
                Id = "UUID:12345-12345-12345-12345-12345-12345",
                ArchiveDescription = "test description",
                StartDate          = new DateTime(2017, 5, 1),
                EndDate            = new DateTime(2017, 8, 31),
                AgreementNumber    = "Agreement number",
                System             = new MetadataSystemInformationUnit
                {
                    Name    = "Example System that supports Noark",
                    Version = "6.0",
                    Type    = "Noark4"
                },
                Transferer = new MetadataEntityInformationUnit
                {
                    Entity        = "Nav Telemark",
                    ContactPerson = "Hans 'The Transferer' Hansen",
                    Email         = "*****@*****.**",
                    Telephone     = "12345678"
                },
                Producer = new MetadataEntityInformationUnit
                {
                    Entity        = "Archive Solution Consulting Company",
                    ContactPerson = "Kari 'The Producer' Olsen",
                    Email         = "*****@*****.**",
                    Telephone     = "12345678"
                },
                ArchiveCreators = new List <MetadataEntityInformationUnit>
                {
                    new MetadataEntityInformationUnit
                    {
                        Entity        = "Arkivverket, seksjon Avlervering",
                        ContactPerson = "John 'The Creator' Johnsen",
                        Email         = "*****@*****.**",
                        Telephone     = "12345678"
                    }
                },
                Owners = new List <MetadataEntityInformationUnit>
                {
                    new MetadataEntityInformationUnit
                    {
                        Entity        = "Nav Telemark",
                        ContactPerson = "Tim 'The Owner' Jensen",
                        Email         = "*****@*****.**",
                        Telephone     = "12345678"
                    }
                },
                Comments = new List <string>()
                {
                    "Comments about the archive"
                },
                History = "A brief history"
            };

            return(metadataExample);
        }
Exemplo n.º 8
0
        private static void LoadRecipient(ArchiveMetadata archiveMetadata, metsTypeMetsHdrAgent[] metsHdrAgents)
        {
            metsTypeMetsHdrAgent metsRecipientAgent = metsHdrAgents.FirstOrDefault(a =>
                                                                                   a.TYPE == metsTypeMetsHdrAgentTYPE.ORGANIZATION &&
                                                                                   a.ROLE == metsTypeMetsHdrAgentROLE.PRESERVATION
                                                                                   );

            archiveMetadata.Recipient = metsRecipientAgent?.name;
        }
Exemplo n.º 9
0
        private void LoadExistingMetsFileAsArchiveMetadata()
        {
            FileInfo diasMetsFile = _testSession.Archive.WorkingDirectory.Root().WithFile(ArkadeConstants.DiasMetsXmlFileName);

            if (diasMetsFile.Exists)
            {
                ArchiveMetadata archiveMetadata = DiasMetsLoader.Load(diasMetsFile.FullName);

                if (archiveMetadata.AgreementNumber != null) // archiveMetadata.ArchiveDescription is not required
                {
                    MetaDataModelArchiveDescription = GuiMetadataMapper.MapToArchiveDescription(
                        archiveMetadata.ArchiveDescription, archiveMetadata.AgreementNumber
                        );
                }

                if (archiveMetadata.ArchiveCreators != null && archiveMetadata.ArchiveCreators.Any())
                {
                    MetaDataArchiveCreators = GuiMetadataMapper.MapToArchiveCreators(archiveMetadata.ArchiveCreators);
                }

                if (archiveMetadata.Transferer != null)
                {
                    MetaDataTransferer = GuiMetadataMapper.MapToTransferer(archiveMetadata.Transferer);
                }

                if (archiveMetadata.Producer != null)
                {
                    MetaDataProducer = GuiMetadataMapper.MapToProducer(archiveMetadata.Producer);
                }

                if (archiveMetadata.Owners != null && archiveMetadata.Owners.Any())
                {
                    MetaDataOwners = GuiMetadataMapper.MapToOwners(archiveMetadata.Owners);
                }

                if (archiveMetadata.Recipient != null)
                {
                    MetaDataRecipient = GuiMetadataMapper.MapToRecipient(archiveMetadata.Recipient);
                }

                if (archiveMetadata.System != null)
                {
                    MetaDataSystem = GuiMetadataMapper.MapToSystem(archiveMetadata.System);
                }

                if (archiveMetadata.ArchiveSystem != null)
                {
                    MetaDataArchiveSystem = GuiMetadataMapper.MapToArchiveSystem(archiveMetadata.ArchiveSystem);
                }

                if (archiveMetadata.Comments != null && archiveMetadata.Comments.Any())
                {
                    MetaDataComments = GuiMetadataMapper.MapToComments(archiveMetadata.Comments);
                }
            }
        }
Exemplo n.º 10
0
 private static void LoadMetsHdrAgents(ArchiveMetadata archiveMetadata, metsTypeMetsHdrAgent[] metsHdrAgents)
 {
     LoadArchiveCreators(archiveMetadata, metsHdrAgents);
     LoadTransferer(archiveMetadata, metsHdrAgents);
     LoadProducer(archiveMetadata, metsHdrAgents);
     LoadOwners(archiveMetadata, metsHdrAgents);
     LoadRecipient(archiveMetadata, metsHdrAgents);
     LoadSystem(archiveMetadata, metsHdrAgents);
     LoadArchiveSystem(archiveMetadata, metsHdrAgents);
 }
Exemplo n.º 11
0
 public premisComplexType Create(Archive archive, ArchiveMetadata metadata)
 {
     return(new premisComplexType()
     {
         @object = new objectComplexType[]
         {
             CreateEntryForTarFile(archive.Uuid)
         }
     });
 }
Exemplo n.º 12
0
 public void Create(Archive archive, ArchiveMetadata metadata)
 {
     _diasMetsCreator.CreateAndSaveFile(archive, metadata);
     _diasPremisCreator.CreateAndSaveFile(archive, metadata);
     // EAD is not included in v1.0
     _eadCreator.CreateAndSaveFile(archive, metadata);
     // EAC-CPF is not included in v1.0
     _eacCpfCreator.CreateAndSaveFile(archive, metadata);
     CopyDiasMetsXsdToRootDirectory(archive.WorkingDirectory);
 }
Exemplo n.º 13
0
        private static void CreateMetsElementAttributes(mets mets, ArchiveMetadata metadata)
        {
            mets.OBJID   = metadata.Id;
            mets.PROFILE = "http://xml.ra.se/METS/RA_METS_eARD.xml";
            mets.LABEL   = $"{metadata.System.Name}";

            if (metadata.StartDate != null && metadata.EndDate != null)
            {
                mets.LABEL += $" ({metadata.StartDate?.Year} - {metadata.EndDate?.Year})";
            }
        }
Exemplo n.º 14
0
 public MetsCreatorTest()
 {
     ArchiveMetadata = new ArchiveMetadata
     {
         Id = "UUID:12345-12345-12345-12345-12345-12345",
         ArchiveDescription = "Some archive description",
         AgreementNumber    = "XX 00-0000/0000; 0000-00-00",
         ArchiveCreators    = new List <MetadataEntityInformationUnit>
         {
             CreateMetadataEntityInformationUnit('1'),
             CreateMetadataEntityInformationUnit('2')
         },
         Transferer = CreateMetadataEntityInformationUnit('3'),
         Producer   = CreateMetadataEntityInformationUnit('4'),
         Owners     = new List <MetadataEntityInformationUnit>
         {
             CreateMetadataEntityInformationUnit('5'),
             CreateMetadataEntityInformationUnit('6')
         },
         Recipient = "Some recipient",
         System    = new MetadataSystemInformationUnit
         {
             Name        = "Some system name",
             Version     = "v1.0.0",
             Type        = "Noark5",
             TypeVersion = "v3.1"
         },
         ArchiveSystem = new MetadataSystemInformationUnit
         {
             Name        = "Some archive system name",
             Version     = "v2.0.0",
             Type        = "Noark4",
             TypeVersion = "N/A" // To be ignored by MetsCreator
         },
         Comments = new List <string> {
             "Some comment 1", "Some comment 2"
         },
         FileDescriptions = new List <FileDescription>
         {
             new FileDescription
             {
                 Id             = 1,
                 Name           = "someFileName.pdf",
                 Extension      = "pdf",
                 Sha256Checksum = "3B29DFCC4286E50B180AF8F21904C86F8AA42A23C4055C3A71D0512F9AE3886F",
                 Size           = 2325452,
                 CreationTime   = new DateTime(2017, 06, 30)
             }
         },
         StartDate = new DateTime(2017, 01, 01),
         EndDate   = new DateTime(2020, 01, 01),
     };
 }
Exemplo n.º 15
0
        private static void LoadMetsHdr(ArchiveMetadata archiveMetadata, metsTypeMetsHdr metsHdr)
        {
            if (metsHdr.altRecordID != null)
            {
                LoadMetsHdrAltRecordIDs(archiveMetadata, metsHdr.altRecordID);
            }

            if (metsHdr.agent != null)
            {
                LoadMetsHdrAgents(archiveMetadata, metsHdr.agent);
            }
        }
Exemplo n.º 16
0
        public void Generate(string outputFileName)
        {
            ArchiveMetadata metadataExample = CreateExampleData();

            string serializedObject = JsonConvert.SerializeObject(metadataExample,
                                                                  Formatting.Indented,
                                                                  new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            WriteMetadataToFile(outputFileName, serializedObject);
        }
Exemplo n.º 17
0
        public void Create(Archive archive, ArchiveMetadata metadata)
        {
            _diasPremisCreator.CreateAndSaveFile(archive, metadata);
            // EAD is not included in v1.0
            _eadCreator.CreateAndSaveFile(archive, metadata);
            // EAC-CPF is not included in v1.0
            _eacCpfCreator.CreateAndSaveFile(archive, metadata);
            CopyDiasMetsXsdToRootDirectory(archive.WorkingDirectory);

            // Generate mets-file last for it to describe all other package content
            _diasMetsCreator.CreateAndSaveFile(archive, metadata);
        }
Exemplo n.º 18
0
        private static void CreateAltRecordIDs(metsTypeMetsHdr metsHdr, ArchiveMetadata metadata)
        {
            var altRecordIDs = new List <metsTypeMetsHdrAltRecordID>();

            if (!string.IsNullOrEmpty(metadata.ArchiveDescription))
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID
                {
                    TYPESpecified = true,
                    TYPE          = metsTypeMetsHdrAltRecordIDTYPE.DELIVERYSPECIFICATION,
                    Value         = metadata.ArchiveDescription
                });
            }

            if (!string.IsNullOrEmpty(metadata.AgreementNumber))
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID
                {
                    TYPESpecified = true,
                    TYPE          = metsTypeMetsHdrAltRecordIDTYPE.SUBMISSIONAGREEMENT,
                    Value         = metadata.AgreementNumber
                });
            }

            if (metadata.StartDate != null)
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID
                {
                    TYPESpecified = true,
                    TYPE          = metsTypeMetsHdrAltRecordIDTYPE.STARTDATE,
                    Value         = ((DateTime)metadata.StartDate).ToString(DateFormat)
                });
            }

            if (metadata.EndDate != null)
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID
                {
                    TYPESpecified = true,
                    TYPE          = metsTypeMetsHdrAltRecordIDTYPE.ENDDATE,
                    Value         = ((DateTime)metadata.EndDate).ToString(DateFormat)
                });
            }

            // Ensure min. 3 altRecordIDs (ESSArch requirement)
            while (altRecordIDs.Count < 3)
            {
                altRecordIDs.Add(new metsTypeMetsHdrAltRecordID());
            }

            metsHdr.altRecordID = altRecordIDs.ToArray();
        }
Exemplo n.º 19
0
        private Stream CreateCachedDecoderStream(ArchiveMetadata metadata, int section)
        {
            // TODO: decode stream once then reuse the cached data

            // HACK: this implementation is just a dirty hack to test something
            var buffer = new MemoryStream();

            using (var reader = new DecodedSectionReader(mStream, metadata, section, mPassword))
                using (var stream = reader.OpenStream())
                    stream.CopyTo(buffer);
            buffer.Position = 0;
            return(buffer);
        }
Exemplo n.º 20
0
 public ead Create(Archive archive, ArchiveMetadata metadata)
 {
     return(new ead()
     {
         control = new control()
         {
             recordid = new recordid()
             {
                 Text = new[] { archive.Uuid.ToString() }
             }
         }
     });
 }
Exemplo n.º 21
0
 public eaccpf Create(Archive archive, ArchiveMetadata metadata)
 {
     return(new eaccpf()
     {
         control = new control()
         {
             recordId = new recordId()
             {
                 Value = archive.Uuid.ToString()
             }
         }
     });
 }
Exemplo n.º 22
0
        private void LoadMetadataIntoForm(FileSystemInfo metadataFile, Action errorAction)
        {
            try
            {
                ArchiveMetadata metadata = MetadataLoader.Load(metadataFile.FullName);

                FillForm(metadata);
            }
            catch
            {
                errorAction.Invoke();
            }
        }
Exemplo n.º 23
0
        private static void CreateMetsHdr(metsType mets, ArchiveMetadata metadata)
        {
            var metsHdr = new metsTypeMetsHdr();

            CreateAltRecordIDs(metsHdr, metadata);

            CreateHdrAgents(metsHdr, metadata);

            if (metsHdr.altRecordID != null || metsHdr.agent != null)
            {
                mets.metsHdr = metsHdr;
            }
        }
Exemplo n.º 24
0
        private static void CreateMetsElementAttributes(mets mets, ArchiveMetadata metadata)
        {
            mets.OBJID   = metadata.Id;
            mets.PROFILE = "http://xml.ra.se/METS/RA_METS_eARD.xml";

            mets.TYPE = metadata.PackageType == PackageType.SubmissionInformationPackage
                ? metsTypeTYPE.SIP
                : metsTypeTYPE.AIP;

            if (!string.IsNullOrEmpty(metadata.Label))
            {
                mets.LABEL = metadata.Label;
            }
        }
Exemplo n.º 25
0
        public static mets Create(ArchiveMetadata metadata)
        {
            var mets = new mets();

            CreateMetsHdr(mets, metadata);

            CreateAmdSec(mets, metadata);

            CreateFileSec(mets, metadata);

            CreateStructMap(mets, metadata);

            return(mets);
        }
Exemplo n.º 26
0
        private static void LoadMetsHdr(ArchiveMetadata archiveMetadata, metsTypeMetsHdr metsHdr)
        {
            archiveMetadata.ExtractionDate = metsHdr.CREATEDATE;

            if (metsHdr.altRecordID != null)
            {
                LoadMetsHdrAltRecordIDs(archiveMetadata, metsHdr.altRecordID);
            }

            if (metsHdr.agent != null)
            {
                LoadMetsHdrAgents(archiveMetadata, metsHdr.agent);
            }
        }
Exemplo n.º 27
0
        public void CreateAndSaveFile(Archive archive, ArchiveMetadata metadata)
        {
            PrepareForPackageDescription(archive, metadata);

            mets infoXml = Create(metadata);

            FileInfo targetFileName = archive.WorkingDirectory.Root().WithFile(ArkadeConstants.InfoXmlFileName);

            XmlSerializerNamespaces namespaces = SetupNamespaces();

            SerializeUtil.SerializeToFile(infoXml, targetFileName, namespaces);

            Log.Information($"Created {ArkadeConstants.InfoXmlFileName}");
        }
Exemplo n.º 28
0
        public void CreateAndSaveFile(Archive archive, ArchiveMetadata metadata)
        {
            eaccpf eaccpf = Create(archive, metadata);

            var namespaces = new XmlSerializerNamespaces();

            namespaces.Add("", "urn:isbn:1-931666-33-4"); // use blank in namespace prefix to create files without prefixed elements
            namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            FileInfo targetFileName = archive.WorkingDirectory.DescriptiveMetadata().WithFile(ArkadeConstants.EacCpfXmlFileName);

            SerializeUtil.SerializeToFile(eaccpf, targetFileName, namespaces);

            Log.Information($"Created {ArkadeConstants.EacCpfXmlFileName}");
        }
Exemplo n.º 29
0
        public void CreateAndSaveFile(Archive archive, ArchiveMetadata metadata)
        {
            PrepareForPackageDescription(archive, metadata);

            mets infoXml = Create(metadata);

            FileInfo targetFileName = archive.GetInfoXmlFileName();

            XmlSerializerNamespaces namespaces = SetupNamespaces();

            SerializeUtil.SerializeToFile(infoXml, targetFileName, namespaces);

            Log.Information($"Created {targetFileName}");
        }
Exemplo n.º 30
0
        public void Run(CommandLineOptions options)
        {
            try
            {
                var arkade = new Core.Base.Arkade();

                var fileInfo = new FileInfo(options.Archive);
                Log.Information($"Processing archive: {fileInfo.FullName}");

                if (!Enum.TryParse(options.ArchiveType, true, out ArchiveType archiveType))
                {
                    Log.Error("Unknown archive type");
                    throw new ArgumentException("unknown archive type");
                }

                if (archiveType == ArchiveType.Noark4)
                {
                    Log.Error("Archive type Noark 4 is currently not supported");
                    throw new ArgumentException("unsupported archive type");
                }

                TestSession testSession = CreateTestSession(options, arkade, archiveType);

                if (!TestingIsSkipped(options))
                {
                    arkade.RunTests(testSession);
                    SaveTestReport(arkade, testSession, options);
                }

                if (!PackingIsSkipped(options))
                {
                    ArchiveMetadata archiveMetadata = MetadataLoader.Load(options.MetadataFile);

                    archiveMetadata.PackageType = options.InformationPackageType != null &&
                                                  options.InformationPackageType.Equals("AIP")
                        ? PackageType.ArchivalInformationPackage
                        : PackageType.SubmissionInformationPackage;

                    testSession.ArchiveMetadata    = archiveMetadata;
                    testSession.ArchiveMetadata.Id = $"UUID:{testSession.Archive.Uuid}";

                    arkade.CreatePackage(testSession, options.OutputDirectory);
                }
            }
            finally
            {
                ArkadeProcessingArea.CleanUp();
            }
        }
Exemplo n.º 31
0
 public DecodedArchiveSectionStream(Stream stream, ArchiveMetadata metadata, int index, PasswordStorage password)
 {
     mReader = new ArchiveSectionDecoder(stream, metadata, index, password);
 }
Exemplo n.º 32
0
 /// <summary>
 /// Allows to copy partial sections from an existing archive, reencoding selected entries on the fly.
 /// </summary>
 public Task TranscodeSectionAsync(Stream stream, ArchiveMetadata metadata, int section, Func<int, Task<bool>> selector, EncoderDefinition definition)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 33
0
        /// <summary>
        /// Allows to copy complete sections from existing archives into this archive.
        /// </summary>
        public async Task TransferSectionAsync(Stream stream, ArchiveMetadata metadata, int section)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            if (metadata == null)
                throw new ArgumentNullException(nameof(metadata));

            if (section < 0 || section >= metadata.DecoderSections.Length)
                throw new ArgumentOutOfRangeException(nameof(section));

            var decoderSection = metadata.DecoderSections[section];
            var count = decoderSection.Streams.Length;
            if (count == 0)
                throw new InvalidOperationException();

            // TODO: wait for pending writes
            // TODO: translate and append decoder section

            foreach (var decoder in decoderSection.Decoders)
            {
                foreach (var input in decoder.InputStreams)
                {
                    if (!input.DecoderIndex.HasValue)
                    {
                        var fileSection = metadata.FileSections[input.StreamIndex];
                        var offset = mAppendPosition;
                        var length = fileSection.Length;
                        mAppendPosition = checked(offset + length);
                        mFileSections.Add(new ArchiveFileSection(offset, length, fileSection.Checksum));
                        using (var fileSectionStream = new ConstrainedReadStream(mArchiveStream, fileSection.Offset, fileSection.Length))
                            await fileSectionStream.CopyToAsync(mArchiveStream).ConfigureAwait(false);
                    }
                }
            }
        }
Exemplo n.º 34
0
 /// <summary>
 /// Creates a new iteration to unpack a sequence of streams from a decoded archive section.
 /// </summary>
 /// <param name="stream">A readable and seekable stream for the archive.</param>
 /// <param name="metadata">The metadata for the archive.</param>
 /// <param name="index">The decoder section index from the metadata which should be unpacked.</param>
 /// <param name="password">An optional password to unpack the archive content.</param>
 public DecodedSectionReader(Stream stream, ArchiveMetadata metadata, int index, PasswordStorage password)
 {
     mDecodedStream = new ArchiveSectionDecoder(stream, metadata, index, password);
     mMetadata = metadata;
     mDecoderSection = metadata.DecoderSections[index];
 }
        private Stream CreateCachedDecoderStream(ArchiveMetadata metadata, int section)
        {
            // TODO: decode stream once then reuse the cached data

            // HACK: this implementation is just a dirty hack to test something
            var buffer = new MemoryStream();
            using (var reader = new DecodedSectionReader(mStream, metadata, section, mPassword))
            using (var stream = reader.OpenStream())
                stream.CopyTo(buffer);
            buffer.Position = 0;
            return buffer;
        }
Exemplo n.º 36
0
        public ArchiveSectionDecoder(Stream stream, ArchiveMetadata metadata, int index, PasswordStorage password)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            if (!stream.CanRead)
                throw new ArgumentException("Stream must be readable.", nameof(stream));

            if (!stream.CanSeek)
                throw new ArgumentException("Stream must be seekable.", nameof(stream));

            if (metadata == null)
                throw new ArgumentNullException(nameof(metadata));

            if (index < 0 || index >= metadata.DecoderSections.Length)
                throw new ArgumentOutOfRangeException(nameof(index));

            var inputCoordinator = new StreamCoordinator(stream);
            var inputStreams = new ReaderNode[metadata.FileSections.Length];
            for (int i = 0; i < inputStreams.Length; i++)
                inputStreams[i] = new CoordinatedStream(inputCoordinator, metadata.FileSections[i].Offset, metadata.FileSections[i].Length);

            var decoderSection = metadata.DecoderSections[index];
            var decoderDefinitions = decoderSection.Decoders;
            var decoders = new DecoderNode[decoderDefinitions.Length];

            for (int i = 0; i < decoders.Length; i++)
            {
                var decoderDefinition = decoderDefinitions[i];
                decoders[i] = decoderDefinition.DecoderType.CreateDecoder(decoderDefinition.Settings, decoderDefinition.OutputStreams, password);
            }

            for (int i = 0; i < decoders.Length; i++)
            {
                var decoder = decoders[i];
                var decoderDefinition = decoderDefinitions[i];
                var decoderInputDefinitions = decoderDefinition.InputStreams;

                for (int j = 0; j < decoderInputDefinitions.Length; j++)
                {
                    ReaderNode inputStream;
                    long inputLength;
                    SelectStream(metadata, decoderSection, decoderInputDefinitions[j], inputStreams, decoders, out inputStream, out inputLength);
                    decoder.SetInputStream(j, inputStream, inputLength);
                }
            }

            ReaderNode outputStream;
            long outputLength;
            SelectStream(metadata, decoderSection, decoderSection.DecodedStream, inputStreams, decoders, out outputStream, out outputLength);

            mCoordinator = inputCoordinator;
            mInputStreams = inputStreams;
            mDecoders = decoders;
            mOutputStream = outputStream;
        }
Exemplo n.º 37
0
 private static void SelectStream(
     ArchiveMetadata archiveMetadata,
     ArchiveDecoderSection sectionMetadata,
     DecoderInputMetadata selector,
     ReaderNode[] streams,
     DecoderNode[] decoders,
     out ReaderNode result,
     out long length)
 {
     var decoderIndex = selector.DecoderIndex;
     if (decoderIndex.HasValue)
     {
         length = sectionMetadata.Decoders[decoderIndex.Value].OutputStreams[selector.StreamIndex].Length;
         result = decoders[decoderIndex.Value].GetOutputStream(selector.StreamIndex);
     }
     else
     {
         length = archiveMetadata.FileSections[selector.StreamIndex].Length;
         result = streams[selector.StreamIndex];
     }
 }