Example #1
0
        /// <summary>
        /// Writes the given container record to the file stream.
        /// </summary>
        /// <param name="containerRecord">The container record to be written to the PQDIF file.</param>
        /// <exception cref="ArgumentNullException"><paramref name="containerRecord"/> is null.</exception>
        /// <exception cref="ObjectDisposedException">The writer was disposed.</exception>
        /// <exception cref="InvalidOperationException">Attempt was made to write multiple container records to the file.</exception>
        /// <exception cref="InvalidDataException">The PQDIF data is invalid.</exception>
        /// <exception cref="NotSupportedException">
        ///     <para>Attempt is made to use <see cref="CompressionStyle.TotalFile"/>.</para>
        ///     <para>- OR -</para>
        ///     <para>Attempt is made to use <see cref="CompressionAlgorithm.PKZIP"/>.</para>
        /// </exception>
        public async Task WriteAsync(ContainerRecord containerRecord)
        {
            if (containerRecord == null)
            {
                throw new ArgumentNullException("containerRecord");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (m_containerRecord != null)
            {
                throw new InvalidOperationException("Only one container record can be written to a PQDIF file.");
            }

            ValidateContainerRecord(containerRecord);

            m_containerRecord = containerRecord;
            await m_physicalWriter.WriteRecordAsync(containerRecord.PhysicalRecord);

            m_physicalWriter.CompressionAlgorithm = m_containerRecord.CompressionAlgorithm;
            m_physicalWriter.CompressionStyle     = m_containerRecord.CompressionStyle;
        }
Example #2
0
        private void ValidateContainerRecord(ContainerRecord containerRecord)
        {
            if (!containerRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ContainerRecord.VersionInfoTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.Container, "VersionInfoTag", ContainerRecord.VersionInfoTag));
            }

            if (!containerRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ContainerRecord.FileNameTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.Container, "FileNameTag", ContainerRecord.FileNameTag));
            }

            if (!containerRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ContainerRecord.VersionInfoTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.Container, "CreationTag", ContainerRecord.CreationTag));
            }
        }
Example #3
0
        // Static Methods

        /// <summary>
        /// Creates a new container record from scratch.
        /// </summary>
        /// <returns>The new container record.</returns>
        public static ContainerRecord CreateContainerRecord()
        {
            Guid            recordTypeTag   = Record.GetTypeAsTag(RecordType.Container);
            Record          physicalRecord  = new Record(recordTypeTag);
            ContainerRecord containerRecord = new ContainerRecord(physicalRecord);

            DateTime now = DateTime.UtcNow;

            containerRecord.WriterMajorVersion     = 1;
            containerRecord.WriterMinorVersion     = 5;
            containerRecord.CompatibleMajorVersion = 1;
            containerRecord.CompatibleMinorVersion = 0;
            containerRecord.FileName = $"{now:yyyy-MM-dd_HH.mm.ss}.pqd";
            containerRecord.Creation = now;

            return(containerRecord);
        }