コード例 #1
0
        /// <summary>
        /// This function will either assign the right value of the diff entry if it
        /// exists or create a new one with the right value and id.
        /// </summary>
        /// <param name="id">ID of entry</param>
        /// <param name="value">New right value</param>
        public static void AddRightValue(int id, string value)
        {
            int diffIndex = diffs.FindIndex(d => d.ID == id);

            if (diffIndex > -1)
            {
                diffs[diffIndex].Right = value;

                DiffDB.SaveEntry(diffs[diffIndex]);

                return;
            }

            DiffEntry newDiff = new DiffEntry(id, "", value);

            DiffDB.SaveEntry(newDiff);

            diffs.Add(newDiff);
        }
コード例 #2
0
        /// <summary>
        /// Tries to find and compare the values of a desired DiffEntry
        /// </summary>
        /// <param name="id">ID of DiffEntry to compare</param>
        public static DiffResult Compare(int id)
        {
            // Try to find the desired DiffEntry
            DiffEntry entry = diffs.Find(d => d.ID == id);

            if (entry == null || entry.Left == string.Empty || entry.Right == string.Empty)
            {
                // Invalid ID or incomplete entry so return appropriate diff result
                return(new DiffResult {
                    Valid = false
                });
            }

            if (entry.Left.Length != entry.Right.Length)
            {
                // Lenghts don't match so return that
                return(new DiffResult {
                    Valid = true,
                    ResultType = DiffResult.DiffResultType.SizeDoNotMatch
                });
            }

            if (entry.Left != entry.Right)
            {
                // The data is of the same length so let's compare and
                // return the results.
                return(compareByteArrays(entry.Left, entry.Right));
            }

            // If all the checks pass, the data is the same.
            // Return appropriate result.
            return(new DiffResult {
                Valid = true,
                ResultType = DiffResult.DiffResultType.Equals
            });
        }