// Returns content of the row forced to be instantiated without trying to reusing existing cells. private IList <LiveCell> BuildForcedRowCellsContentWithNewData <Cell>(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount, IList <Cell> cellsData) where Cell : class { // Get instance of existing cells placeholder list. IList <LiveCell> forcedRowCellsContent = new List <LiveCell>(); // Fill empty cells placeholder with appropriate number of empty cells // for the row of the number of columns specified with the provided column count. for (int cellIndex = 0; cellIndex < columnCount; cellIndex++) { // Determine cell sheet relative index of the cell to be created, // by adding left column index, to the cell order index. int cellSheetRelativeIndex = leftColumnIndex + cellIndex; // Get cell data of the type depending on the generic type the current method. Cell cellData = cellsData?.ElementAtOrDefault(cellIndex); // Build new cell instance. LiveCell cell = LiveCell.Construct(spreadsheetId, sheetTitleId, cellSheetRelativeIndex, rowSheetRelativeIndex, cellData); // Add created cell to row cells content list. forcedRowCellsContent.Add(cell); } // Return return(forcedRowCellsContent); }
// Size and content of provided IList<Cell> newRowCellsData must matching other provided parameters string spreadsheetId, string sheetTitleId, int leftColumnIndex, // int rowSheetRelativeIndex, int columnCount. private IList <LiveCell> BuildRowCellsContentWithDataOverride <Cell>(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount, IList <Cell> newRowCellsData, bool ignoreNullData) where Cell : class { // Get all existing rows data related with the provided spreadsheet id/ sheet title id / row index. IList <LiveRow> existingRowData = this._productionIndex[spreadsheetId][sheetTitleId][rowSheetRelativeIndex]; // Get instance of existing cells placeholder list. IList <LiveCell> rowCellsContent = new List <LiveCell>(); // If new row cells data has been provided simply obtain existing cells // located on the area covered by the provided parameters, // then assign the data, but only // Loop from 0 to < columnCount. Obtain existing cells wherever they are available, for (int cellRangeRelativeIndex = 0; cellRangeRelativeIndex < columnCount; cellRangeRelativeIndex++) { // Calculate cell sheet relative index for // this specific cell range relative index. int cellSheetRelativeIndex = cellRangeRelativeIndex + leftColumnIndex; // ... obtain new data for that cell if any available Cell newRowCellData = newRowCellsData?.ElementAtOrDefault(cellRangeRelativeIndex); // Loop through each existing row... foreach (LiveRow exsistingRow in existingRowData) { // ...if this specific existing row contains the cell located // on the appropriate cell sheet relative index.... if (exsistingRow.HasCellOnSheetRelativeColumnIndex(cellSheetRelativeIndex)) { // ... obtain that cell... LiveCell existingCell = exsistingRow.GetCellFromSheetRelativeColumnIndex(cellSheetRelativeIndex); // ... override data for the existing cell using provided ignoreNullData flag existingCell.SetData(newRowCellData, ignoreNullData); // ...then add cell in to the row cells content. ... rowCellsContent.Add(existingCell); // ...Then break out from foreach loop. break; } } // If existing cell hasn't been found and added in to the existing cells list, // in the above foreach loop... if (rowCellsContent.Count == cellRangeRelativeIndex) { // ...build new empty cell instance based on that data, or empty cell for null... LiveCell emptyCell = LiveCell.Construct(spreadsheetId, sheetTitleId, cellSheetRelativeIndex, rowSheetRelativeIndex, newRowCellData); // ...and add it to the existing cells list. rowCellsContent.Add(emptyCell); } } // Return constructed row cells content. return(rowCellsContent); }
// IMPORTANT NOTE // The unusual code design - repeatable code below - its a performance optimize design. // As many as possible if/else checks has been move into the level above to be // executed once for each row rather then once for each cell, and then based on that // execute appropriate build row cells content method: // BuildRowCellsContentWithoutNewData / BuildRowCellsContentWithoutDataOverride / BuildRowCellsContentWithDataOverride // Building Row Cells Content reusing existing cells where available: // Size and content of provided IList<Cell> newRowCellsData must matching other provided parameters string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount. private IList <LiveCell> BuildRowCellsContentWithoutNewData(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount) { // Get all existing rows data related with the provided spreadsheet id/ sheet title id / row index. IList <LiveRow> existingRowData = this._productionIndex[spreadsheetId][sheetTitleId][rowSheetRelativeIndex]; // Get instance of existing cells placeholder list. IList <LiveCell> rowCellsContent = new List <LiveCell>(); // Obtain existing cells located on the area covered by the provided parameters. // Loop from 0 to < columnCount for (int cellRangeRelativeIndex = 0; cellRangeRelativeIndex < columnCount; cellRangeRelativeIndex++) { // Calculate cell sheet relative index for // this specific cell range relative index. int cellSheetRelativeIndex = cellRangeRelativeIndex + leftColumnIndex; // Loop through each existing row... foreach (LiveRow exsistingRow in existingRowData) { // ...if this specific existing row contains the cell located // on the appropriate cell sheet relative index.... if (exsistingRow.HasCellOnSheetRelativeColumnIndex(cellSheetRelativeIndex)) { // ... obtain that cell... LiveCell existingCell = exsistingRow.GetCellFromSheetRelativeColumnIndex(cellSheetRelativeIndex); // ...and add it to the existing cells list. ... rowCellsContent.Add(existingCell); // ...Then break out from foreach loop. break; } } // If existing cell hasn't been found and added in to the existing cells list, // in the above foreach loop... if (rowCellsContent.Count == cellRangeRelativeIndex) { // ...build new empty cell instance... LiveCell emptyCell = LiveCell.Construct(spreadsheetId, sheetTitleId, cellSheetRelativeIndex, rowSheetRelativeIndex, null); // ...and add it to the existing cells list. rowCellsContent.Add(emptyCell); } } // Return constructed row cells content. return(rowCellsContent); }
// Returns content of the row forced to be instantiated without trying to reusing existing cells. private IList <LiveCell> BuildForcedRowCellsContentWithoutNewData(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount) { // Get instance of existing cells placeholder list. IList <LiveCell> forcedRowCellsContent = new List <LiveCell>(); // Fill empty cells placeholder with appropriate number of empty cells // for the row of the number of columns specified with the provided column count. for (int cellIndex = 0; cellIndex < columnCount; cellIndex++) { // Determine cell sheet relative index of the cell to be created, // by adding left column index, to the cell order index. int cellSheetRelativeIndex = leftColumnIndex + cellIndex; // Build new cell instance. LiveCell cell = LiveCell.Construct(spreadsheetId, sheetTitleId, cellSheetRelativeIndex, rowSheetRelativeIndex, null); // Add created cell to row cells content list. forcedRowCellsContent.Add(cell); } // Return return(forcedRowCellsContent); }