// Possibly more expensive performance wise, but it will assure that each cell has only one // instance of LiveCell representing it ever initialized. #region Get // Empty from parameters using already existing cells wherever available. internal LiveRow Get(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount) { // Assure that the appropriate space in the factory production index is existing to start the production process. this._productionIndex.AssureStorageSpace(spreadsheetId, sheetTitleId, rowSheetRelativeIndex); // Get row covering requested area if already existing. LiveRow requestedRow = this._productionIndex.GetExistingRow(spreadsheetId, sheetTitleId, leftColumnIndex, rowSheetRelativeIndex, columnCount); // If requested row already exists... if (!(requestedRow is null)) { // ...return it. return(requestedRow); } // Build new row cells content using appropriate row cells content creation method to create // the new row cells content build from the existing cells wherever possible... IList <LiveCell> rowCellsContent = this.BuildRowCellsContentWithoutNewData( // Row cells content spreadsheet id spreadsheetId, // Row cells content sheet title id sheetTitleId, // Row most left column index leftColumnIndex, // Row sheet relative index rowSheetRelativeIndex, // Total number of the cells covered by the row columnCount); // Manufacture and return newly create row. return(this.Manufacture(spreadsheetId, sheetTitleId, leftColumnIndex, rowSheetRelativeIndex, columnCount, rowCellsContent)); }
// The only method which should call the LiveRow constructor. private LiveRow Manufacture(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount, IList <LiveCell> rowCellsContent) { // Build new instance of LiveRow class using provided parameters... LiveRow newRow = new LiveRow( // Row cells content spreadsheet id spreadsheetId, // Row cells content sheet title id sheetTitleId, // Row most left column index leftColumnIndex, // Row sheet relative index rowSheetRelativeIndex, // Total number of the cells covered by the row columnCount, // Row cells content rowCellsContent); // Add newly instantiated LiveRow into the factory production index. this._productionIndex.AddSpecificRow(newRow); // Return newly created row. return(newRow); }
// Simply removed row stored in the factory production index. public void RemoveStoredRow(LiveRow toBeRemovedRow) { this._productionIndex.RemoveSpecificRow(toBeRemovedRow); }
// Re-Indexing provided row, increasing the row index it is indexed to by the provided rowIndexChangeByValue internal void ReIndexStoredRow(LiveRow rowToBeReIndexed, int rowIndexChangeByValue) { this._productionIndex.ReIndexStoredRow(rowToBeReIndexed, rowIndexChangeByValue); }
// Internal generic base // Returns new instance of LiveRow class, build based on, and pre-filled with the provided new row cell data. // The row will be created assuring that all of the cells which already existing will be reused, new cells // created where existing ones not available, and both of them - depending on the boolean flags provided // - will be filled with provided data, possibly overwriting exsisting data. internal LiveRow Get <Cell>(string spreadsheetId, string sheetTitleId, int leftColumnIndex, int rowSheetRelativeIndex, int columnCount, IList <Cell> newRowCellsData, bool overrideExistingData = true, bool overrideOnNullInput = false) where Cell : class { // Assure that the appropriate space in the factory production index is existing to start the production process. this._productionIndex.AssureStorageSpace(spreadsheetId, sheetTitleId, rowSheetRelativeIndex); // Get row covering requested area if already existing. LiveRow requestedRow = this._productionIndex.GetExistingRow(spreadsheetId, sheetTitleId, leftColumnIndex, rowSheetRelativeIndex, columnCount); // If requested row already exists... if (!(requestedRow is null)) { // ... and if provided override existing data flag is true // as well as newRowCellsData has been provided... if (overrideExistingData && !(newRowCellsData is null)) { // Set data of existing row using provided new row cells data. requestedRow.SetDataFromCellsData( // Do not get confuse left buffer index with left column index leftBufferIndex: 0, // Cells data cellsData: newRowCellsData, // Ignore null data flag set according inversed overrideOnNullInput flag ignoreNullData: !overrideOnNullInput); } // ...return it. return(requestedRow); } // Declare new row cells content... IList <LiveCell> newRowCellsContent; // If no new row cells data designated for the new row has been provided... if (newRowCellsData is null) { //... use appropriate row cells content creation method to create // the new row cells content build from the existing cells wherever possible... newRowCellsContent = this.BuildRowCellsContentWithoutNewData( // Row cells content spreadsheet id spreadsheetId, // Row cells content sheet title id sheetTitleId, // Row most left column index leftColumnIndex, // Row sheet relative index rowSheetRelativeIndex, // Total number of the cells covered by the row columnCount); } // Else if new row cells data has been provided, and override existing data // flag indicating that it should not be overriding any existing data... else if (!overrideExistingData) { //... use appropriate row cells content creation method to create // the new row cells content, build from the existing cells wherever possible. // As well as creating new cells pre-filled with new row cells data wherever // existing cell is not available... newRowCellsContent = this.BuildRowCellsContentWithoutDataOverride( // Row cells content spreadsheet id spreadsheetId, // Row cells content sheet title id sheetTitleId, // Row most left column index leftColumnIndex, // Row sheet relative index rowSheetRelativeIndex, // Total number of the cells covered by the row columnCount, // Null as no other data then already existing is available. - Optional parameter null is default value. newRowCellsData); } // Else if new row cells data has been provided, and override existing data // flag indicating that it should override the existing data... else { //... use appropriate row cells content creation method to create // the new row cells content, build from the existing cells wherever possible, // and overriding existing cells data wherever provided new row cells data // is overlapping any existing cell as well as creating new cells pre-filled // with new row cells data wherever existing cell is not available... newRowCellsContent = this.BuildRowCellsContentWithDataOverride( // Row cells content spreadsheet id spreadsheetId, // Row cells content sheet title id sheetTitleId, // Row most left column index leftColumnIndex, // Row sheet relative index rowSheetRelativeIndex, // Total number of the cells covered by the row columnCount, // Null as no other data then already existing is available. - Optional parameter null is default value. newRowCellsData, // False as existing data should not be overridden. As null has been provided above // providing true should not matter anyway. - Optional parameter false is NOT default value. overrideOnNullInput); } // Manufacture and return newly create row. return(this.Manufacture(spreadsheetId, sheetTitleId, leftColumnIndex, rowSheetRelativeIndex, columnCount, newRowCellsContent)); }