public void ShiftColumnDown() { IGridConfiguration conf = CreateTestConfig(); IGrid grid = new SquareGrid(conf); List <ICellContent> contents = new List <ICellContent>(conf.ColumnCount * conf.RowCount); FillColumnContents(grid, contents); Assert.AreSame(contents[0], grid.Columns[0][0].Content); Assert.AreSame(contents[1], grid.Columns[0][1].Content); ICellContent firstRowContent = grid.Columns[0][0].Content; grid.Accept(new ColumnDownShifter(0, 3)); Assert.AreSame(firstRowContent, grid.Columns[0][3].Content); grid.Accept(new ColumnDownShifter(0, 10)); Assert.AreSame(firstRowContent, grid.Columns[0][3].Content); grid.Accept(new ColumnDownShifter(0, 13)); Assert.AreSame(firstRowContent, grid.Columns[0][1].Content); }
public void Put(ICellContent content) { if (!this.IsEmpty) { throw new InvalidOperationException(); } this.Content = content; }
public void SetGridCellContent() { IGridConfiguration conf = CreateTestConfig(); IGrid grid = new SquareGrid(conf); ICellContent content = Substitute.For <ICellContent>(); Cell.Cell cell = grid.GetCell(0, 0); cell.Content = content; Assert.AreEqual(content, grid.GetCell(0, 0).Content); }
void FillColumnContents(IGrid grid, List <ICellContent> contents) { foreach (CellCollection column in grid.Columns) { column.Foreach(delegate(Cell.Cell c) { ICellContent content = Substitute.For <ICellContent>(); c.Content = content; contents.Add(content); }); } }
void FillRowContents(IGrid grid, List <ICellContent> contents) { foreach (CellCollection row in grid.Rows) { row.Foreach(delegate(Cell.Cell c) { ICellContent content = Substitute.For <ICellContent>(); c.Content = content; contents.Add(content); }); } }
private static void ConvertFile(String sourcePath) { using (FileStream input = File.OpenRead(sourcePath)) using (BinaryReader br = new BinaryReader(input)) { CshHeader header = new CshHeader { Type = br.ReadBigUInt32(), ColumnNumber = br.ReadBigUInt32(), RowNumber = br.ReadBigUInt32() }; if (header.Type != 0) { throw new NotSupportedException($"Unknown type: {header.Type}"); } CshCell[] cells = new CshCell[header.ColumnNumber * header.RowNumber]; input.DangerousReadStructs(cells, cells.Length); String targetPath = Path.ChangeExtension(sourcePath, ".csv"); ICellContent[] buff = new ICellContent[header.ColumnNumber]; using (CsvWriter writer = new CsvWriter(targetPath)) { Int32 cellIndex = 0; for (Int32 r = 0; r < header.RowNumber; r++) { for (Int32 c = 0; c < header.ColumnNumber; c++) { CshCell cell = cells[cellIndex++]; ICellContent content = ReadContent(input, cell); buff[c] = content; } ContentEntry entry = new ContentEntry(buff); writer.WriteEntry(entry, null); } } } }
public Cell(ICellContent content, Coordinates coords) { this.Coordinates = coords; this.Put(content); }
public void AddContent(ICellContent openXmlParagraphModel) { _contents.Add(openXmlParagraphModel); }
public void Empty() { Content = NullContent.Instance; }
private static void TransformBackFile(String csvPath, String decPath) { String tmpPath; CshCell[] cells; using (FileStream decInput = File.OpenRead(decPath)) using (BinaryReader decBr = new BinaryReader(decInput)) { CshHeader header = new CshHeader { Type = decBr.ReadBigUInt32(), ColumnNumber = decBr.ReadBigUInt32(), RowNumber = decBr.ReadBigUInt32() }; if (header.Type != 0) { throw new NotSupportedException($"Unknown type: {header.Type}"); } cells = new CshCell[header.ColumnNumber * header.RowNumber]; decInput.DangerousReadStructs(cells, cells.Length); RowCsvEntry[] data = CsvReader.Read <RowCsvEntry>(csvPath); if (header.RowNumber != data.Length) { throw new InvalidDataException($"header.RowNumber ({header.RowNumber}) != data.Length ({data.Length})"); } tmpPath = decPath + ".tmp"; using (FileStream decOutput = File.Create(tmpPath)) using (BinaryWriter decBw = new BinaryWriter(decOutput)) { decBw.WriteBig(header.Type); decBw.WriteBig(header.ColumnNumber); decBw.WriteBig(header.RowNumber); Int64 headerOffset = decOutput.Position; // Reserve space for header decOutput.DangerousWriteStructs(cells, cells.Length); if (decOutput.Position != decInput.Position) { throw new InvalidDataException(); } AlignData(decOutput); Int32 cellIndex = 0; for (Int32 r = 0; r < header.RowNumber; r++) { RowCsvEntry row = data[r]; for (Int32 c = 0; c < header.ColumnNumber; c++) { CshCell cell = cells[cellIndex++]; ICellContent cellContent = ReadContent(decInput, cell); if (cell.Offset != 0) { cell.Offset = (UInt32)decOutput.Position; cells[cellIndex - 1] = cell; // It's a struct } if (cellContent is StringContent str) { str.ParseValue(CsvParser.String(row.Raw[c])); } cellContent.Write(decOutput, decBw); AlignData(decOutput); } } // Update offsets decOutput.Position = headerOffset; decOutput.DangerousWriteStructs(cells, cells.Length); // For test //CheckFiles(decInput, decOutput); } } File.Delete(decPath); File.Move(tmpPath, decPath); }