Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions mcs/class/System.Data/System.Data/DataRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ internal void ImportRecord (int record)
CheckValue (this [col], col, false);
}

void CheckValue (object v, DataColumn col)
private void CheckValue (object v, DataColumn col)
{
CheckValue (v, col, true);
}
Expand Down Expand Up @@ -1399,6 +1399,11 @@ public void SetParentRow (DataRow parentRow, DataRelation relation)

//Copy all values of this DataRow to the row parameter.
internal void CopyValuesToRow (DataRow row)
{
CopyValuesToRow(row, true);
}

internal void CopyValuesToRow (DataRow row, bool doROCheck)
{
if (row == null)
throw new ArgumentNullException("row");
Expand Down Expand Up @@ -1454,19 +1459,19 @@ internal void CopyValuesToRow (DataRow row)
if (targetColumn != null) {
if (HasVersion (DataRowVersion.Original)) {
object val = column[Original];
row.CheckValue (val, targetColumn);
row.CheckValue (val, targetColumn, doROCheck);
targetColumn [row.Original] = val;
}

if (HasVersion (DataRowVersion.Current) && Current != Original) {
object val = column[Current];
row.CheckValue (val, targetColumn);
row.CheckValue (val, targetColumn, doROCheck);
targetColumn [row.Current] = val;
}

if (HasVersion (DataRowVersion.Proposed)) {
object val = column[row.Proposed];
row.CheckValue (val, targetColumn);
row.CheckValue (val, targetColumn, doROCheck);
targetColumn [row.Proposed] = val;
}
}
Expand Down
3 changes: 2 additions & 1 deletion mcs/class/System.Data/System.Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ private void AddChangedRow (Hashtable addedRows, DataTable copyTable, DataRow ro
// add the current row
DataRow newRow = copyTable.NewNotInitializedRow ();
copyTable.Rows.AddInternal (newRow);
row.CopyValuesToRow (newRow);
// Don't check for ReadOnly, when cloning data to new uninitialized row.
row.CopyValuesToRow (newRow, false);
newRow.XmlRowID = row.XmlRowID;
addedRows.Add (row, row);
}
Expand Down
3 changes: 2 additions & 1 deletion mcs/class/System.Data/System.Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ public DataTable GetChanges (DataRowState rowStates)
if (copyTable == null)
copyTable = Clone ();
DataRow newRow = copyTable.NewNotInitializedRow ();
row.CopyValuesToRow (newRow);
// Don't check for ReadOnly, when cloning data to new uninitialized row.
row.CopyValuesToRow (newRow, false);
#if NET_2_0
newRow.XmlRowID = row.XmlRowID;
#endif
Expand Down
3 changes: 2 additions & 1 deletion mcs/class/System.Data/System.Data/MergeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ private static void MergeRow(DataTable targetTable, DataRow row, bool preserveCh
if (targetRow == null)
{
DataRow newRow = targetTable.NewNotInitializedRow();
row.CopyValuesToRow(newRow);
// Don't check for ReadOnly, when cloning data to new uninitialized row.
row.CopyValuesToRow(newRow, false);
targetTable.Rows.AddInternal (newRow);
}
// row exists in target table, and presere changes is false -
Expand Down
32 changes: 20 additions & 12 deletions mcs/class/System.Data/Test/System.Data/DataSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,46 +1211,54 @@ public void WriteDiffReadAutoWriteSchema ()
[Test]
public void CloneCopy ()
{
DataTable table = new DataTable ("pTable"); DataTable table1 = new DataTable ("cTable"); DataSet set = new DataSet ();

DataTable table = new DataTable ("pTable");
DataTable table1 = new DataTable ("cTable");
DataSet set = new DataSet ();

set.Tables.Add (table);
set.Tables.Add (table1); DataColumn col = new DataColumn ();
set.Tables.Add (table1);

DataColumn col = new DataColumn ();
col.ColumnName = "Id";
col.DataType = Type.GetType ("System.Int32");
table.Columns.Add (col);
UniqueConstraint uc = new UniqueConstraint ("UK1", table.Columns[0] );
table.Constraints.Add (uc);

col = new DataColumn ();
col.ColumnName = "Name";
col.DataType = Type.GetType ("System.String");
table.Columns.Add (col);

col = new DataColumn ();
col.ColumnName = "Id";
col.DataType = Type.GetType ("System.Int32");
table1.Columns.Add (col);

col = new DataColumn ();
col.ColumnName = "Name";
col.DataType = Type.GetType ("System.String");
table1.Columns.Add (col);
ForeignKeyConstraint fc = new ForeignKeyConstraint ("FK1", table.Columns[0], table1.Columns[0] );
table1.Constraints.Add (fc);


DataRow row = table.NewRow ();

row ["Id"] = 147;
row ["name"] = "Row1";
row.RowError = "Error#1";
table.Rows.Add (row);


// Set column to RO as commonly used by auto-increment fields.
// ds.Copy() has to omit the RO check when cloning DataRows
table.Columns["Id"].ReadOnly = true;

row = table1.NewRow ();
row ["Id"] = 147;
row ["Name"] = "Row1";
table1.Rows.Add (row);

//Setting properties of DataSet
set.CaseSensitive = true;
set.DataSetName = "My DataSet";
Expand All @@ -1262,7 +1270,7 @@ public void CloneCopy ()
set.ExtendedProperties.Add ("TimeStamp", DateTime.Now);
CultureInfo cultureInfo = new CultureInfo( "ar-SA" );
set.Locale = cultureInfo;

//Testing Copy ()
DataSet copySet = set.Copy ();
Assert.AreEqual (set.CaseSensitive, copySet.CaseSensitive, "#A01");
Expand Down
21 changes: 17 additions & 4 deletions mcs/class/System/System.Configuration/ApplicationSettingsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,24 @@ public override SettingsPropertyCollection Properties {

try {
if (properties == null) {
LocalFileSettingsProvider local_provider = null;
SettingsProvider local_provider = null;

properties = new SettingsPropertyCollection ();

foreach (PropertyInfo prop in GetType ().GetProperties ()) { // only public properties
Type this_type = GetType();
SettingsProviderAttribute[] provider_attrs = (SettingsProviderAttribute[])this_type.GetCustomAttributes (typeof (SettingsProviderAttribute), false);;
if (provider_attrs != null && provider_attrs.Length != 0) {
Type provider_type = Type.GetType (provider_attrs[0].ProviderTypeName);
SettingsProvider provider = (SettingsProvider) Activator.CreateInstance (provider_type);
provider.Initialize (null, null);
if (provider != null && Providers [provider.Name] == null) {
Providers.Add (provider);
local_provider = provider;
}
}

PropertyInfo[] type_props = this_type.GetProperties ();
foreach (PropertyInfo prop in type_props) { // only public properties
SettingAttribute[] setting_attrs = (SettingAttribute[])prop.GetCustomAttributes (typeof (SettingAttribute), false);
if (setting_attrs == null || setting_attrs.Length == 0)
continue;
Expand All @@ -292,7 +305,7 @@ public override SettingsPropertyCollection Properties {
}
}

void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref LocalFileSettingsProvider local_provider)
void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref SettingsProvider local_provider)
{
SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
SettingsProvider provider = null;
Expand Down Expand Up @@ -346,7 +359,7 @@ void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection prope

if (provider == null) {
if (local_provider == null) {
local_provider = new LocalFileSettingsProvider ();
local_provider = new LocalFileSettingsProvider () as SettingsProvider;
local_provider.Initialize (null, null);
}
setting.Provider = local_provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,11 @@ private static string GetProductName ()
assembly = Assembly.GetCallingAssembly ();

#if !TARGET_JVM

byte [] pkt = assembly.GetName ().GetPublicKeyToken ();
return String.Format ("{0}_{1}_{2}",
AppDomain.CurrentDomain.FriendlyName,
pkt != null ? "StrongName" : "Url",
pkt != null && pkt.Length > 0 ? "StrongName" : "Url",
GetEvidenceHash());

#else // AssemblyProductAttribute-based code
AssemblyProductAttribute [] attrs = (AssemblyProductAttribute[]) assembly.GetCustomAttributes (typeof (AssemblyProductAttribute), true);

Expand All @@ -299,18 +297,22 @@ private static string GetProductName ()
#endif
}

// FIXME: it seems that something else is used
// here, to convert hash bytes to string.
// Note: Changed from base64() to hex output to avoid unexpected chars like '\' or '/' with filesystem meaning.
// Otherwise eventually filenames, which are invalid on linux or windows, might be created.
// Signed-off-by: Carsten Schlote <[email protected]>
// TODO: Compare with .NET. It might be also, that their way isn't suitable for Unix OS derivates (slahes in output)
private static string GetEvidenceHash ()
{
Assembly assembly = Assembly.GetEntryAssembly ();
if (assembly == null)
assembly = Assembly.GetCallingAssembly ();

byte [] pkt = assembly.GetName ().GetPublicKeyToken ();
byte [] hash = SHA1.Create ().ComputeHash (pkt != null ? pkt : Encoding.UTF8.GetBytes (assembly.EscapedCodeBase));

return Convert.ToBase64String (hash);
byte [] hash = SHA1.Create ().ComputeHash (pkt != null && pkt.Length >0 ? pkt : Encoding.UTF8.GetBytes (assembly.EscapedCodeBase));
System.Text.StringBuilder evidence_string = new System.Text.StringBuilder();
foreach (byte b in hash)
evidence_string.AppendFormat("{0:x2}",b);
return evidence_string.ToString ();
}

private static string GetProductVersion ()
Expand Down