private void ProcessNode(Node node) { var sqlNode = new SqlNode { Id = node.Id, TimeStamp = node.TimeStamp, LocalChangeset = node.LocalChangeset, Latitude = node.Latitude, Longtitude = node.Longtitude, }; sqlNode.MakePosition(); var command = new SqlCommand("Insert into Node (Id, TimeStamp, Latitude, Longtitude, Position) values (@Id, @TimeStamp, @Latitude, @Longtitude, @Position)") { Connection = _db }; command.Parameters.Add(new SqlParameter("@Id", sqlNode.Id)); command.Parameters.Add(new SqlParameter("@TimeStamp", sqlNode.TimeStamp)); command.Parameters.Add(new SqlParameter("@LocalChangeset", sqlNode.LocalChangeset)); command.Parameters.Add(new SqlParameter("@Latitude", sqlNode.Latitude)); command.Parameters.Add(new SqlParameter("@Longtitude", sqlNode.Longtitude)); command.Parameters.Add(new SqlParameter("@Position", sqlNode.Position) { UdtTypeName = "Geography" }); command.ExecuteNonQuery(); }
public void UpdatNodesInBulk() { _db.Open(); Console.WriteLine("--------------- Updating Nodes ---------------"); var nodes = _mongoConnector.GetAllNodesFromChangeset(_localChangeset); var tempNodeList = new List <Node>(); foreach (var node in nodes) { tempNodeList.Add(node); if (tempNodeList.Count != 10000) { continue; } var nodeTable = CreateNodeTable(); var nodeTagTable = CreateTagTable(); foreach (var node1 in tempNodeList) { foreach (var tagKey in node1.Tags.Keys) { var tagRow = nodeTagTable.NewRow(); var value = node1.Tags[tagKey]; var validValue = value.Substring(0, Math.Min(200, value.Length)); tagRow.ItemArray = new object[] { node1.Id, tagKey, validValue }; nodeTagTable.Rows.Add(tagRow); } var sqlNode = new SqlNode { Id = node1.Id, TimeStamp = node1.TimeStamp, LocalChangeset = node1.LocalChangeset, Latitude = node1.Latitude, Longtitude = node1.Longtitude, }; sqlNode.MakePosition(); var nodeRow = nodeTable.NewRow(); nodeRow.ItemArray = new object[] { sqlNode.Id, sqlNode.TimeStamp, sqlNode.LocalChangeset, sqlNode.Latitude, sqlNode.Longtitude, sqlNode.Position }; nodeTable.Rows.Add(nodeRow); } using (var bulk = new SqlBulkCopy(_db)) { bulk.DestinationTableName = "Node"; bulk.WriteToServer(nodeTable); } using (var bulk = new SqlBulkCopy(_db)) { bulk.DestinationTableName = "NodeTag"; bulk.WriteToServer(nodeTagTable); } tempNodeList = new List <Node>(10000); Console.WriteLine("10000 Passed"); } //---------------------------------------------------------------------------- // Remains var nodeTable1 = CreateNodeTable(); var nodeTagTable1 = CreateTagTable(); foreach (var node1 in tempNodeList) { foreach (var tagKey in node1.Tags.Keys) { var tagRow = nodeTagTable1.NewRow(); var value = node1.Tags[tagKey]; var validValue = value.Substring(0, Math.Min(200, value.Length)); tagRow.ItemArray = new object[] { node1.Id, tagKey, validValue }; nodeTagTable1.Rows.Add(tagRow); } var sqlNode = new SqlNode { Id = node1.Id, TimeStamp = node1.TimeStamp, LocalChangeset = node1.LocalChangeset, Latitude = node1.Latitude, Longtitude = node1.Longtitude, }; sqlNode.MakePosition(); var nodeRow = nodeTable1.NewRow(); nodeRow.ItemArray = new object[] { sqlNode.Id, sqlNode.TimeStamp, sqlNode.LocalChangeset, sqlNode.Latitude, sqlNode.Longtitude, sqlNode.Position }; nodeTable1.Rows.Add(nodeRow); } using (var bulk = new SqlBulkCopy(_db)) { bulk.DestinationTableName = "Node"; bulk.WriteToServer(nodeTable1); } using (var bulk = new SqlBulkCopy(_db)) { bulk.DestinationTableName = "NodeTag"; bulk.WriteToServer(nodeTagTable1); } _db.Close(); }