public IFrame Copy(IFrame srcFrame, Guid newFrameId, bool copyData) { if (!(srcFrame is SimpleFrame)) throw new ArgumentException("srcFrame"); SimpleFrame copy = null; if (copyData) return Copy(srcFrame, newFrameId); if (srcFrame is SimpleFrame) { SimpleFrame srcSimpleFrame = srcFrame as SimpleFrame; copy = new SimpleFrame(newFrameId); copy.MinimumCapacity = srcSimpleFrame.RowCount; foreach (DataColumn col in srcSimpleFrame.Columns) { DataColumn newCol = CopyColumn(col); copy.Columns.Add(newCol); } for (int i = 0; i < srcSimpleFrame.Rows.Count; i++) { copy.Rows.Add(copy.NewRow()); } copy.AcceptChanges(); } return copy; }
public IFrame Merge(IFrame frame0, IFrame frame1, Guid newFrameId) { SimpleFrame merged = null; if (frame0.RowCount != frame1.RowCount) { throw new ArgumentException(string.Format("The input frames must have the same number of rows before being merged.")); } if (!(frame0 is SimpleFrame)) throw new ArgumentException(string.Format("Invalid type: must be of type {0}.", typeof(SimpleFrame).Name), "frame0"); if (!(frame1 is SimpleFrame)) throw new ArgumentException(string.Format("Invalid type: must be of type {0}.", typeof(SimpleFrame).Name), "frame1"); if (frame0 == frame1) { throw new ArgumentException(string.Format("Both input frame parameters represent the same instance. A frame cannot be merged with itself.")); } SimpleFrame baseFrame0 = frame0 as SimpleFrame; SimpleFrame baseFrame1 = frame1 as SimpleFrame; merged = new SimpleFrame(newFrameId); using (SimpleFrameDataCopier copier = new SimpleFrameDataCopier()) { merged = copier.Copy(frame0, newFrameId) as SimpleFrame; } int[] colIndices = new int[baseFrame1.Columns.Count]; for (int i = 0; i < baseFrame1.Columns.Count; i++) { string [] existingColNames = merged.ColumnNames; DataColumn column = new DataColumn( NamingHelper.MakeUnique(existingColNames, baseFrame1.Columns[i].ColumnName), baseFrame1.Columns[i].DataType); colIndices[i] = merged.Columns.Count; merged.Columns.Add(column); } for (int i = 0; i < merged.Rows.Count; i++) { for (int j = 0; j < colIndices.Length; j++) { merged.Rows[i][colIndices[j]] = baseFrame1.Rows[i][j]; } } merged.AcceptChanges(); return merged; }
public IFrame Copy(IFrame srcFrame, Guid newFrameId) { if (!(srcFrame is SimpleFrame)) throw new ArgumentException("srcFrame"); SimpleFrame copy = null; if (srcFrame is SimpleFrame) { SimpleFrame srcSimpleFrame = srcFrame as SimpleFrame; copy = new SimpleFrame(newFrameId); using (DataTableReader reader = new DataTableReader(srcSimpleFrame)) { copy.Load(reader); } copy.AcceptChanges(); } return copy; }
public SimpleFrameColumnObjectAccessor(int colIndex, SimpleFrame table) { _Table = table; _ColIndex = colIndex; _Column = _Table.Columns[_ColIndex]; }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. /// 1) If <paramref name="disposing"/> equals true, the method has been called directly /// or indirectly by a user's code: managed and unmanaged resources can be disposed. /// 2) If <paramref name="disposing"/> equals false, the method has been called by the runtime from inside /// the finalizer and you should not reference other objects: only unmanaged resources can be disposed. /// </summary> /// <param name="disposing">If calling from client code, set to true</param> protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { _Column = null; _Table = null; } } _disposed = true; }
public void TearDown() { _Table = null; }
public void Setup() { _Table = new SimpleFrame(Guid.NewGuid()); }
public void AddInitialColumnOfStrings(int rowCount) { SimpleFrame frame0 = new SimpleFrame(); SimpleFrameTool tool = new SimpleFrameTool(); Random rand = new Random(); string[] data = new string[rowCount]; for (int i = 0; i < rowCount; i++) { data[i] = string.Format("val-{0}", i); } int index = tool.AddInitialColumn<string>(frame0, "col X", data); Assert.AreEqual(0, index, "index should match expected"); Assert.AreEqual(1, frame0.ColumnCount, "ColumnCount should match expected."); for (int i = 0; i < frame0.Rows.Count; i++) { Assert.AreEqual<string>(data[i], (string)frame0.Rows[i][index], "Item should match expected"); } tool.Dispose(); }
public void AddInitialColumnOfInts(int rowCount) { SimpleFrame frame0 = new SimpleFrame(); SimpleFrameTool tool = new SimpleFrameTool(); Random rand = new Random(); int[] data = new int[rowCount]; for (int i = 0; i < rowCount; i++) { data[i] = rand.Next(); } int index = tool.AddInitialColumn<int>(frame0, "col X", data); Assert.AreEqual(0, index, "index should match expected"); Assert.AreEqual(1, frame0.ColumnCount, "ColumnCount should match expected."); for (int i = 0; i < frame0.Rows.Count; i++) { Assert.AreEqual<int>(data[i], (int)frame0.Rows[i][index], "Item should match expected"); } tool.Dispose(); }