nHydrate.Generator.Models.TableCollectionController.PasteTable C# (CSharp) Method

PasteTable() private method

private PasteTable ( TableCollection tableCollection, XmlNode tableNode, XmlNode columnListNode ) : void
tableCollection TableCollection
tableNode System.Xml.XmlNode
columnListNode System.Xml.XmlNode
return void
		private void PasteTable(TableCollection tableCollection, XmlNode tableNode, XmlNode columnListNode)
		{
			try
			{
				var table = tableCollection.Add();
				var id = table.Id;
				table.XmlLoad(tableNode);
				table.SetId(id);
				table.SetKey(Guid.NewGuid().ToString());
				table.Name = "[" + table.Name + "]";
				table.Columns.Clear();
				table.Relationships.Clear();
				table.CustomRetrieveRules.Clear();

				var columnMapper = new Dictionary<int, int>();
				foreach (XmlNode child in columnListNode)
				{
					var column = ((ModelRoot)this.Object.Root).Database.Columns.Add();
					id = column.Id;
					column.XmlLoad(child);
					columnMapper.Add(column.Id, id);
					column.SetId(id);
					column.SetKey(Guid.NewGuid().ToString());
					table.Columns.Add(column.CreateRef());
					column.ParentTableRef = table.CreateRef();
				}

				foreach (RowEntry r in table.StaticData)
				{
					foreach (CellEntry cell in r.CellEntries)
					{
						if (columnMapper.ContainsKey(cell.ColumnRef.Ref))
						{
							var newID = columnMapper[cell.ColumnRef.Ref];
							cell.ColumnRef.Ref = newID;
						}
					}
				}

			}
			catch (Exception ex)
			{
				throw;
			}
		}