/// <summary> /// Create a full snapshort of this table /// </summary> /// <returns></returns> public TableDto ToSnapshot() { var dto = new TableDto { TableName = this.TableName, Id = this.TableName, DateTime = this.DateTime, RowsCount = Data.GetLength(0), ColumnsCount = Data.GetLength(1), IsComplete = true, Version = Version, Cells = new List <TableCell>() }; for (int row = 0; row < dto.RowsCount; row++) { for (int column = 0; column < dto.ColumnsCount; column++) { var value = Data[row, column]; // default(Variant) has this type if (value.TypeEnum == TypeEnum.None) { continue; } dto.Cells.Add(new TableCell { Row = row, Column = column, Value = value }); } } return(dto); }
public static Table FromSnapshot(TableDto dto) { if (!dto.IsComplete) { throw new ArgumentException("Snapshot must be complete"); } var table = new Table(dto.RowsCount, dto.ColumnsCount) { TableName = dto.TableName, DateTime = dto.DateTime, Version = dto.Version, }; foreach (var cell in dto.Cells) { table.Data[cell.Row, cell.Column] = cell.Value; } return(table); }
public TableDto ToDelta(Table previous) { if (RowsCount != previous.RowsCount || ColumnsCount != previous.ColumnsCount) { return(ToSnapshot()); } var dto = new TableDto { TableName = this.TableName, Id = this.TableName, DateTime = this.DateTime, RowsCount = Data.GetLength(0), ColumnsCount = Data.GetLength(1), IsComplete = false, Version = Version, Cells = new List <TableCell>() }; for (var row = 0; row < dto.RowsCount; row++) { for (var column = 0; column < dto.ColumnsCount; column++) { var value = Data[row, column]; var previousValue = previous.Data[row, column]; if (value == previousValue) { continue; } dto.Cells.Add(new TableCell { Row = row, Column = column, Value = value }); } } return(dto); }
public static Table ApplyDelta(Table previous, TableDto dto) { if (previous.RowsCount != dto.RowsCount || previous.ColumnsCount != dto.ColumnsCount || dto.IsComplete) { Trace.Assert(dto.IsComplete); return(FromSnapshot(dto)); } var dataCopy = (Variant[, ])previous.Data.Clone(); var table = new Table(dataCopy) { TableName = dto.TableName, DateTime = dto.DateTime, Version = dto.Version, }; foreach (var cell in dto.Cells) { table.Data[cell.Row, cell.Column] = cell.Value; } return(table); }