public void Foreign() { DmRelation Relation = new DmRelation("FK_ClientType", clientTypeTable.Columns["TypeId"], clientTable.Columns["ClientType"]); _set.Relations.Add(Relation); DmRow Row = clientTable.NewRow(); Row[0] = 1; Row[1] = 1; Row[2] = "Sébastien"; clientTable.Rows.Add(Row); Row = clientTable.NewRow(); Row[0] = 2; Row[1] = 1; Row[2] = "Pierre"; clientTable.Rows.Add(Row); Row = clientTable.NewRow(); Row[0] = 3; Row[1] = 2; Row[2] = "Paul"; Row = clientTypeTable.NewRow(); Row[0] = 1; Row[1] = "Grand Compte"; clientTypeTable.Rows.Add(Row); Row = clientTypeTable.NewRow(); Row[0] = 2; Row[1] = "PME"; clientTypeTable.Rows.Add(Row); // Get all rows wher ClientType = "Grand Compte" var rowTypeGrandCompte = clientTypeTable.FindByKey(1); // Get all childs var rowsClients = rowTypeGrandCompte.GetChildRows("FK_ClientType"); Assert.Equal(2, rowsClients.Length); // Get all parents var rowClient = clientTable.Rows[0]; var rowClientType = rowClient.GetParentRow("FK_ClientType"); Assert.Equal("Grand Compte", rowClientType[1]); }
public void DmTable_RejectChanges() { tbl.AcceptChanges(); var dmRow = tbl.Rows[0]; dmRow["CustomerID"] = 2; tbl.RejectChanges(); Assert.Equal(1, dmRow["CustomerID"]); Assert.Equal(DmRowState.Unchanged, dmRow.RowState); // Try to reject changes after creating a table, with no acceptchanges var tbl3 = new DmTable(); var id3 = new DmColumn <Int32>("ServiceTicketID"); id3.IsAutoIncrement = true; tbl3.Columns.Add(id3); var key3 = new DmKey(new DmColumn[] { id3 }); tbl3.PrimaryKey = key3; tbl3.Columns.Add(new DmColumn <string>("Title")); var st3 = tbl3.NewRow(); st3["Title"] = "Titre AER"; tbl3.Rows.Add(st3); // SInce we didn't AcceptChanges, raise an error Assert.Throws <Exception>(() => tbl3.RejectChanges()); }
public void DmTable_Clone_Copy() { var tbl = new DmTable("ServiceTickets"); var id = new DmColumn <Guid>("ServiceTicketID"); tbl.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl.PrimaryKey = key; tbl.Columns.Add(new DmColumn <string>("Title")); tbl.Columns.Add(new DmColumn <string>("Description")); tbl.Columns.Add(new DmColumn <int>("StatusValue")); tbl.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl.Columns.Add(new DmColumn <DateTime>("Opened")); tbl.Columns.Add(new DmColumn <DateTime>("Closed")); tbl.Columns.Add(new DmColumn <int>("CustomerID")); var st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); var tbl2 = tbl.Clone(); Assert.NotSame(tbl2, tbl); Assert.Empty(tbl2.Rows); Assert.Equal(8, tbl2.Columns.Count); Assert.NotNull(tbl2.PrimaryKey); var tbl3 = tbl.Copy(); Assert.NotSame(tbl3, tbl2); Assert.NotSame(tbl3, tbl); Assert.NotNull(tbl3.PrimaryKey); Assert.Equal(8, tbl3.Columns.Count); Assert.NotEmpty(tbl3.Rows); }
public void DmTable_ImportRow() { var tbl2 = new DmTable(); var id = new DmColumn <Guid>("ServiceTicketID"); tbl2.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl2.PrimaryKey = key; tbl2.Columns.Add(new DmColumn <string>("Title")); tbl2.Columns.Add(new DmColumn <string>("Description")); tbl2.Columns.Add(new DmColumn <int>("StatusValue")); tbl2.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl2.Columns.Add(new DmColumn <DateTime>("Opened")); tbl2.Columns.Add(new DmColumn <DateTime>("Closed")); tbl2.Columns.Add(new DmColumn <int>("CustomerID")); var st = tbl2.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl2.Rows.Add(st); // Importing into tbl var st2 = this.tbl.ImportRow(st); // acceptchanges to change the row state this.tbl.AcceptChanges(); Assert.NotEqual(st.RowState, st2.RowState); // making change to be sure st2["CustomerID"] = 2; Assert.Equal(2, st2["CustomerID"]); Assert.Equal(1, st["CustomerID"]); }
public void DmRow_Add_Rows() { var tbl = new DmTable("ServiceTickets"); var idColumn = new DmColumn <Guid>("ServiceTicketID"); tbl.Columns.Add(idColumn); var key = new DmKey(new DmColumn[] { idColumn }); tbl.PrimaryKey = key; var titleColumn = new DmColumn <string>("Title"); tbl.Columns.Add(titleColumn); var statusValueColumn = new DmColumn <int>("StatusValue"); tbl.Columns.Add(statusValueColumn); var openedColumn = new DmColumn <DateTime>("Opened"); tbl.Columns.Add(openedColumn); var st = tbl.NewRow(); Assert.Null(st[0]); Assert.Null(st[1]); var id = Guid.NewGuid(); var dateNow = DateTime.Now; st["ServiceTicketID"] = id; st["Title"] = "Titre AER"; st["StatusValue"] = 2; st["Opened"] = dateNow; tbl.Rows.Add(st); Assert.Equal(id, st["ServiceTicketID"]); Assert.Equal("Titre AER", st["Title"]); Assert.Equal(2, st["StatusValue"]); Assert.Equal(dateNow, st["Opened"]); }
/// <summary> /// Construct a row from a dmTable, a rowState and the bitIndex /// </summary> private DmRow ConstructRow(DmTable dt, DmRowState rowState, int bitIndex) { DmRow dmRow = dt.NewRow(); int count = dt.Columns.Count; dmRow.BeginEdit(); for (int i = 0; i < count; i++) { object dmRowObject = this.Records[i][bitIndex]; // Sometimes, a serializer could potentially serialize type into string // For example JSON.Net will serialize GUID into STRING // So we try to deserialize in correct type if (dmRowObject != null) { var columnType = dt.Columns[i].DataType; var dmRowObjectType = dmRowObject.GetType(); if (dmRowObjectType != columnType && columnType != typeof(object)) { if (columnType == typeof(Guid) && (dmRowObject as string) != null) { dmRowObject = new Guid(dmRowObject.ToString()); } if (columnType == typeof(Guid) && (dmRowObject.GetType() == typeof(byte[]))) { dmRowObject = new Guid((byte[])dmRowObject); } else if (columnType == typeof(Int32) && dmRowObjectType != typeof(Int32)) { dmRowObject = Convert.ToInt32(dmRowObject); } else if (columnType == typeof(UInt32) && dmRowObjectType != typeof(UInt32)) { dmRowObject = Convert.ToUInt32(dmRowObject); } else if (columnType == typeof(Int16) && dmRowObjectType != typeof(Int16)) { dmRowObject = Convert.ToInt16(dmRowObject); } else if (columnType == typeof(UInt16) && dmRowObjectType != typeof(UInt16)) { dmRowObject = Convert.ToUInt16(dmRowObject); } else if (columnType == typeof(Int64) && dmRowObjectType != typeof(Int64)) { dmRowObject = Convert.ToInt64(dmRowObject); } else if (columnType == typeof(UInt64) && dmRowObjectType != typeof(UInt64)) { dmRowObject = Convert.ToUInt64(dmRowObject); } else if (columnType == typeof(Byte) && dmRowObjectType != typeof(Byte)) { dmRowObject = Convert.ToByte(dmRowObject); } else if (columnType == typeof(Char) && dmRowObjectType != typeof(Char)) { dmRowObject = Convert.ToChar(dmRowObject); } else if (columnType == typeof(DateTime) && dmRowObjectType != typeof(DateTime)) { dmRowObject = Convert.ToDateTime(dmRowObject); } else if (columnType == typeof(Decimal) && dmRowObjectType != typeof(Decimal)) { dmRowObject = Convert.ToDecimal(dmRowObject); } else if (columnType == typeof(Double) && dmRowObjectType != typeof(Double)) { dmRowObject = Convert.ToDouble(dmRowObject); } else if (columnType == typeof(SByte) && dmRowObjectType != typeof(SByte)) { dmRowObject = Convert.ToSByte(dmRowObject); } else if (columnType == typeof(Single) && dmRowObjectType != typeof(Single)) { dmRowObject = Convert.ToSingle(dmRowObject); } else if (columnType == typeof(String) && dmRowObjectType != typeof(String)) { dmRowObject = Convert.ToString(dmRowObject); } else if (columnType == typeof(Boolean) && dmRowObjectType != typeof(Boolean)) { dmRowObject = Convert.ToBoolean(dmRowObject); } else if (columnType == typeof(Byte[]) && dmRowObjectType != typeof(Byte[]) && dmRowObjectType == typeof(String)) { dmRowObject = Convert.FromBase64String(dmRowObject.ToString()); } else if (dmRowObjectType != columnType) { var t = dmRowObject.GetType(); var converter = columnType.GetConverter(); if (converter != null && converter.CanConvertFrom(t)) { dmRowObject = converter.ConvertFrom(dmRowObject); } } } } if (rowState == DmRowState.Deleted) { // Since some columns might be not null (and we have null because the row is deleted) if (this.Records[i][bitIndex] != null) { dmRow[i] = dmRowObject; } } else { dmRow[i] = dmRowObject; } } dt.Rows.Add(dmRow); switch (rowState) { case DmRowState.Unchanged: { dmRow.AcceptChanges(); dmRow.EndEdit(); return(dmRow); } case DmRowState.Added: { dmRow.EndEdit(); return(dmRow); } case DmRowState.Deleted: { dmRow.AcceptChanges(); dmRow.Delete(); dmRow.EndEdit(); return(dmRow); } case DmRowState.Modified: { dmRow.AcceptChanges(); dmRow.SetModified(); dmRow.EndEdit(); return(dmRow); } default: throw new ArgumentException("InvalidRowState"); } }
public void Properties() { DmSet set = new DmSet("DMSET"); DmTable clientsTable = new DmTable("Clients"); DmTable productsTable = new DmTable("Products"); set.Tables.Add(clientsTable); set.Tables.Add(productsTable); DmColumn productId = new DmColumn <Int32>("Id"); productId.AllowDBNull = false; productId.IsAutoIncrement = true; productId.IsCompute = false; productId.IsUnicode = false; productId.IsUnsigned = false; productsTable.Columns.Add(productId); DmColumn fkClientId = new DmColumn <Guid>("clientId"); fkClientId.AllowDBNull = true; productsTable.Columns.Add(fkClientId); DmColumn productName = new DmColumn <string>("name"); productName.AllowDBNull = true; productName.DbType = System.Data.DbType.StringFixedLength; productName.MaxLength = 150; productId.IsCompute = false; productId.IsUnicode = true; productId.IsUnsigned = true; productsTable.Columns.Add(productName); DmColumn productPrice = new DmColumn <Decimal>("price"); productPrice.AllowDBNull = false; productPrice.DbType = System.Data.DbType.VarNumeric; productPrice.Precision = 6; productPrice.Scale = 2; // for test purpose productId.IsCompute = true; productsTable.Columns.Add(productPrice); productsTable.PrimaryKey = new DmKey(new DmColumn[] { productId, productName, productPrice }); DmColumn clientId = new DmColumn <Guid>("Id"); clientId.AllowDBNull = false; clientsTable.Columns.Add(clientId); DmColumn clientName = new DmColumn <string>("Name"); clientsTable.Columns.Add(clientName); clientsTable.PrimaryKey = new DmKey(clientId); // ForeignKey DmRelation fkClientRelation = new DmRelation("FK_Products_Clients", clientId, fkClientId); productsTable.AddForeignKey(fkClientRelation); var clientGuid = Guid.NewGuid(); var drClient = clientsTable.NewRow(); drClient["Name"] = "Pertus"; drClient["Id"] = clientGuid; clientsTable.Rows.Add(drClient); var drProduct = productsTable.NewRow(); drProduct["clientId"] = clientGuid; drProduct["name"] = "Ensemble bleu blanc rouge"; drProduct["price"] = 12.23d; productsTable.Rows.Add(drProduct); // Convert to DmSetSurrogate var surrogateDs = new DmSetSurrogate(set); // serialize as json string var stringSurrogate = JsonConvert.SerializeObject(surrogateDs); // deserialize as surrogate var surrogateDsFromJson = JsonConvert.DeserializeObject <DmSetSurrogate>(stringSurrogate); // Convert to DmSet var set2 = surrogateDs.ConvertToDmSet(set); // Assertions on DmSet properties Assert.Equal(set.DmSetName, set2.DmSetName); Assert.Equal(set.Culture, set2.Culture); Assert.Equal(set.CaseSensitive, set2.CaseSensitive); Assert.Equal(set.Relations.Count, set2.Relations.Count); Assert.Equal(set.Tables.Count, set2.Tables.Count); //Assertions on Table properties var productsTable2 = set2.Tables["Products"]; var clientsTable2 = set2.Tables["Clients"]; AssertIsEqual(productsTable, productsTable2); AssertIsEqual(clientsTable, clientsTable2); // Assertions on columns var productId2 = set2.Tables["Products"].Columns["Id"]; AssertIsEqual(productId, productId2); var fkClientId2 = set2.Tables["Products"].Columns["clientId"]; AssertIsEqual(fkClientId, fkClientId2); var productName2 = set2.Tables["Products"].Columns["name"]; AssertIsEqual(productName, productName2); var productPrice2 = set2.Tables["Products"].Columns["price"]; AssertIsEqual(productPrice, productPrice2); var clientId2 = set2.Tables["Clients"].Columns["Id"]; AssertIsEqual(clientId, clientId2); var clientName2 = set2.Tables["Clients"].Columns["Name"]; AssertIsEqual(clientName, clientName2); }
public DmSurrogateTests() { set = new DmSet("ClientDmSet"); var tbl = new DmTable("ServiceTickets"); set.Tables.Add(tbl); var id = new DmColumn <Guid>("ServiceTicketID"); tbl.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl.PrimaryKey = key; tbl.Columns.Add(new DmColumn <string>("Title")); tbl.Columns.Add(new DmColumn <string>("Description")); tbl.Columns.Add(new DmColumn <int>("StatusValue")); tbl.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl.Columns.Add(new DmColumn <DateTime>("Opened")); tbl.Columns.Add(new DmColumn <DateTime>("Closed")); tbl.Columns.Add(new DmColumn <int>("CustomerID")); tbl.Columns.Add(new DmColumn <Object>("VariantObject")); #region adding rows var st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; st["VariantObject"] = DateTime.Now; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre DE"; st["Description"] = "Description 2"; st["EscalationLevel"] = 3; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; st["VariantObject"] = 12; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre FF"; st["Description"] = "Description 2"; st["EscalationLevel"] = 3; st["StatusValue"] = 4; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; st["VariantObject"] = new { Prop1 = 12, Prop2 = DateTime.Now }; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AC"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; st["VariantObject"] = null; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre ZDZDZ"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; st["VariantObject"] = "Hello"; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre VGH"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; st["VariantObject"] = DmRowState.Added; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre ETTG"; st["Description"] = "Description 2"; st["EscalationLevel"] = 2; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; st["VariantObject"] = 0; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre SADZD"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; st["VariantObject"] = new Byte[0]; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AEEE"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 0; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre CZDADA"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 0; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AFBBB"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 3; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AZDCV"; st["Description"] = "Description 2"; st["EscalationLevel"] = 2; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre UYTR"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre NHJK"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre XCVBN"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre LKNB"; st["Description"] = "Description 2"; st["EscalationLevel"] = 3; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre ADFVB"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); #endregion tbl.AcceptChanges(); }
public DmTableTests() { this.tbl = new DmTable("ServiceTickets"); var id = new DmColumn <Guid>("ServiceTicketID"); tbl.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl.PrimaryKey = key; tbl.Columns.Add(new DmColumn <string>("Title")); tbl.Columns.Add(new DmColumn <string>("Description")); tbl.Columns.Add(new DmColumn <int>("StatusValue")); tbl.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl.Columns.Add(new DmColumn <DateTime>("Opened")); tbl.Columns.Add(new DmColumn <DateTime>("Closed")); tbl.Columns.Add(new DmColumn <int>("CustomerID")); #region adding rows var st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre DE"; st["Description"] = "Description 2"; st["EscalationLevel"] = 3; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre FF"; st["Description"] = "Description 2"; st["EscalationLevel"] = 3; st["StatusValue"] = 4; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AC"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre ZDZDZ"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre VGH"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre ETTG"; st["Description"] = "Description 2"; st["EscalationLevel"] = 2; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre SADZD"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AEEE"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 0; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre CZDADA"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 0; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AFBBB"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 3; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AZDCV"; st["Description"] = "Description 2"; st["EscalationLevel"] = 2; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre UYTR"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre NHJK"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre XCVBN"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 1; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 2; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre LKNB"; st["Description"] = "Description 2"; st["EscalationLevel"] = 3; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 3; tbl.Rows.Add(st); st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre ADFVB"; st["Description"] = "Description 2"; st["EscalationLevel"] = 0; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); #endregion }
public void DmTable_Merge() { var tbl2 = new DmTable(); var id = new DmColumn <Guid>("ServiceTicketID"); tbl2.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl2.PrimaryKey = key; tbl2.Columns.Add(new DmColumn <string>("Title")); tbl2.Columns.Add(new DmColumn <string>("Description")); tbl2.Columns.Add(new DmColumn <int>("StatusValue")); tbl2.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl2.Columns.Add(new DmColumn <DateTime>("Opened")); tbl2.Columns.Add(new DmColumn <DateTime>("Closed")); tbl2.Columns.Add(new DmColumn <int>("CustomerID")); var st = tbl2.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl2.Rows.Add(st); // Importing into tbl var actualRowsCount = this.tbl.Rows.Count; this.tbl.Merge(tbl2); Assert.Equal(actualRowsCount + 1, this.tbl.Rows.Count); var tbl3 = new DmTable(); var id3 = new DmColumn <Guid>("ServiceTicketID"); tbl3.Columns.Add(id3); var key3 = new DmKey(new DmColumn[] { id3 }); tbl3.PrimaryKey = key3; tbl3.Columns.Add(new DmColumn <string>("Title")); tbl3.Columns.Add(new DmColumn <string>("Description")); tbl3.Columns.Add(new DmColumn <int>("StatusValue")); tbl3.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl3.Columns.Add(new DmColumn <DateTime>("Opened")); tbl3.Columns.Add(new DmColumn <DateTime>("Closed")); tbl3.Columns.Add(new DmColumn <int>("CustomerID")); tbl3.Columns.Add(new DmColumn <int>("AAAAAAAAAAAAAA")); tbl3.Columns.Add(new DmColumn <string>("VVVVVVVVVVVVVVVVVVVV")); var st3 = tbl3.NewRow(); st3["ServiceTicketID"] = Guid.NewGuid(); st3["Title"] = "Titre AER"; st3["Description"] = "Description 2"; st3["EscalationLevel"] = 1; st3["StatusValue"] = 2; st3["Opened"] = DateTime.Now; st3["Closed"] = null; st3["CustomerID"] = 1; st3["AAAAAAAAAAAAAA"] = "A"; st3["VVVVVVVVVVVVVVVVVVVV"] = "V"; tbl3.Rows.Add(st3); // Importing into tbl actualRowsCount = this.tbl.Rows.Count; this.tbl.Merge(tbl3); Assert.Equal(actualRowsCount + 1, this.tbl.Rows.Count); Assert.Equal(10, this.tbl.Columns.Count); }
public static Task DmTableSurrogatetest() { ServiceConfiguration serviceConfiguration = new ServiceConfiguration(); serviceConfiguration.BatchDirectory = Path.Combine(Path.GetTempPath() + "tmp"); serviceConfiguration.ConflictResolutionPolicy = ConflictResolutionPolicy.ClientWins; serviceConfiguration.DownloadBatchSizeInKB = 10000; serviceConfiguration.EnableDiagnosticPage = true; serviceConfiguration.FilterParameters = new List <SyncParameter>(); serviceConfiguration.FilterParameters.Add(new SyncParameter { Name = "ClientId", Value = 12 }); serviceConfiguration.OverwriteConfiguration = false; serviceConfiguration.SerializationConverter = SerializationFormat.Json; serviceConfiguration.UseBulkOperations = true; serviceConfiguration.UseVerboseErrors = true; var dmSet = new DmSet(); DmTable dtClient = new DmTable("Client"); DmColumn dcId = new DmColumn <int>("Id"); DmColumn dcName = new DmColumn <string>("Name"); DmColumn dcBirthdate = new DmColumn <DateTime>("Date"); DmColumn dcMoney = new DmColumn <Double>("Money"); DmColumn dcInt = new DmColumn <Int64>("i64"); DmColumn dcJob = new DmColumn <String>("Job"); dtClient.Columns.AddRange(new[] { dcId, dcName, dcBirthdate, dcMoney, dcInt, dcJob }); dmSet.Tables.Add(dtClient); serviceConfiguration.ScopeSet = dmSet; for (int i = 0; i < 5; i++) { var newRow = dtClient.NewRow(); Random r = new Random(DateTime.Now.Second); var l = r.NextDouble() * 100; string name = ""; for (int j = 0; j < l; j++) { name += "a"; } newRow["Id"] = 12; newRow["Name"] = name; newRow["Date"] = DateTime.Now; newRow["Money"] = l; var l2 = r.NextDouble() * 10; string job = ""; for (int j = 0; j < l2; j++) { job += "b"; } newRow["Job"] = job; newRow["i64"] = l2; dtClient.Rows.Add(newRow); } var dmTableS = new DmTableSurrogate(dtClient); var str = JsonConvert.SerializeObject(dmTableS); Console.WriteLine(str); return(Task.CompletedTask); }
public void DmTable_FindByKey() { var key = Guid.NewGuid(); var st = tbl.NewRow(); st["ServiceTicketID"] = key; st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); var dmRow = tbl.FindByKey(key); Assert.NotNull(dmRow); Assert.Equal(key, dmRow["ServiceTicketID"]); // Multiple Key // Check if the culture / case sensitive works as well with // string in the pkey var tbl2 = new DmTable("ServiceTickets"); tbl2.CaseSensitive = true; var id1 = new DmColumn <Guid>("ServiceTicketID"); var id2 = new DmColumn <int>("CustomerID"); var id3 = new DmColumn <string>("Title"); tbl2.Columns.Add(id1); tbl2.Columns.Add(id2); tbl2.Columns.Add(id3); var pkey = new DmKey(new DmColumn[] { id1, id2, id3 }); tbl2.PrimaryKey = pkey; tbl2.Columns.Add(new DmColumn <string>("Description")); tbl2.Columns.Add(new DmColumn <int>("StatusValue")); tbl2.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl2.Columns.Add(new DmColumn <DateTime>("Opened")); tbl2.Columns.Add(new DmColumn <DateTime>("Closed")); var rowPkeyGuid = Guid.NewGuid(); var row = tbl2.NewRow(); row["ServiceTicketID"] = rowPkeyGuid; row["CustomerID"] = 1; row["Title"] = "Titre AER"; row["Description"] = "Description 2"; row["EscalationLevel"] = 1; row["StatusValue"] = 2; row["Opened"] = DateTime.Now; row["Closed"] = null; tbl2.Rows.Add(row); row = tbl2.NewRow(); row["ServiceTicketID"] = rowPkeyGuid; row["CustomerID"] = 1; row["Title"] = "Titre DE"; row["Description"] = "Description 2"; row["EscalationLevel"] = 3; row["StatusValue"] = 2; row["Opened"] = DateTime.Now; row["Closed"] = null; tbl2.Rows.Add(row); var dmRow2 = tbl2.FindByKey(new object[] { rowPkeyGuid, 1, "Titre aer" }); Assert.Null(dmRow2); tbl2.CaseSensitive = false; var dmRow3 = tbl2.FindByKey(new object[] { rowPkeyGuid, 1, "Titre aer" }); Assert.NotNull(dmRow3); }
/// <summary> /// Construct a row from a dmTable, a rowState and the bitIndex /// </summary> private DmRow ConstructRow(DmTable dt, DmRowState rowState, int bitIndex) { DmRow dmRow = dt.NewRow(); int count = dt.Columns.Count; dmRow.BeginEdit(); for (int i = 0; i < count; i++) { object dmRowObject = this.Records[i][bitIndex]; // Sometimes, a serializer could potentially serialize type into string // For example JSON.Net will serialize GUID into STRING // So we try to deserialize in correct type if (dmRowObject != null) { var columnType = dt.Columns[i].DataType; if (columnType == typeof(Guid) && (dmRowObject as string) != null) { dmRowObject = new Guid(dmRowObject.ToString()); } else if (columnType == typeof(Int32) && dmRowObject.GetType() != typeof(Int32)) { dmRowObject = Convert.ToInt32(dmRowObject); } else if (columnType == typeof(Int16) && dmRowObject.GetType() != typeof(Int16)) { dmRowObject = Convert.ToInt16(dmRowObject); } else if (dmRowObject.GetType() != columnType) { Debug.WriteLine($"Can't convert serialized value {dmRowObject.ToString()} to {columnType}"); var t = dmRowObject.GetType(); var converter = columnType.GetConverter(); if (converter.CanConvertFrom(t)) { dmRowObject = converter.ConvertFrom(dmRowObject); } else { dmRowObject = Convert.ChangeType(dmRowObject, columnType, CultureInfo.InvariantCulture); } } } if (rowState == DmRowState.Deleted) { // Since some columns might be not null (and we have null because the row is deleted) if (this.Records[i][bitIndex] != null) { dmRow[i] = dmRowObject; } } else { dmRow[i] = dmRowObject; } } //if (rowState == DmRowState.Deleted) //{ // // we are in a deleted state, so we have only primary keys available // for (int i = 0; i < count; i++) // { // // since some columns might be not null (and we have null because the row is deleted) // if (this.Records[i][bitIndex] != null) // dmRow[i] = this.Records[i][bitIndex]; // } //} //else //{ // for (int i = 0; i < count; i++) // dmRow[i] = this.Records[i][bitIndex]; //} dt.Rows.Add(dmRow); switch (rowState) { case DmRowState.Unchanged: { dmRow.AcceptChanges(); dmRow.EndEdit(); return(dmRow); } case DmRowState.Added: { dmRow.EndEdit(); return(dmRow); } case DmRowState.Deleted: { dmRow.AcceptChanges(); dmRow.Delete(); dmRow.EndEdit(); return(dmRow); } case DmRowState.Modified: { dmRow.AcceptChanges(); dmRow.SetModified(); dmRow.EndEdit(); return(dmRow); } default: throw new ArgumentException("InvalidRowState"); } }
public void Serialize_Object() { BaseConverter <Client> serializer = new DmBinaryConverter <Client>(); Guid guid = Guid.NewGuid(); var client = new Client { Id = 1, ClientId = guid, Birthday = new DateTime(1976, 10, 23), FirstName = "sébastien", LastName = "Pertus" }; using (var ms = new MemoryStream()) { serializer.Serialize(client, ms); ms.Position = 0; var client2 = serializer.Deserialize(ms); Assert.NotSame(client, client2); Assert.Equal(1, client2.Id); Assert.Equal(guid, client2.ClientId); Assert.Equal("sébastien", client2.FirstName); } var serializer2 = new DmBinaryConverter <List <Client> >(); // Test List<T> var lst = new List <Client>(); lst.Add(client); lst.Add(client); lst.Add(client); using (var ms = new MemoryStream()) { serializer2.Serialize(lst, ms); ms.Position = 0; var lst2 = serializer2.Deserialize(ms); Assert.NotSame(lst, lst2); Assert.Equal(3, lst2.Count); } var serializer3 = new DmBinaryConverter <NullableClient>(); // test nullable var client3 = new NullableClient { Id = null, ClientId = null, Birthday = null, FirstName = "~#'\"é{[", LastName = null, Money = null }; using (var ms = new MemoryStream()) { serializer3.Serialize(client3, ms); ms.Position = 0; var client4 = serializer3.Deserialize(ms); Assert.NotSame(client3, client4); Assert.Null(client4.Id); Assert.Null(client4.ClientId); Assert.Null(client4.Birthday); Assert.Null(client4.LastName); Assert.Null(client4.Money); Assert.Equal("~#'\"é{[", client4.FirstName); } var serializer4 = new DmBinaryConverter <DmSetSurrogate>(); // Test on datatable var ds = new DmSet("Fabrikam"); var tbl = new DmTable("ServiceTickets"); var id = new DmColumn <Guid>("ServiceTicketID"); tbl.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl.PrimaryKey = key; tbl.Columns.Add(new DmColumn <string>("Title")); tbl.Columns.Add(new DmColumn <string>("Description")); tbl.Columns.Add(new DmColumn <int>("StatusValue")); tbl.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl.Columns.Add(new DmColumn <DateTime>("Opened")); tbl.Columns.Add(new DmColumn <DateTime>("Closed")); tbl.Columns.Add(new DmColumn <int>("CustomerID")); var st = tbl.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl.Rows.Add(st); ds.Tables.Add(tbl); var dsSurrogate = new DmSetSurrogate(ds); using (var ms = new MemoryStream()) { serializer4.Serialize(dsSurrogate, ms); ms.Position = 0; var dsSurrogate2 = serializer4.Deserialize(ms); var ds2 = dsSurrogate2.ConvertToDmSet(ds); Assert.NotSame(ds, ds2); Assert.Equal(ds.CaseSensitive, ds2.CaseSensitive); Assert.Equal(ds.Culture, ds2.Culture); Assert.Equal(ds.DmSetName, ds2.DmSetName); Assert.Equal(ds.Tables.Count, ds2.Tables.Count); Assert.Equal(ds.Tables[0].Columns.Count, ds2.Tables[0].Columns.Count); Assert.Equal(ds.Tables[0].Rows.Count, ds2.Tables[0].Rows.Count); Assert.Equal(ds.Tables[0].PrimaryKey.Columns.Length, ds2.Tables[0].PrimaryKey.Columns.Length); } }
/// <summary> /// Create a DmRow from a IDataReader /// </summary> private DmRow CreateRowFromReader(IDataReader dataReader, DmTable dmTable) { // we have an insert / update or delete DmRow dataRow = dmTable.NewRow(); for (int i = 0; i < dataReader.FieldCount; i++) { var columnName = dataReader.GetName(i); var dmRowObject = dataReader.GetValue(i); if (dmRowObject != DBNull.Value) { if (dmRowObject != null) { var columnType = dmTable.Columns[columnName].DataType; var dmRowObjectType = dmRowObject.GetType(); if (dmRowObjectType != columnType && columnType != typeof(object)) { if (columnType == typeof(Guid) && (dmRowObject as string) != null) { dmRowObject = new Guid(dmRowObject.ToString()); } else if (columnType == typeof(Guid) && dmRowObject.GetType() == typeof(byte[])) { dmRowObject = dataReader.GetGuid(i); } else if (columnType == typeof(Int32) && dmRowObjectType != typeof(Int32)) { dmRowObject = Convert.ToInt32(dmRowObject); } else if (columnType == typeof(UInt32) && dmRowObjectType != typeof(UInt32)) { dmRowObject = Convert.ToUInt32(dmRowObject); } else if (columnType == typeof(Int16) && dmRowObjectType != typeof(Int16)) { dmRowObject = Convert.ToInt16(dmRowObject); } else if (columnType == typeof(UInt16) && dmRowObjectType != typeof(UInt16)) { dmRowObject = Convert.ToUInt16(dmRowObject); } else if (columnType == typeof(Int64) && dmRowObjectType != typeof(Int64)) { dmRowObject = Convert.ToInt64(dmRowObject); } else if (columnType == typeof(UInt64) && dmRowObjectType != typeof(UInt64)) { dmRowObject = Convert.ToUInt64(dmRowObject); } else if (columnType == typeof(Byte) && dmRowObjectType != typeof(Byte)) { dmRowObject = Convert.ToByte(dmRowObject); } else if (columnType == typeof(Char) && dmRowObjectType != typeof(Char)) { dmRowObject = Convert.ToChar(dmRowObject); } else if (columnType == typeof(DateTime) && dmRowObjectType != typeof(DateTime)) { dmRowObject = Convert.ToDateTime(dmRowObject); } else if (columnType == typeof(Decimal) && dmRowObjectType != typeof(Decimal)) { dmRowObject = Convert.ToDecimal(dmRowObject); } else if (columnType == typeof(Double) && dmRowObjectType != typeof(Double)) { dmRowObject = Convert.ToDouble(dmRowObject); } else if (columnType == typeof(SByte) && dmRowObjectType != typeof(SByte)) { dmRowObject = Convert.ToSByte(dmRowObject); } else if (columnType == typeof(Single) && dmRowObjectType != typeof(Single)) { dmRowObject = Convert.ToSingle(dmRowObject); } else if (columnType == typeof(String) && dmRowObjectType != typeof(String)) { dmRowObject = Convert.ToString(dmRowObject); } else if (columnType == typeof(Boolean) && dmRowObjectType != typeof(Boolean)) { dmRowObject = Convert.ToBoolean(dmRowObject); } else if (dmRowObjectType != columnType) { var t = dmRowObject.GetType(); var converter = columnType.GetConverter(); if (converter != null && converter.CanConvertFrom(t)) { dmRowObject = converter.ConvertFrom(dmRowObject); } } } } dataRow[columnName] = dmRowObject; } } return(dataRow); }
public void DmTable_LoadDataRow() { // Trying with a key GUID (not auto incremented) var tbl2 = new DmTable(); var id = new DmColumn <Guid>("ServiceTicketID"); tbl2.Columns.Add(id); var key = new DmKey(new DmColumn[] { id }); tbl2.PrimaryKey = key; tbl2.Columns.Add(new DmColumn <string>("Title")); tbl2.Columns.Add(new DmColumn <string>("Description")); tbl2.Columns.Add(new DmColumn <int>("StatusValue")); tbl2.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl2.Columns.Add(new DmColumn <DateTime>("Opened")); tbl2.Columns.Add(new DmColumn <DateTime>("Closed")); tbl2.Columns.Add(new DmColumn <int>("CustomerID")); var st = tbl2.NewRow(); st["ServiceTicketID"] = Guid.NewGuid(); st["Title"] = "Titre AER"; st["Description"] = "Description 2"; st["EscalationLevel"] = 1; st["StatusValue"] = 2; st["Opened"] = DateTime.Now; st["Closed"] = null; st["CustomerID"] = 1; tbl2.Rows.Add(st); var array = new object[] { Guid.NewGuid(), "Titre 2", "Desc", 1, 2, DateTime.Now, null, 3 }; tbl2.LoadDataRow(array, true); Assert.Equal(2, tbl2.Rows.Count); // Trying with a key Int auto incremented var tbl3 = new DmTable(); var id3 = new DmColumn <Int32>("ServiceTicketID"); id3.IsAutoIncrement = true; tbl3.Columns.Add(id3); var key3 = new DmKey(new DmColumn[] { id3 }); tbl3.PrimaryKey = key3; tbl3.Columns.Add(new DmColumn <string>("Title")); tbl3.Columns.Add(new DmColumn <string>("Description")); tbl3.Columns.Add(new DmColumn <int>("StatusValue")); tbl3.Columns.Add(new DmColumn <int>("EscalationLevel")); tbl3.Columns.Add(new DmColumn <DateTime>("Opened")); tbl3.Columns.Add(new DmColumn <DateTime>("Closed")); tbl3.Columns.Add(new DmColumn <int>("CustomerID")); var st3 = tbl3.NewRow(); st3["Title"] = "Titre AER"; st3["Description"] = "Description 2"; st3["EscalationLevel"] = 1; st3["StatusValue"] = 2; st3["Opened"] = DateTime.Now; st3["Closed"] = null; st3["CustomerID"] = 1; tbl3.Rows.Add(st3); var array3 = new object[] { "Titre 2", "Desc", 1, 2, DateTime.Now, null, 3 }; tbl3.LoadDataRow(array3, true); Assert.Equal(1, tbl3.Rows[0][0]); Assert.Equal(2, tbl3.Rows[1][0]); }
private static void ParseProcedureBody(DmTable parametersTable, string body, string sqlMode, string schema, string procName) { List <string> modes = new List <string>(new string[3] { "IN", "OUT", "INOUT" }); int pos = 1; MySqlTokenizer tokenizer = new MySqlTokenizer(body) { AnsiQuotes = sqlMode.IndexOf("ANSI_QUOTES") != -1, BackslashEscapes = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") == -1, ReturnComments = false }; string token = tokenizer.NextToken(); // this block will scan for the opening paren while also determining // if this routine is a function. If so, then we need to add a // parameter row for the return parameter since it is ordinal position // 0 and should appear first. while (token != "(") { if (String.Compare(token, "FUNCTION", StringComparison.OrdinalIgnoreCase) == 0) { var newRow = parametersTable.NewRow(); InitParameterRow(newRow, schema, procName); parametersTable.Rows.Add(newRow); } token = tokenizer.NextToken(); } token = tokenizer.NextToken(); // now move to the next token past the ( while (token != ")") { DmRow parmRow = parametersTable.NewRow(); InitParameterRow(parmRow, schema, procName); parmRow["ORDINAL_POSITION"] = pos++; // handle mode and name for the parameter string mode = token.ToUpperInvariant(); if (!tokenizer.Quoted && modes.Contains(mode)) { parmRow["PARAMETER_MODE"] = mode; token = tokenizer.NextToken(); } if (tokenizer.Quoted) { token = token.Substring(1, token.Length - 2); } parmRow["PARAMETER_NAME"] = token; // now parse data type token = ParseDataType(parmRow, tokenizer); if (token == ",") { token = tokenizer.NextToken(); } parametersTable.Rows.Add(parmRow); } // now parse out the return parameter if there is one. token = tokenizer.NextToken().ToUpperInvariant(); if (String.Compare(token, "RETURNS", StringComparison.OrdinalIgnoreCase) == 0) { DmRow parameterRow = parametersTable.Rows[0]; parameterRow["PARAMETER_NAME"] = "RETURN_VALUE"; ParseDataType(parameterRow, tokenizer); } }
private static void TestSerializerSize() { DmTable dtClient = new DmTable("Client"); DmColumn dcId = new DmColumn <int>("Id"); DmColumn dcName = new DmColumn <string>("Name"); DmColumn dcBirthdate = new DmColumn <DateTime>("Date"); DmColumn dcMoney = new DmColumn <Double>("Money"); DmColumn dcInt = new DmColumn <Int64>("i64"); DmColumn dcJob = new DmColumn <String>("Job"); dtClient.Columns.AddRange(new[] { dcId, dcName, dcBirthdate, dcMoney, dcInt, dcJob }); long rowsSize = 0; foreach (var c in dtClient.Columns) { DmColumnSurrogate dcs = new DmColumnSurrogate(c); Console.WriteLine($"Column {dcs.ColumnName} Surrogate length : " + dcs.GetBytesLength()); rowsSize += dcs.GetBytesLength(); } var dmTableS = new DmTableSurrogate(dtClient); var dmTableSLength = dmTableS.GetEmptyBytesLength(); Console.WriteLine("DmTableSurrogate length = " + dmTableSLength); rowsSize += dmTableSLength; for (int i = 0; i < 50000; i++) { var newRow = dtClient.NewRow(); Random r = new Random(DateTime.Now.Second); var l = r.NextDouble() * 100; string name = ""; for (int j = 0; j < l; j++) { name += "a"; } newRow["Id"] = 12; newRow["Name"] = name; newRow["Date"] = DateTime.Now; newRow["Money"] = l; var l2 = r.NextDouble() * 100; string job = ""; for (int j = 0; j < l2; j++) { job += "b"; } newRow["Job"] = job; newRow["i64"] = l2; rowsSize += DmTableSurrogate.GetRowSizeFromDataRow(newRow); dtClient.Rows.Add(newRow); } var serializer = new DmSerializer(); long dtSize = 0; if (File.Exists("dt.bin")) { File.Delete("dt.bin"); } using (var fs = new FileStream("dt.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { serializer.Serialize(new DmTableSurrogate(dtClient), fs); dtSize = fs.Length; } //using (var fs = new FileStream("dt.bin", FileMode.Open, FileAccess.Read)) //{ // var ds = serializer.Deserialize<DmTableSurrogate>(fs); //} Console.WriteLine("Rows Size : " + rowsSize); Console.WriteLine("Table Size : " + dtSize); }