///<summary> /// Edit the specified rows via a client supplied callback ///</summary> ///<param name="indices">rows to edit</param> ///<param name="rowCallback">client supplied callback</param> public virtual void Edit(IEnumerable<int> indices, RowEditEvent rowCallback) { var fi = new FileInfo(_fileName); if ((int)fi.Length == _headerLength) { // The file is empty, so just return return; } foreach (Field field in _columns) { field.NumberConverter = new NumberConverter(field.Length, field.DecimalCount); } var fields = new Fields(_columns); using (var myStream = new FileStream(_fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, _recordLength)) { var e = new RowEditEventArgs(_recordLength - 1, fields); foreach (int rowIndex in indices) { int strt = GetFileIndex(rowIndex); long offset = _headerLength + 1 + strt * _recordLength; myStream.Seek(offset, SeekOrigin.Begin); myStream.Read(e.ByteContent, 0, _recordLength - 1); e.RowNumber = rowIndex; e.Modified = false; if (rowCallback(e)) return; if (e.Modified) { myStream.Seek(offset, SeekOrigin.Begin); myStream.Write(e.ByteContent, 0, _recordLength - 1); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="recordLength"></param> /// <param name="columns"></param> public RowEditEventArgs(int recordLength, Fields columns) { Columns = columns; ByteContent = new byte[recordLength]; Modified = false; }