コード例 #1
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
 public static bool CompareXml(string baselineFile, string actualFile, string xmldiffoptionvalue, DelayedWriteLogger logger)
 {
     using (var fsActual = new FileStream(actualFile, FileMode.Open, FileAccess.Read))
     using (var fsExpected = new FileStream(baselineFile, FileMode.Open, FileAccess.Read))
     {
         return CompareXml(fsActual, fsExpected, xmldiffoptionvalue, logger);
     }
 }
コード例 #2
0
        public static bool VerifySingleAssemblyUsingPEVerify(string asmName, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            bool result = false;

            if (File.Exists(asmName))
            {
                //add double quotes for names with whitespace in them
                string processArguments = " /quiet " + "\"" + asmName + "\"";

                // Call PEVerify to verify persistant assembly.
                Process peVerifyProcess = new Process();
                peVerifyProcess.StartInfo.FileName  = SearchPath("peverify.exe");
                peVerifyProcess.StartInfo.Arguments = " " + processArguments;
                //peVerifyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                peVerifyProcess.StartInfo.CreateNoWindow         = true;
                peVerifyProcess.StartInfo.UseShellExecute        = false;
                peVerifyProcess.StartInfo.RedirectStandardOutput = true;

                peVerifyProcess.Start();
                output = peVerifyProcess.StandardOutput.ReadToEnd();
                peVerifyProcess.WaitForExit();

                // Check the output for the Assembly name, and the word "PASS"
                // For example:
                // C:>peverify /quiet 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll
                // 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll PASS
                if (peVerifyProcess.ExitCode == 0 && output.Contains(asmName) && output.Contains("PASS"))
                {
                    result = true;
                }
                else
                {
                    if (logger != null)
                    {
                        logger.LogMessage("PEVerify could not be run or FAILED : {0}", asmName + " " + output);
                    }
                    result = false;
                }
            }
            else
            {
                if (logger != null)
                {
                    logger.LogMessage("Assembly file could not be found : {0}", asmName);
                }
                result = false;
            }

            return(result);
        }
コード例 #3
0
        public static bool VerifyAssemblyUsingPEVerify(string asmName, DelayedWriteLogger logger, ref string output)
        {
            String scriptAsmNameFormat = Path.ChangeExtension(asmName, null) + "_Script{0}.dll";
            int    scriptCounter       = 0;
            String testAsm             = asmName;
            bool   result = false;

            do
            {
                result  = VerifySingleAssemblyUsingPEVerify(testAsm, logger, ref output);
                testAsm = String.Format(scriptAsmNameFormat, ++scriptCounter);
            }while (result && File.Exists(testAsm));

            return(result);
        }
コード例 #4
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
        public static bool CompareXml(Stream expectedStream, Stream actualStream, string xmldiffoptionvalue, DelayedWriteLogger logger)
        {
            bool bResult = false;

            // Default Diff options used by XSLT V2 driver.
            int defaultXmlDiffOptions = (int)(XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder);
            XmlDiff diff = new XmlDiff();

            if (xmldiffoptionvalue == null || xmldiffoptionvalue.Equals(string.Empty))
                diff.Option = (XmlDiffOption)defaultXmlDiffOptions;
            else
            {
                if (logger != null) logger.LogMessage("Custom XmlDiffOptions used. Value passed is " + xmldiffoptionvalue);
                diff.Option = (XmlDiffOption)Int32.Parse(xmldiffoptionvalue);
            }

            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            try
            {
                bResult =
                   diff.Compare(new XmlTextReader(actualStream, XmlNodeType.Element, context),
                             new XmlTextReader(expectedStream, XmlNodeType.Element, context));
            }
            catch (Exception e)
            {
                bResult = false;
                if (logger != null)
                {
                    logger.LogMessage("Exception thrown in XmlDiff compare!");
                    logger.LogXml(e.ToString());
                    throw;
                }
            }

            if (bResult)
                return true;

            if (logger != null)
            {
                logger.LogMessage("Mismatch in XmlDiff");
                logger.LogMessage("Actual result: ");
            }

            return false;
        }
コード例 #5
0
        // Call PEVerify on the Assembly name, parse the output,
        // and return true if the output is PASS and false if the output is FAIL.
        public static bool VerifyAssemblyUsingPEVerify(string asmName, bool isValidCase, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            if (!asmName.Contains(".dll") || !asmName.Contains(".DLL"))
            {
                asmName = asmName + ".dll";
            }

            if (File.Exists(asmName))
            {
                return(VerifyAssemblyUsingPEVerify(asmName, logger, ref output));
            }
            else
            {
                if (isValidCase)
                {
                    string message = "PEVerify could not be run, no assembly present: " + asmName;
                    if (logger != null)
                    {
                        logger.LogMessage(message);
                    }
                    output = message;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="startFromLine">The line to start calculating the checksum. Any text before this line is ignored. First line is 1.</param>
        /// <param name="logger"></param>
        /// <returns></returns>
        private static string CalcChecksum(string fileName, int startFromLine, DelayedWriteLogger logger)
        {
            const int BUFFERSIZE = 4096;
            Decimal   dResult    = 0;  // Numerical value of the checksum
            int       i          = 0;  // Generic counter
            int       cBytesRead = 1;  // # of bytes read at one time
            int       cTotalRead = 0;  // Total # of bytes read so far
            Decimal   dEndBuffer = 0;  // Buffer to remove from the end (This is necessary because

            // notepad adds CR/LF onto the end of every file)
            Char[] rgBuffer = new Char[BUFFERSIZE];

            string xml = "";

            StreamReader fs = null;

            try
            {
                fs = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));

                //switch to the line to start from, lines start from 1
                for (int j = 1; j < startFromLine; j++)
                {
                    fs.ReadLine();
                }

                cBytesRead = fs.Read(rgBuffer, 0, BUFFERSIZE);

                while (cBytesRead > 0)
                {
                    // Keep XML property up to date
                    xml = String.Concat(xml, new String(rgBuffer, 0, cBytesRead));

                    // Calculate the checksum
                    for (i = 0; i < cBytesRead; i++)
                    {
                        dResult += Math.Round((Decimal)(rgBuffer[i] / (cTotalRead + i + 1.0)), 10);
                    }

                    cTotalRead += cBytesRead;
                    dEndBuffer  = 0;

                    // Keep reading (in case file is bigger than 4K)
                    cBytesRead = fs.Read(rgBuffer, 0, BUFFERSIZE);
                }
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.LogXml(ex.ToString());
                }
                return("");
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }
            return(Convert.ToString(dResult - dEndBuffer, NumberFormatInfo.InvariantInfo));
        }
コード例 #7
0
 private static string CalcChecksum(string fileName, DelayedWriteLogger logger)
 {
     return(CalcChecksum(fileName, 1, logger));
 }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Baseline"></param>
        /// <param name="baselineStartLine">The line to start comparison in the baseline file</param>
        /// <param name="OutFile"></param>
        /// <param name="outFileStartLine">The line to start comparion in the output file</param>
        /// <param name="driverVersion"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        public static bool CompareChecksum(string Baseline, int baselineStartLine, string OutFile, int outFileStartLine, int driverVersion, DelayedWriteLogger logger)
        {
            // Keep people honest.
            if (driverVersion == 2)
            {
                if (logger != null)
                {
                    logger.LogMessage("Calculating checksum for baseline output {0}...", Baseline);
                }

                string expectedCheckSum = CalcChecksum(Baseline, baselineStartLine, logger);
                string actualChecksum   = CalcChecksum(OutFile, outFileStartLine, logger);

                if (expectedCheckSum.Equals(actualChecksum))
                {
                    return(true);
                }
                else
                {
                    if (logger != null)
                    {
                        logger.LogMessage("Actual checksum: {0}, Expected checksum: {1}", actualChecksum, expectedCheckSum);
                        logger.LogMessage("Actual result: ");
                        logger.WriteOutputFileToLog(OutFile);
                    }
                    return(false);
                }
            }
            else
            {
                throw new NotSupportedException("Not a supported driver version");
            }
        }
コード例 #9
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
        /// <summary>
        ///
        /// </summary>
        /// <param name="Baseline"></param>
        /// <param name="baselineStartLine">The line to start comparison in the baseline file</param>
        /// <param name="OutFile"></param>
        /// <param name="outFileStartLine">The line to start comparion in the output file</param>
        /// <param name="driverVersion"></param>
        /// <param name="logger"></param>
        /// <returns></returns>
        public static bool CompareChecksum(string Baseline, int baselineStartLine, string OutFile, int outFileStartLine, int driverVersion, DelayedWriteLogger logger)
        {
            // Keep people honest.
            if (driverVersion == 2)
            {
                if (logger != null) logger.LogMessage("Calculating checksum for baseline output {0}...", Baseline);

                string expectedCheckSum = CalcChecksum(Baseline, baselineStartLine, logger);
                string actualChecksum = CalcChecksum(OutFile, outFileStartLine, logger);

                if (expectedCheckSum.Equals(actualChecksum))
                    return true;
                else
                {
                    if (logger != null)
                    {
                        logger.LogMessage("Actual checksum: {0}, Expected checksum: {1}", actualChecksum, expectedCheckSum);
                        logger.LogMessage("Actual result: ");
                        logger.WriteOutputFileToLog(OutFile);
                    }
                    return false;
                }
            }
            else throw new NotSupportedException("Not a supported driver version");
        }
コード例 #10
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
        public static bool VerifySingleAssemblyUsingPEVerify(string asmName, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            bool result = false;

            if (File.Exists(asmName))
            {
                //add double quotes for names with whitespace in them
                string processArguments = " /quiet " + "\"" + asmName + "\"";

                // Call PEVerify to verify persistant assembly.
                Process peVerifyProcess = new Process();
                peVerifyProcess.StartInfo.FileName = SearchPath("peverify.exe");
                peVerifyProcess.StartInfo.Arguments = " " + processArguments;
                //peVerifyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                peVerifyProcess.StartInfo.CreateNoWindow = true;
                peVerifyProcess.StartInfo.UseShellExecute = false;
                peVerifyProcess.StartInfo.RedirectStandardOutput = true;

                peVerifyProcess.Start();
                output = peVerifyProcess.StandardOutput.ReadToEnd();
                peVerifyProcess.WaitForExit();

                // Check the output for the Assembly name, and the word "PASS"
                // For example:
                // C:>peverify /quiet 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll
                // 4AC8BD29F3CB888FAD76F7C08FD57AD3.dll PASS
                if (peVerifyProcess.ExitCode == 0 && output.Contains(asmName) && output.Contains("PASS"))
                    result = true;
                else
                {
                    if (logger != null)
                        logger.LogMessage("PEVerify could not be run or FAILED : {0}", asmName + " " + output);
                    result = false;
                }
            }
            else
            {
                if (logger != null)
                    logger.LogMessage("Assembly file could not be found : {0}", asmName);
                result = false;
            }

            return result;
        }
コード例 #11
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
        public static bool VerifyAssemblyUsingPEVerify(string asmName, DelayedWriteLogger logger, ref string output)
        {
            String scriptAsmNameFormat = Path.ChangeExtension(asmName, null) + "_Script{0}.dll";
            int scriptCounter = 0;
            String testAsm = asmName;
            bool result = false;

            do
            {
                result = VerifySingleAssemblyUsingPEVerify(testAsm, logger, ref output);
                testAsm = String.Format(scriptAsmNameFormat, ++scriptCounter);
            }
            while (result && File.Exists(testAsm));

            return result;
        }
コード例 #12
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
        // Call PEVerify on the Assembly name, parse the output,
        // and return true if the output is PASS and false if the output is FAIL.
        public static bool VerifyAssemblyUsingPEVerify(string asmName, bool isValidCase, DelayedWriteLogger logger, ref string output)
        {
            Debug.Assert(asmName != null);
            Debug.Assert(asmName != String.Empty);

            if (!asmName.Contains(".dll") || !asmName.Contains(".DLL"))
                asmName = asmName + ".dll";

            if (File.Exists(asmName))
            {
                return VerifyAssemblyUsingPEVerify(asmName, logger, ref output);
            }
            else
            {
                if (isValidCase)
                {
                    string message = "PEVerify could not be run, no assembly present: " + asmName;
                    if (logger != null)
                        logger.LogMessage(message);
                    output = message;
                    return false;
                }
                else return true;
            }
        }
コード例 #13
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="startFromLine">The line to start calculating the checksum. Any text before this line is ignored. First line is 1.</param>
        /// <param name="logger"></param>
        /// <returns></returns>
        private static string CalcChecksum(string fileName, int startFromLine, DelayedWriteLogger logger)
        {
            const int BUFFERSIZE = 4096;
            Decimal dResult = 0;        // Numerical value of the checksum
            int i = 0;                  // Generic counter
            int cBytesRead = 1;        // # of bytes read at one time
            int cTotalRead = 0;         // Total # of bytes read so far
            Decimal dEndBuffer = 0;     // Buffer to remove from the end (This is necessary because
            // notepad adds CR/LF onto the end of every file)
            Char[] rgBuffer = new Char[BUFFERSIZE];

            string xml = "";

            StreamReader fs = null;

            try
            {
                fs = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));

                //switch to the line to start from, lines start from 1
                for (int j = 1; j < startFromLine; j++)
                {
                    fs.ReadLine();
                }

                cBytesRead = fs.Read(rgBuffer, 0, BUFFERSIZE);

                while (cBytesRead > 0)
                {
                    // Keep XML property up to date
                    xml = String.Concat(xml, new String(rgBuffer, 0, cBytesRead));

                    // Calculate the checksum
                    for (i = 0; i < cBytesRead; i++)
                    {
                        dResult += Math.Round((Decimal)(rgBuffer[i] / (cTotalRead + i + 1.0)), 10);
                    }

                    cTotalRead += cBytesRead;
                    dEndBuffer = 0;

                    // Keep reading (in case file is bigger than 4K)
                    cBytesRead = fs.Read(rgBuffer, 0, BUFFERSIZE);
                }
            }
            catch (Exception ex)
            {
                if (logger != null) logger.LogXml(ex.ToString());
                return "";
            }
            finally
            {
                if (fs != null) fs.Dispose();
            }
            return Convert.ToString(dResult - dEndBuffer, NumberFormatInfo.InvariantInfo);
        }
コード例 #14
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
 private static string CalcChecksum(string fileName, DelayedWriteLogger logger)
 {
     return CalcChecksum(fileName, 1, logger);
 }
コード例 #15
0
 public static bool CompareXml(string baselineFile, string actualFile, string xmldiffoptionvalue, DelayedWriteLogger logger)
 {
     using (var fsActual = new FileStream(actualFile, FileMode.Open, FileAccess.Read))
         using (var fsExpected = new FileStream(baselineFile, FileMode.Open, FileAccess.Read))
         {
             return(CompareXml(fsActual, fsExpected, xmldiffoptionvalue, logger));
         }
 }
コード例 #16
0
 public static bool CompareChecksum(string Baseline, string OutFile, int driverVersion, DelayedWriteLogger logger)
 {
     return(CompareChecksum(
                Baseline,
                1,        //start from the first line in the baseline file
                OutFile,
                1,        //start from the first line in the output file
                driverVersion,
                logger));
 }
コード例 #17
0
        public static bool CompareXml(Stream expectedStream, Stream actualStream, string xmldiffoptionvalue, DelayedWriteLogger logger)
        {
            bool bResult = false;

            // Default Diff options used by XSLT V2 driver.
            int     defaultXmlDiffOptions = (int)(XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder);
            XmlDiff diff = new XmlDiff();

            if (xmldiffoptionvalue == null || xmldiffoptionvalue.Equals(string.Empty))
            {
                diff.Option = (XmlDiffOption)defaultXmlDiffOptions;
            }
            else
            {
                if (logger != null)
                {
                    logger.LogMessage("Custom XmlDiffOptions used. Value passed is " + xmldiffoptionvalue);
                }
                diff.Option = (XmlDiffOption)Int32.Parse(xmldiffoptionvalue);
            }

            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            try
            {
                bResult =
                    diff.Compare(new XmlTextReader(actualStream, XmlNodeType.Element, context),
                                 new XmlTextReader(expectedStream, XmlNodeType.Element, context));
            }
            catch (Exception e)
            {
                bResult = false;
                if (logger != null)
                {
                    logger.LogMessage("Exception thrown in XmlDiff compare!");
                    logger.LogXml(e.ToString());
                    throw;
                }
            }

            if (bResult)
            {
                return(true);
            }

            if (logger != null)
            {
                logger.LogMessage("Mismatch in XmlDiff");
                logger.LogMessage("Actual result: ");
            }

            return(false);
        }
コード例 #18
0
ファイル: XsltCommon.cs プロジェクト: geoffkizer/corefx
 public static bool CompareChecksum(string Baseline, string OutFile, int driverVersion, DelayedWriteLogger logger)
 {
     return CompareChecksum(
        Baseline,
        1,                //start from the first line in the baseline file
        OutFile,
        1,                //start from the first line in the output file
        driverVersion,
        logger);
 }