Пример #1
0
        protected override void ExecuteTask()
        {
            if (DebugTask && !System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Launch();

            NAnt.Contrib.Functions.FileFunctions contribFileFunctions = new Contrib.Functions.FileFunctions(base.Project, base.Properties);

            if (null != InElement && 0 < InElement.Count && 0 < InElement[0].FileNames.Count)
            {
                for (int idx = 0; idx < InElement.Count; idx++)
                {
                    FileSet fs = InElement[idx];
                    for (int idx2 = 0; idx2 < fs.FileNames.Count; idx2++)
                    {
                        FileInfo fileToCheck = new FileInfo(fs.FileNames[idx2]);
                        FileInfo checksumFile = new FileInfo(fileToCheck.FullName + '.' + Algorithm);

                        if (!checksumFile.Exists) throw new FileNotFoundException("Can't find checksum file", checksumFile.FullName);
                        if (!fileToCheck.Exists) throw new FileNotFoundException("Can't find file to check", fileToCheck.FullName);

                        string actualChecksum = contribFileFunctions.GetChecksum(fileToCheck.FullName, Algorithm);
                        using (StreamReader sr = checksumFile.OpenText())
                        {
                            string expectedChecksum = sr.ReadToEnd();
                            if (actualChecksum != expectedChecksum) throw new Exception(string.Format("The checksum generated does not match the contents of the file's counterpart.  Actual [{0}] from [{1}] was expected to be [{2}]", actualChecksum, fileToCheck.FullName, expectedChecksum));
                        }
                    }
                }
            }
        }
Пример #2
0
        protected override void ExecuteTask()
        {
            if (DebugTask && !System.Diagnostics.Debugger.IsAttached)
            {
                System.Diagnostics.Debugger.Launch();
            }

            NAnt.Contrib.Functions.FileFunctions contribFileFunctions = new Contrib.Functions.FileFunctions(base.Project, base.Properties);

            if (null != InElement && 0 < InElement.Count && 0 < InElement[0].FileNames.Count)
            {
                for (int idx = 0; idx < InElement.Count; idx++)
                {
                    FileSet fs = InElement[idx];
                    for (int idx2 = 0; idx2 < fs.FileNames.Count; idx2++)
                    {
                        FileInfo fileToCheck  = new FileInfo(fs.FileNames[idx2]);
                        FileInfo checksumFile = new FileInfo(fileToCheck.FullName + '.' + Algorithm);

                        if (!checksumFile.Exists)
                        {
                            throw new FileNotFoundException("Can't find checksum file", checksumFile.FullName);
                        }
                        if (!fileToCheck.Exists)
                        {
                            throw new FileNotFoundException("Can't find file to check", fileToCheck.FullName);
                        }

                        string actualChecksum = contribFileFunctions.GetChecksum(fileToCheck.FullName, Algorithm);
                        using (StreamReader sr = checksumFile.OpenText())
                        {
                            string expectedChecksum = sr.ReadToEnd();
                            if (actualChecksum != expectedChecksum)
                            {
                                throw new Exception(string.Format("The checksum generated does not match the contents of the file's counterpart.  Actual [{0}] from [{1}] was expected to be [{2}]", actualChecksum, fileToCheck.FullName, expectedChecksum));
                            }
                        }
                    }
                }
            }
        }