示例#1
0
        public bool CanFilesOfEqualLengthBeTreatedEqual(FolderUpdateMethod folderUpdateMethod, string mainNamespace, IReadOnlyList <byte> sourceContents, IReadOnlyList <byte> destinationContents,
                                                        FileInfo sourceFileInfo, bool hasSomethingBeenUpdated, FileSystemInfo destinationFileInfo, out string updateReason)
        {
            updateReason = Properties.Resources.FilesHaveEqualLengthThatCannotBeIgnored;
            var differences = sourceContents.Where((t, i) => t != destinationContents[i]).Count();

            if (differences == 0)
            {
                return(true);
            }

            updateReason = string.Format(Properties.Resources.FilesHaveEqualLengthButNDifferences, differences);
            return(folderUpdateMethod == FolderUpdateMethod.AssembliesButNotIfOnlySlightlyChanged && IsBinary(sourceFileInfo.Name) && differences < 30 && sourceFileInfo.Length >= MinimumBinaryFileSizeInBytes);
        }
示例#2
0
        public void UpdateFolder(IFolder sourceFolder, IFolder destinationFolder, FolderUpdateMethod folderUpdateMethod, string mainNamespace, IErrorsAndInfos errorsAndInfos)
        {
            if (folderUpdateMethod != FolderUpdateMethod.AssembliesButNotIfOnlySlightlyChanged && folderUpdateMethod != FolderUpdateMethod.AssembliesEvenIfOnlySlightlyChanged)
            {
                throw new NotImplementedException("Update method is not implemented");
            }

            if (!destinationFolder.Exists())
            {
                Directory.CreateDirectory(destinationFolder.FullName);
            }

            var hasSomethingBeenUpdated = false;

            foreach (var sourceFileInfo in Directory.GetFiles(sourceFolder.FullName, "*.*", SearchOption.AllDirectories).Select(f => new FileInfo(f)))
            {
                var    destinationFileInfo = new FileInfo(destinationFolder.FullName + '\\' + sourceFileInfo.FullName.Substring(sourceFolder.FullName.Length));
                string updateReason;
                if (File.Exists(destinationFileInfo.FullName))
                {
                    if (sourceFileInfo.Length == 0 && destinationFileInfo.Length == 0)
                    {
                        continue;
                    }

                    if (sourceFileInfo.Length == destinationFileInfo.Length)
                    {
                        var sourceContents      = File.ReadAllBytes(sourceFileInfo.FullName);
                        var destinationContents = File.ReadAllBytes(destinationFileInfo.FullName);
                        if (sourceContents.Length == destinationContents.Length)
                        {
                            if (BinariesHelper.CanFilesOfEqualLengthBeTreatedEqual(folderUpdateMethod, mainNamespace, sourceContents, destinationContents, sourceFileInfo, hasSomethingBeenUpdated, destinationFileInfo, out updateReason))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            updateReason = string.Format(Properties.Resources.FilesDifferInLength, sourceContents.Length, destinationContents.Length);
                        }
                    }
                    else
                    {
                        updateReason = string.Format(Properties.Resources.FilesDifferInLength, sourceFileInfo.Length, destinationFileInfo.Length);
                    }
                }
                else
                {
                    updateReason = string.Format(Properties.Resources.FileIsNew);
                }

                errorsAndInfos.Infos.Add(string.Format(Properties.Resources.UpdatingFile, sourceFileInfo.Name) + ", " + updateReason);
                if (!string.IsNullOrEmpty(destinationFileInfo.DirectoryName) && !Directory.Exists(destinationFileInfo.DirectoryName))
                {
                    Directory.CreateDirectory(destinationFileInfo.DirectoryName);
                }

                if (!CopyFileReturnSuccess(sourceFileInfo, destinationFileInfo, errorsAndInfos))
                {
                    continue;
                }

                hasSomethingBeenUpdated = true;
            }
        }
示例#3
0
 public void UpdateFolder(IFolder sourceFolder, IFolder destinationFolder, FolderUpdateMethod folderUpdateMethod, IErrorsAndInfos errorsAndInfos)
 {
     UpdateFolder(sourceFolder, destinationFolder, folderUpdateMethod, "", errorsAndInfos);
 }