コード例 #1
0
ファイル: DataGenerator.cs プロジェクト: wormst/ProjektISK
        public static Packet GeneratePacket(List <Frame> frames, ChecksumType checksumType, int checksumLength)
        {
            IChecksumCalculator calculator = ChecksumCalculatorFactory.Create(checksumType);
            string framesData = string.Join("", frames.Select(f => f.GetFrame()));
            string checksum   = calculator.Calculate(framesData, checksumLength);

            return(new Packet(frames, checksum));
        }
コード例 #2
0
ファイル: DataGenerator.cs プロジェクト: wormst/ProjektISK
        public static Frame GenerateFrame(int length, ChecksumType checksumType, int checksumLength)
        {
            string data = GenerateBytes(length);

            IChecksumCalculator calculator = ChecksumCalculatorFactory.Create(checksumType);
            string checksum = calculator.Calculate(data, checksumLength);

            return(new Frame(data, checksum));
        }
コード例 #3
0
        private bool IsLineHashDifferent(IAnalysisIssueLocation location, ITextSnapshotLine snapshotLine)
        {
            if (string.IsNullOrEmpty(location.LineHash))
            {
                return(false);
            }

            var textInSnapshot   = snapshotLine.GetText();
            var snapshotLineHash = checksumCalculator.Calculate(textInSnapshot);

            return(snapshotLineHash != location.LineHash);
        }
コード例 #4
0
        public string Calculate(string documentText, int oneBasedLineNumber)
        {
            if (string.IsNullOrEmpty(documentText) || oneBasedLineNumber < 1)
            {
                return(null);
            }

            var lines = GetLines(documentText);

            if (oneBasedLineNumber > lines.Length)
            {
                return(null);
            }

            var lineToHash = lines[oneBasedLineNumber - 1];

            var hash = checksumCalculator.Calculate(lineToHash);

            return(hash);
        }
コード例 #5
0
        /// <summary>
        /// Validate the subject for the given expected checksum.
        /// The checksum is calculated and then compared to the expected one.
        /// </summary>
        /// <param name="calculator">The algorithm</param>
        /// <param name="subject">the text to check</param>
        /// <param name="expectedChecksum">the checksum that is expected</param>
        /// <returns>Is the expected checksum found</returns>
        public static bool Validate(this IChecksumCalculator calculator, string subject, int expectedChecksum)
        {
            var actualChecksum = calculator.Calculate(subject);

            return(actualChecksum == expectedChecksum);
        }