/// <summary> /// Get all rows in the table /// </summary> /// <returns>List of rows.</returns> public List <TableRow> GetRows() { List <TableRow> _rows = new List <TableRow>(); int _rowCount = RowCount; for (int _i = 0; _i < _rowCount; _i++) { TableRow _row = GetRowByIndex(_i); if (_row != null) { _rows.Add(_row); } else { #if UNITY_EDITOR string _message = string.Format("Index: {0} is out of bounds!", _i); Debug.LogError(_message); OnLogUpdate?.Invoke(null, new LogArgs(_message, false)); #endif return(null); } } return(_rows); }
/// <summary> /// Tries to remove a row from table. Will raise OnRowRemoved which will /// contain the last reference to the removed row /// </summary> /// <returns>True if removed, false if not.</returns> public bool RemoveRow(int _index) { if (_index >= RowCount) { #if UNITY_EDITOR string _message = string.Format("Can't remove row. Index: {0} is out of bounds!", _index); Debug.LogError(_message); OnLogUpdate?.Invoke(null, new LogArgs(_message, false)); #endif return(false); } List <ITableRowValue> _rows = new List <ITableRowValue>(); TableRow _row = new TableRow(_rows); int _count = ColumnCount; for (int _i = 0; _i < _count; _i++) { // Remove a row value from column and add it to the removed rows _rows.Add(columns[_i].Remove(_index)); } rowCount--; OnRowRemoved?.Invoke(null, new TableArgs(_row)); #if UNITY_EDITOR string _msg = string.Format("Row removed. Index: {0}", _index); OnLogUpdate?.Invoke(null, new LogArgs(_msg, true)); #endif return(false); }
//////////////////////////////////////////////////////////////////////// #region Remove public bool RemoveColumn(string _name) { ITableColumn _column = GetColumn(_name); if (_column != null) { OnColumnRemoved?.Invoke(null, new TableArgs(_column)); columns.RemoveAt(_column.Index); #if UNITY_EDITOR string _msg = string.Format("Removed column with name: {0}", _name); OnLogUpdate?.Invoke(null, new LogArgs(_msg, true)); #endif return(true); } #if UNITY_EDITOR string _message = string.Format("Column with name: {0} doesn't exist!", _name); Debug.LogError(_message); OnLogUpdate?.Invoke(null, new LogArgs(_message, false)); #endif ReIndexColumns(); return(false); }
public void Log(string message, LogType type = LogType.INFO) { var msg = $"{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")}: [{type}] {message}"; var x = new LogData(message, msg, type); Logs.Add(x); OnLogUpdate?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Create a row at index /// </summary> /// <returns>The row.</returns> /// <param name="_index">Index.</param> public TableRow InsertRow(int _index) { // No columns existing if (ColumnCount == 0) { #if UNITY_EDITOR string _msg = string.Format("Attempted to insert a row when no columns exist!"); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(null); } if (_index >= rowCount) { #if UNITY_EDITOR string _msg = string.Format("Cannot insert a row! Index: {0} exceeds row count: {1}", _index, rowCount); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(null); } if (_index < 0) { #if UNITY_EDITOR string _msg = string.Format("Cannot insert a row! Negative index: {0}", _index); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(null); } List <ITableRowValue> _columns = new List <ITableRowValue>(); int _count = ColumnCount; for (int _i = 0; _i < _count; _i++) { ITableRowValue rowValue = columns[_i].CreateTableRow(string.Empty, _index); _columns.Add(rowValue); } // Increment row count rowCount++; TableRow _row = new TableRow(_columns); OnRowInserted?.Invoke(null, new TableArgs(_row)); #if UNITY_EDITOR string _message = string.Format("Row inserted. Index: {0}", _index); OnLogUpdate?.Invoke(null, new LogArgs(_message, true)); #endif return(_row); }
public void writeResultData(string data) { log.Add(new LogEntry(index, new Tuple <bool, string>(true, data))); index++; if (!supressUpdates) { OnLogUpdate?.Invoke(this, new EventArgs()); } }
public void writeLogMessage(string message) { log.Add(new LogEntry(index, new Tuple <bool, string>(false, message))); index++; if (!supressUpdates) { OnLogUpdate?.Invoke(this, new EventArgs()); } }
//////////////////////////////////////////////////////////////////////// #region Shift Rows /// <summary> /// Move a row to another index /// </summary> public bool ShiftRow(int _indexFrom, int _indexTo) { if (_indexFrom == _indexTo) { #if UNITY_EDITOR string _msg = string.Format("Cannot shift rows with same index: {0}", _indexFrom); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(false); } if (RowCount > -1) { if (_indexFrom < 0 || _indexFrom >= RowCount || _indexTo < 0 || _indexTo >= RowCount) { #if UNITY_EDITOR string _msg = string.Format( "Cannot shift rows, index out of bounds! Index from: {0}, Index To: {1}, Row Count: {2}", _indexFrom, _indexTo, RowCount ); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(false); } int _count = ColumnCount; for (int _i = 0; _i < _count; _i++) { columns[_i].ShiftRows(_indexFrom, _indexTo); } OnRowShifted?.Invoke(null, new TableArgs(_indexFrom, _indexTo)); #if UNITY_EDITOR string _message = string.Format("Row shifted. From Index: {0}, To Index: {1}", _indexFrom, _indexTo); OnLogUpdate?.Invoke(null, new LogArgs(_message, true)); #endif return(true); } return(false); }
//////////////////////////////////////////////////////////////////////// #region Create /// <summary> /// Creates a column and adds all necessary rows to it. /// </summary> /// <returns>False if column with the name already exists</returns> public bool CreateColumn(string _name) { if (string.IsNullOrEmpty(_name)) { #if UNITY_EDITOR string _msg = string.Format("Can't create a column. Column must have a name!"); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(false); } if (ColumnExists(_name)) { #if UNITY_EDITOR string _msg = string.Format("Can't create a column. Column with name: {0}, already exists!", _name); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(false); } // Create column TableColumn _column = new TableColumn(_name, ColumnCount); // Add to list columns.Add(_column); // Create rows in the column for (int _i = 0; _i < rowCount; _i++) { _column.CreateTableRow(string.Empty); } OnColumnCreated?.Invoke(null, new TableArgs(_column)); #if UNITY_EDITOR string _message = string.Format("Created a column with name: {0}", _name); OnLogUpdate?.Invoke(null, new LogArgs(_message, true)); #endif ReIndexColumns(); return(true); }
//////////////////////////////////////////////////////////////////////// #region Update public bool UpdateColumnName(string _newName, ITableColumn _column) { if (ColumnExists(_newName)) { #if UNITY_EDITOR string _msg = string.Format("Can't rename column {0}. Column with name: {1}, already exists!", _column.ColumnName, _newName); Debug.LogError(_msg); OnLogUpdate?.Invoke(null, new LogArgs(_msg, false)); #endif return(false); } TableColumn _cast = _column as TableColumn; _cast?.UpdateName(_newName); return(true); }
/// <summary> /// Get a number of rows starting from index /// </summary> /// <returns>The rows.</returns> /// <param name="_startIndex">Start index.</param> /// <param name="_count">Count.</param> /// <param name="_isPagination">True ONLY when you are displaying rows on a page, if false, will display error if trying to get too many rows.</param> public List <TableRow> GetRows(int _startIndex, int _count, bool _isPagination) { if (RowCount == 0) { return(null); } if (!_isPagination && _startIndex >= RowCount) { #if UNITY_EDITOR string _message = string.Format("Can't select rows. Index: {0} is out of bounds!", _startIndex); Debug.LogError(_message); OnLogUpdate?.Invoke(null, new LogArgs(_message, false)); #endif return(null); } List <TableRow> _rows = new List <TableRow>(); // Last item which should be added to the list int _endIndex = _startIndex + _count; int _rowCount = _count > RowCount ? RowCount : _count; for (int _i = _startIndex; _i < _rowCount; _i++) { TableRow _row = GetRowByIndex(_i); if (_row != null) { _rows.Add(_row); } else { #if UNITY_EDITOR string _message = string.Format("Index: {0} is out of bounds!", _i); Debug.LogError(_message); OnLogUpdate?.Invoke(null, new LogArgs(_message, false)); #endif return(null); } } return(_rows); }
public void RemoveColumn(ITableColumn _column) { if (_column.Index >= columns.Count || _column.Index < 0) { #if UNITY_EDITOR string _message = string.Format("Can't remove column. Index: {0} is out of bounds!", _column); Debug.LogError(_message); OnLogUpdate?.Invoke(null, new LogArgs(_message, false)); #endif return; } columns.RemoveAt(_column.Index); OnColumnRemoved?.Invoke(null, new TableArgs(_column)); #if UNITY_EDITOR string _msg = string.Format("Removed column with name: {0}, index: {1}", _column.ColumnName, _column.Index); OnLogUpdate?.Invoke(null, new LogArgs(_msg, true)); #endif ReIndexColumns(); }
public void Log(LogData data) { data.Data = $"{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")}: [{data.Type}] {data.Data}"; Logs.Add(data); OnLogUpdate?.Invoke(this, EventArgs.Empty); }
private void _logger_OnLogUpdate(object sender, EventArgs e) { OnLogUpdate?.Invoke(this, EventArgs.Empty); }