Beispiel #1
0
        private void ValidateLogFile(GranularLogCompleteMsg msg, string fullSourceFileName)
        {
            if (msg.ChecksumUsed != GranularLogCloseData.ChecksumAlgorithm.MD5)
            {
                GranularWriter.Tracer.TraceError((long)this.GetHashCode(), "only MD5 supported for now");
                this.ThrowUnexpectedMessage("only MD5 supported for now");
            }
            Exception ex = null;

            try
            {
                using (SafeFileHandle safeFileHandle = LogCopy.OpenLogForRead(fullSourceFileName))
                {
                    using (FileStream fileStream = LogCopy.OpenFileStream(safeFileHandle, true))
                    {
                        FileInfo fileInfo = new FileInfo(fullSourceFileName);
                        if (fileInfo.Length != 1048576L)
                        {
                            throw new IOException(string.Format("Unexpected log file size: '{0}' has 0x{1:X} bytes", fullSourceFileName, fileInfo.Length));
                        }
                        byte[] buffer = new byte[1048576];
                        int    num    = fileStream.Read(buffer, 0, 1048576);
                        if (num != 1048576)
                        {
                            GranularWriter.Tracer.TraceError <int, int, string>((long)this.GetHashCode(), "ValidateLogFile. Expected {0} but got {1} bytes from {2}", 1048576, num, fullSourceFileName);
                            throw new IOException(ReplayStrings.UnexpectedEOF(fullSourceFileName));
                        }
                        byte[] b;
                        using (MessageDigestForNonCryptographicPurposes messageDigestForNonCryptographicPurposes = new MessageDigestForNonCryptographicPurposes())
                        {
                            b = messageDigestForNonCryptographicPurposes.ComputeHash(buffer);
                        }
                        if (!GranularWriter.BytesAreIdentical(b, msg.ChecksumBytes))
                        {
                            GranularWriter.Tracer.TraceError <string>((long)this.GetHashCode(), "ValidateLogFile: MD5 hash failure on '{0}'", fullSourceFileName);
                            throw new GranularReplicationTerminatedException(string.Format("MD5 HASH fails on {0}", fullSourceFileName));
                        }
                    }
                }
            }
            catch (IOException ex2)
            {
                ex = ex2;
            }
            catch (UnauthorizedAccessException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                throw new GranularReplicationTerminatedException(string.Format("ValidateLogFile on {0} failed: {1}", fullSourceFileName, ex.Message), ex);
            }
        }
Beispiel #2
0
 // Token: 0x06001AB0 RID: 6832 RVA: 0x0007240F File Offset: 0x0007060F
 private static FileStream OpenFileStream(SafeFileHandle fileHandle, bool openForRead)
 {
     return(LogCopy.OpenFileStream(fileHandle, openForRead));
 }
Beispiel #3
0
        // Token: 0x06001D67 RID: 7527 RVA: 0x00084D0C File Offset: 0x00082F0C
        private Exception VerifyLog(string fullLocalFileName, long expectedGen)
        {
            Exception ex = null;

            try
            {
                ReplayStopwatch replayStopwatch = new ReplayStopwatch();
                replayStopwatch.Start();
                using (SafeFileHandle safeFileHandle = LogCopy.OpenLogForRead(fullLocalFileName))
                {
                    long arg = replayStopwatch.ElapsedMilliseconds;
                    LogRepair.Tracer.TracePerformance <string, long>((long)this.GetHashCode(), "VerifyLog({0}): Open took: {1} ms", fullLocalFileName, arg);
                    using (FileStream fileStream = LogCopy.OpenFileStream(safeFileHandle, true))
                    {
                        FileInfo fileInfo = new FileInfo(fullLocalFileName);
                        long     elapsedMilliseconds;
                        try
                        {
                            if (fileInfo.Length != 1048576L)
                            {
                                throw new IOException(string.Format("Unexpected log file size: '{0}' has 0x{1:X} bytes.", fullLocalFileName, fileInfo.Length));
                            }
                            elapsedMilliseconds = replayStopwatch.ElapsedMilliseconds;
                            int num = fileStream.Read(this.m_verifierLogDataBuf, 0, 1048576);
                            if (num != 1048576)
                            {
                                LogRepair.Tracer.TraceError <int, int, string>((long)this.GetHashCode(), "VerifyLog. Expected {0} but got {1} bytes from {2}", 1048576, num, fullLocalFileName);
                                throw new IOException(ReplayStrings.UnexpectedEOF(fullLocalFileName));
                            }
                            arg = replayStopwatch.ElapsedMilliseconds - elapsedMilliseconds;
                            LogRepair.Tracer.TracePerformance <string, long>((long)this.GetHashCode(), "VerifyLog({0}): Read took: {1} ms", fullLocalFileName, arg);
                        }
                        catch (IOException ex2)
                        {
                            throw new CorruptLogDetectedException(fullLocalFileName, ex2.Message, ex2);
                        }
                        elapsedMilliseconds = replayStopwatch.ElapsedMilliseconds;
                        EsentErrorException ex3 = this.EseLogVerifier.Verify(fullLocalFileName, this.m_verifierLogDataBuf);
                        if (ex3 != null)
                        {
                            LogRepair.Tracer.TraceError <string, EsentErrorException>((long)this.GetHashCode(), "ESELogVerifier({0}) failed: {1}", fullLocalFileName, ex3);
                            if (ex3 is EsentLogFileCorruptException)
                            {
                                throw new CorruptLogDetectedException(fullLocalFileName, ex3.Message, ex3);
                            }
                            throw ex3;
                        }
                        else
                        {
                            JET_LOGINFOMISC jet_LOGINFOMISC;
                            UnpublishedApi.JetGetLogFileInfo(fullLocalFileName, out jet_LOGINFOMISC, JET_LogInfo.Misc2);
                            if ((long)jet_LOGINFOMISC.ulGeneration != expectedGen)
                            {
                                throw new FileCheckLogfileGenerationException(fullLocalFileName, (long)jet_LOGINFOMISC.ulGeneration, expectedGen);
                            }
                            if (this.m_logfileSignature == null)
                            {
                                this.m_logfileSignature = new JET_SIGNATURE?(jet_LOGINFOMISC.signLog);
                            }
                            if (!jet_LOGINFOMISC.signLog.Equals(this.m_logfileSignature))
                            {
                                throw new FileCheckLogfileSignatureException(fullLocalFileName, jet_LOGINFOMISC.signLog.ToString(), this.m_logfileSignature.ToString());
                            }
                            arg = replayStopwatch.ElapsedMilliseconds - elapsedMilliseconds;
                            LogRepair.Tracer.TracePerformance <string, long>((long)this.GetHashCode(), "VerifyLog({0}): Verify took: {1} ms", fullLocalFileName, arg);
                            return(null);
                        }
                    }
                }
            }
            catch (IOException ex4)
            {
                ex = ex4;
            }
            catch (UnauthorizedAccessException ex5)
            {
                ex = ex5;
            }
            catch (EsentErrorException ex6)
            {
                ex = ex6;
            }
            catch (CorruptLogDetectedException ex7)
            {
                ex = ex7;
            }
            catch (FileCheckException ex8)
            {
                ex = ex8;
            }
            if (ex != null)
            {
                LogRepair.Tracer.TraceError <string, Exception>((long)this.GetHashCode(), "VerifyLog({0}): failed with {1}", fullLocalFileName, ex);
            }
            return(ex);
        }