예제 #1
0
        /// <summary>
        /// Returns the given pending change if it should be undone, otherwise null.
        /// </summary>
        private Task <PendingChange> ShouldUndoPendingChangeAsync(PendingChange pendingChange)
        {
            return(Task.Run(() =>
            {
                if (pendingChange.IsAdd || pendingChange.IsDelete || pendingChange.IsLocalItemDelete || pendingChange.IsUndelete)
                {
                    return null;
                }

                byte[] baseItemHashCode;

                try
                {
                    using (var baseFileStream = pendingChange.DownloadBaseFile())
                    {
                        using (var hashAlgorithem = new SHA1Cng())
                        {
                            baseItemHashCode = hashAlgorithem.ComputeHash(baseFileStream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    const string ErrorMessageFormat = "Error occurred during computing hash for the base item of {0}: {1}";

                    LoggerUtilities.LogError(string.Format(CultureInfo.CurrentCulture, ErrorMessageFormat, pendingChange.ServerItem, ex.ToString()));

                    return null;
                }

                byte[] localItemHashCode;

                try
                {
                    using (var localFileStream = new FileStream(Path.GetFullPath(pendingChange.LocalItem), FileMode.Open, FileAccess.Read))
                    {
                        using (var hashAlgorithem = new SHA1Cng())
                        {
                            localItemHashCode = hashAlgorithem.ComputeHash(localFileStream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    const string ErrorMessageFormat = "Error occurred during computing hash for the local item of {0}: {1}";

                    LoggerUtilities.LogError(string.Format(CultureInfo.CurrentCulture, ErrorMessageFormat, pendingChange.ServerItem, ex.ToString()));

                    return null;
                }

                return Enumerable.SequenceEqual(baseItemHashCode, localItemHashCode) ? pendingChange : null;
            }));
        }
예제 #2
0
        public static bool HasReallyChange(this PendingChange pendingChange)
        {
            if (pendingChange.IsAdd || string.IsNullOrEmpty(Path.GetExtension(pendingChange.LocalItem)) || !File.Exists(pendingChange.LocalItem))
            {
                return(true);
            }
            string tempFileName = Path.GetTempFileName();

            pendingChange.DownloadBaseFile(tempFileName);

            var diffOptions = new DiffOptions
            {
                Flags = DiffOptionFlags.IgnoreWhiteSpace
            };

            var summary = Common.DiffSummary.DiffFiles(tempFileName, FileType.Detect(tempFileName, FileType.TextFileType), pendingChange.LocalItem, FileType.Detect(pendingChange.LocalItem, FileType.TextFileType), diffOptions);
            var res     = summary.TotalLinesAdded != 0 || summary.TotalLinesDeleted != 0 || summary.TotalLinesModified != 0;

            return(res);
        }
예제 #3
0
 /// <summary>
 /// Downloads the base file.
 /// </summary>
 /// <param name="filePathToDownloadFileTo">The file path to download file to.</param>
 public void DownloadBaseFile(string filePathToDownloadFileTo)
 {
     _pendingChange.DownloadBaseFile(filePathToDownloadFileTo);
 }