/// <summary> /// Calculate a Hash for a DataView and the calculates the size of the DataView, too. /// </summary> /// <remarks><em>Do not use for creation of a password hash</em> - this Method uses the SHA1 algorithm /// for speed reasons but this is not deemed safe enough for password hashing! --> Use /// PasswordHelper.GetPasswordHash() for this instead!!!</remarks> /// <param name="AHashDV">The DataView to be analysed.</param> /// <param name="AHash">Returns the Hash value of the DataView.</param> /// <param name="ASize">Returns the size of the DataView.</param> public static void CalculateHashAndSize(DataView AHashDV, out String AHash, out Int32 ASize) { StringBuilder HashStringBuilder; SHA1CryptoServiceProvider HashingProvider; Int32 RowCounter; Int32 ColumnCounter; Int32 TmpSize = 0; ASize = 0; /* * Build a string that contains all values of all rows in the DataView, using * a StringBuilder for efficiency. */ HashStringBuilder = new StringBuilder(); for (RowCounter = 0; RowCounter <= AHashDV.Count - 1; RowCounter += 1) { for (ColumnCounter = 0; ColumnCounter <= AHashDV.Table.Columns.Count - 1; ColumnCounter += 1) { if (AHashDV.Table.Columns[ColumnCounter].DataType != System.Type.GetType("System.DateTime")) { HashStringBuilder.Append( RowCounter.ToString() + '/' + ColumnCounter.ToString() + ':' + AHashDV[RowCounter][ColumnCounter].ToString()); } else { HashStringBuilder.Append(RowCounter.ToString() + '/' + ColumnCounter.ToString() + ':' + TSaveConvert.DateColumnToDate(AHashDV.Table.Columns[ColumnCounter], AHashDV[RowCounter].Row).ToString("dd-MM-yy HH:MM")); } // Increment the size TmpSize = AHashDV[RowCounter][ColumnCounter].ToString().Length; ASize = ASize + TmpSize; } } /* * Calculate the hash of the string containing all values of all rows */ HashingProvider = new SHA1CryptoServiceProvider(); AHash = Convert.ToBase64String(HashingProvider.ComputeHash(Encoding.UTF8.GetBytes(HashStringBuilder.ToString()))); }
/// <summary> /// /// </summary> private IEnumerable <ICharMetric> EnumerateCharMetricsByLine(int lineIndex, bool isTabProcess, bool isAddMetaChar) { var chars = _textView.Doc.Lines[lineIndex].Text.AsEnumerable(); if (isAddMetaChar) { if (lineIndex < _textView.Doc.Lines.LastIndex()) { chars = chars.Append(CharUtil.Space); } DebugUtil.DebugCode(() => { if (lineIndex < _textView.Doc.Lines.LastIndex()) { chars = chars.SkipLast(1).Append('↓'); } else { chars = chars.Concat("[EOF]"); } }); } var lineHeight = _textView.GetLineHeight(); var columnCounter = new ColumnCounter(_textView._settings.tabWidth); var originalIndex = 0; var index = 0; var lineLength = _textView.Doc.Lines[lineIndex].Length; var x = 0.0; var chItem = new CharMetric(); foreach (var ch in chars) { columnCounter.Add(ch); var sourceChar = ch; var color = Color.Black; var backgroundColor = Color.Transparent; #warning test //if (!CharUtil.CanDraw(ch) && ch != CharUtil.Tab) //{ // // バイナリファイルを開いた場合でも、それとなく表示できるようにしておく // ch = '?'; //} if (sourceChar == CharUtil.Tab && isTabProcess) { sourceChar = CharUtil.Space; for (var i = 0; i < columnCounter.LastCharCount; i++) { DebugUtil.DebugCode(() => { sourceChar = i == 0 ? '>' : '.'; color = Color.DarkCyan; backgroundColor = Color.FromRgb(0x00aaaa); }); var width = _textView.AsciiFont.MeasureChar(sourceChar).Width; yield return(chItem.Init( lineIndex, lineHeight, sourceChar, x, index, originalIndex, 1, color, backgroundColor, _textView.AsciiFont, width, _textView._settings.lineHeightAdjust / 2.0)); x += width; index++; } } else { DebugUtil.DebugCode(() => { if (sourceChar == CharUtil.FullWidthSpace) { sourceChar = '□'; color = Color.DarkCyan; } if (originalIndex >= lineLength) { color = Color.DarkCyan; } }); var tempChar = (sourceChar == CharUtil.Tab) ? CharUtil.Space : sourceChar; var font = CharUtil.IsAscii(tempChar) ? _textView.AsciiFont : _textView.JpFont; var width = font.MeasureChar(tempChar).Width *columnCounter.LastCharCount; yield return(chItem.Init( lineIndex, lineHeight, sourceChar, x, index, originalIndex, columnCounter.LastColumnCount, color, backgroundColor, font, width, _textView._settings.lineHeightAdjust / 2.0)); x += width; index++; } originalIndex++; } }