/// <summary>
 /// Compares the with expected output.
 /// </summary>
 public void CompareWithExpectedOutput()
 {
     if (this.CanCompareWithExpectedOutput)
     {
         //TODO handle exceptions!
         FileComparator.DiffWithBeyondCompare(this.ExpectedOutputTestFilePath, this.ResultTestFilePath, this.BeyondCompareFilePath);
     }
 }
        /// <summary>
        /// Checks whether the test output is the same as the expected one
        /// </summary>
        private void CheckTestResults()
        {
            //TODO handle exceptions!
            bool areFilesIdentical = FileComparator.Compare(this.ResultTestFilePath, this.ExpectedOutputTestFilePath);

            if (areFilesIdentical)
            {
                this.TestState = TestState.Passed;
            }
            else
            {
                this.TestState = TestState.NotPassed;
            }
        }
        public void LoadConfig()
        {
            string iniFilePath = IniConfigFileName;

            if (!File.Exists(iniFilePath))
            {
                SaveConfig(); // Generate default config file
            }
            IniFile iniFile = new IniFile();

            iniFile.TryLoad(iniFilePath);

            if (iniFile.ContainsKey("sourcePath"))
            {
                sourcePath = iniFile["sourcePath"];
            }
            if (iniFile.ContainsKey("destinationPath"))
            {
                destinationPath = iniFile["destinationPath"];
            }
            if (iniFile.ContainsKey("recursive"))
            {
                Recursive = iniFile["recursive"].ToBool();
            }
            if (iniFile.ContainsKey("locale"))
            {
                Locale = new CultureInfo(iniFile["locale"]);
            }
            if (iniFile.ContainsKey("patternImage"))
            {
                DestinationPatternImage = iniFile["patternImage"];
            }
            if (iniFile.ContainsKey("patternAudio"))
            {
                DestinationPatternAudio = iniFile["patternAudio"];
            }
            if (iniFile.ContainsKey("patternVideo"))
            {
                DestinationPatternVideo = iniFile["patternVideo"];
            }
            if (iniFile.ContainsKey("precondition"))
            {
                CopyPrecondition = iniFile["precondition"].ToEnum <CopyPrecondition>();
            }
            if (iniFile.ContainsKey("comparator"))
            {
                FileComparator = iniFile["comparator"].ToEnum <FileComparator>();
            }
            if (iniFile.ContainsKey("copyMode"))
            {
                CopyMode = iniFile["copyMode"].ToEnum <CopyMode>();
            }
            if (iniFile.ContainsKey("exceptionHandling"))
            {
                ExceptionHandling = iniFile["exceptionHandling"].ToEnum <ExceptionHandling>();
            }
            if (iniFile.ContainsKey("fileVerification"))
            {
                FileVerification = iniFile["fileVerification"].ToEnum <FileComparator>();
            }
        }
示例#4
0
        public static bool AreFilesIdentical(this FileInfo fileInfo, FileInfo otherFile, FileComparator comparator)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException(nameof(fileInfo));
            }
            if (otherFile == null)
            {
                throw new ArgumentNullException(nameof(otherFile));
            }
            if (!fileInfo.Exists)
            {
                return(false);
            }
            if (!otherFile.Exists)
            {
                return(false);
            }

            bool identical = true;

            if (identical && comparator.HasFlag(FileComparator.FileSize))
            {
                identical &= (fileInfo.Length == otherFile.Length);
            }
            if (identical && comparator.HasFlag(FileComparator.ChecksumMD5))
            {
                identical &= fileInfo.GetMD5Sum() == otherFile.GetMD5Sum();
            }
            if (identical && comparator.HasFlag(FileComparator.ChecksumSHA1))
            {
                identical &= fileInfo.GetSHA1Sum() == otherFile.GetSHA1Sum();
            }
            if (identical && comparator.HasFlag(FileComparator.ChecksumSHA256))
            {
                identical &= fileInfo.GetSHA256Sum() == otherFile.GetSHA256Sum();
            }
            if (identical && comparator.HasFlag(FileComparator.Created))
            {
                identical &= (fileInfo.CreationTimeUtc == otherFile.CreationTimeUtc);
            }
            if (identical && comparator.HasFlag(FileComparator.Modified))
            {
                identical &= (fileInfo.LastWriteTimeUtc == otherFile.LastWriteTimeUtc);
            }
            return(identical);
        }
示例#5
0
 public static bool FileExistsInDirectory(this FileInfo fileInfo, DirectoryInfo directory, FileComparator comparator)
 {
     foreach (FileInfo tempFile in directory.GetFiles())
     {
         if (tempFile.AreFilesIdentical(fileInfo, comparator))
         {
             return(true);
         }
     }
     return(false);
 }
示例#6
0
        private void PerformSourceTargetMatching(List<FileUnit> sFileList, List<FileUnit> tFileList,
            string sDirPath, string tDirPath, Stack<SyncTask> stack)
        {
            FileComparator nameComparator = new FileComparator(true,
                false, false, false);

            tFileList.Sort(nameComparator);
            FileUnit [] tFiles = tFileList.ToArray();

            foreach (FileUnit s in sFileList)
            {
                int i = Array.BinarySearch(tFiles, s, nameComparator);

                if (i >= 0)
                {
                    s.Match = tFileList[i];
                    tFileList[i].Match = s;
                }

                ProcessSourceFileUnit(s, sDirPath, tDirPath, stack);
            }

            foreach (FileUnit t in tFileList)
            {
                if (t.Match == null)
                    ProcessTargetFileUnit(t, sDirPath, tDirPath, stack);
            }
        }
示例#7
0
        private void CheckMatchFilesConflict(FileUnit u, FileUnit sLastSync, FileUnit tLastSync)
        {
            if (sLastSync != null && tLastSync != null)
            {
                // source & target files changed
                if (sLastSync.LastWriteTime != u.LastWriteTime &&
                    tLastSync.LastWriteTime != u.Match.LastWriteTime)
                {
                    this.conflictFilesList.Add(u);
                }
                // source change, target unchanged
                else if (sLastSync.LastWriteTime != u.LastWriteTime &&
                    tLastSync.LastWriteTime == u.Match.LastWriteTime)
                {
                    this.newSourceFilesList.Add(u);
                }
                //target changed, source unchanged
                else if (sLastSync.LastWriteTime == u.LastWriteTime &&
                    tLastSync.LastWriteTime != u.Match.LastWriteTime)
                {
                    this.newTargetFilesList.Add(u.Match);
                }
                else
                    this.unchangedFilesList.Add(u);
            }
            else
            {
                FileComparator comparator = new FileComparator(true, true,
                    true, false);

                if (!u.IsDirectory && (comparator.Compare(u, u.Match) != 0))
                    this.conflictFilesList.Add(u);
                else
                    this.unchangedFilesList.Add(u);
            }
        }
示例#8
0
        public void LoadConfig()
        {
            string iniFilePath = IniConfigFileName;

            if (!File.Exists(iniFilePath))
                SaveConfig(); // Generate default config file

            IniFile iniFile = new IniFile();
            iniFile.TryLoad(iniFilePath);

            if (iniFile.ContainsKey("sourcePath"))
                sourcePath = iniFile["sourcePath"];
            if (iniFile.ContainsKey("destinationPath"))
                destinationPath = iniFile["destinationPath"];
            if (iniFile.ContainsKey("recursive"))
                Recursive = iniFile["recursive"].ToBool();
            if (iniFile.ContainsKey("locale"))
                Locale = new CultureInfo(iniFile["locale"]);
            if (iniFile.ContainsKey("patternImage"))
                DestinationPatternImage = iniFile["patternImage"];
            if (iniFile.ContainsKey("patternAudio"))
                DestinationPatternAudio = iniFile["patternAudio"];
            if (iniFile.ContainsKey("patternVideo"))
                DestinationPatternVideo = iniFile["patternVideo"];
            if (iniFile.ContainsKey("precondition"))
                CopyPrecondition = iniFile["precondition"].ToEnum<CopyPrecondition>();
            if (iniFile.ContainsKey("comparator"))
                FileComparator = iniFile["comparator"].ToEnum<FileComparator>();
            if (iniFile.ContainsKey("copyMode"))
                CopyMode = iniFile["copyMode"].ToEnum<CopyMode>();
            if (iniFile.ContainsKey("exceptionHandling"))
                ExceptionHandling = iniFile["exceptionHandling"].ToEnum<ExceptionHandling>();
            if (iniFile.ContainsKey("verifyFiles"))
                VerifyFiles = iniFile["verifyFiles"].ToBool();
        }