コード例 #1
0
        public ZipArchiveProblems Validate(ZipArchiveEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            var problems = ZipArchiveProblems.None;

            using (var stream = entry.Open())
                using (var reader = new BinaryReader(stream, _encoding))
                {
                    DbaseFileHeader header = null;
                    try
                    {
                        header = DbaseFileHeader.Read(reader);
                    }
                    catch (Exception exception)
                    {
                        problems += entry.HasDbaseHeaderFormatError(exception);
                    }

                    if (header != null)
                    {
                        if (!header.Schema.Equals(_schema))
                        {
                            problems += entry.HasDbaseSchemaMismatch(_schema, header.Schema);
                        }
                        else
                        {
                            using (var records = header.CreateDbaseRecordEnumerator <TDbaseRecord>(reader))
                            {
                                problems += _recordValidator.Validate(entry, records);
                            }
                        }
                    }
                }

            return(problems);
        }