string IParseResumeDataCommand.ParseResumeData(byte[] data, string docType)
        {
            try
            {
                // Check for special cases first.

                if (MiscUtils.ByteArraysEqual(data, TestResume.Invalid.GetData()))
                {
                    throw new LensInvalidDocumentException();
                }

                if (MiscUtils.ByteArraysEqual(data, TestResume.Unavailable.GetData()))
                {
                    throw new LensUnavailableException("Not working.");
                }

                foreach (var resume in TestResume.AllResumes)
                {
                    if (MiscUtils.ByteArraysEqual(data, resume.GetData()))
                    {
                        return(resume.GetLensXml());
                    }
                }

                return("<ResDoc><contact></contact><resume></resume></ResDoc>");
            }
            catch (LensInvalidDocumentException ex)
            {
                throw new InvalidResumeException(ex);
            }
            catch (LensException ex)
            {
                throw new ParserUnavailableException(ex);
            }
        }
Exemplo n.º 2
0
        public static Stream DecompressIfGZipped(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("The stream must support reading.");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must support seeking.");
            }

            // Look for the GZIP file signature.

            var  sigBuffer    = new byte[_gzipFileSignature.Length];
            bool isCompressed = (stream.Read(sigBuffer, 0, sigBuffer.Length) == sigBuffer.Length &&
                                 MiscUtils.ByteArraysEqual(sigBuffer, _gzipFileSignature));

            // Seek back to the start of the signature.
            stream.Position = Math.Max(stream.Position - _gzipFileSignature.Length, 0);

            return(isCompressed ? new GZipStream(stream, CompressionMode.Decompress, true) : stream);
        }
Exemplo n.º 3
0
 public static bool IsKeyedHashValid(byte[] data, byte[] hash)
 {
     return(MiscUtils.ByteArraysEqual(GetKeyedHash(data), hash));
 }