Пример #1
0
        /// <summary>
        /// constructor for serialization
        /// </summary>
        /// <param name="info">required for serialization</param>
        /// <param name="context">required for serialization</param>
        public TTypedDataSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            //TTypedRelation Relation;
            DataSet   ds;
            DataTable table;
            Int32     i;
            String    strSchema;
            String    diffGram;

            // Console.Writeline('DataSet Serialization constructor');
            try
            {
                //no call to base() needed here, default contructor of base class will be run anyway.

                FConstraints = new ArrayList();
                FRelations   = new ArrayList();
                strSchema    = (string)info.GetValue("XmlSchema", typeof(string));
                diffGram     = (string)info.GetValue("XmlDiffGram", typeof(string));

                if (strSchema != null)
                {
                    // TLogging.Log('xmlSchema exists', [ToLogfile]);

                    // TLogging.Log(strSchema, TLoggingType.ToLogfile);

/*
 * SerializationInfoEnumerator it = info.GetEnumerator();
 * while (it.MoveNext())
 * {
 * TLogging.Log(it.Name +": " + it.Value.ToString());
 * }
 */

                    // it seems if the primary key constraint gets removed, then we are in trouble for deleted rows
                    strSchema = TypedDataSet.RemoveConstraintsFromSchema(strSchema);

                    // TLogging.Log("after: " + strSchema, TLoggingType.ToLogfile);
                    ds = new DataSet();
                    ds.ReadXmlSchema(new XmlTextReader(new System.IO.StringReader(strSchema)));

                    // TLogging.Log('before inittables(ds)', [ToLogfile]);
                    InitTables(ds);

                    // TLogging.Log('after inittables(ds)', [ToLogfile]);
                    this.DataSetName        = ds.DataSetName;
                    this.Prefix             = ds.Prefix;
                    this.Namespace          = ds.Namespace;
                    this.Locale             = ds.Locale;
                    this.CaseSensitive      = ds.CaseSensitive;
                    this.EnforceConstraints = ds.EnforceConstraints;
                    ds.Relations.Clear();

                    // TLogging.Log('xmlschema import: ' + ds.GetXMLSchema(), [ToLogfile]);
                    // TLogging.Log('xmlschema local: ' + this.GetXMLSchema(), [ToLogfile]);
                    // TLogging.Log('before merge', [ToLogfile]);
                    foreach (DataTable RemoveExpressionsTable in ds.Tables)
                    {
                        foreach (DataColumn RemoveExpressionsColumn in RemoveExpressionsTable.Columns)
                        {
                            if (RemoveExpressionsColumn.Expression.Length != 0)
                            {
                                // TLogging.Log(RemoveExpressionsColumn.Expression, [ToLogFile]);
                                RemoveExpressionsColumn.Expression = "";
                            }
                        }
                    }

                    // Console.WriteLine('number of constraints: ' + tables['Partner'].Constraints.Count.ToString());
                    // Console.WriteLine('number of columns: ' + tables['Partner'].Columns.Count.ToString());
                    base.Merge(ds, false, System.Data.MissingSchemaAction.Add); // MissingSchemaAction.Ignore

                    // TLogging.Log('before InitVars', [ToLogfile]);
                    // Console.WriteLine('number of constraints: ' + tables['Partner'].Constraints.Count.ToString());
                    // Console.WriteLine('number of columns: ' + tables['Partner'].Columns.Count.ToString());
                    this.InitVars();

                    // Console.WriteLine('before serializationdata');

                    // it seems if the primary key constraint gets removed, then we are in trouble for deleted rows; this comment was related to bug 111
                    // but now it seems in c# and with .net 2.0, we get the original error again, and it works fine without the constraints; see bug 825
                    MyOwnGetSerializationData(strSchema, diffGram);

                    // GetSerializationData(info, context);
                    // Console.WriteLine('before initConstraints');
                    this.MapTables();
                    this.InitConstraints();
                }
                else
                {
                    // Console.Writeline('xmlSchema does not exists');
                    InitClass();
                    ds = new TOtherDataSet(info, context);
                    GetSerializationData(info, context);
                    this.InitVars();
                    this.InitConstraints();
                    EnforceConstraints = ds.EnforceConstraints;
                }

                // start default behaviour
                // check if relation is enabled
                if (ds.Relations.Count != 0)
                {
                    // ms.net client and mono server: relations.count is 0

                    foreach (TTypedRelation Relation in FRelations)
                    {
                        Relation.FEnabled = (ds.Relations.IndexOf(Relation.FName) != -1);
                    }
                }
                else if (FRelations.Count != 0)
                {
                    foreach (TTypedRelation Relation in FRelations)
                    {
                        Relation.FEnabled = true;
                    }
                }

                i = 0;

                while (i < Tables.Count)
                {
                    table = (DataTable)Tables[i];

                    if (ds.Tables.IndexOf(table.TableName) == -1)
                    {
                        RemoveTable(table.TableName);
                    }
                    else
                    {
                        i = i + 1;
                    }
                }

                EnableConstraints();
                EnableRelations();
            }
            catch (Exception e)
            {
                TLogging.Log("PROBLEM: " + e.Message, TLoggingType.ToLogfile);
                TLogging.Log("PROBLEM: " + e.StackTrace, TLoggingType.ToLogfile);
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// constructor for serialization
        /// </summary>
        /// <param name="info">required for serialization</param>
        /// <param name="context">required for serialization</param>
        public TTypedDataSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            //TTypedRelation Relation;
            DataSet ds;
            DataTable table;
            Int32 i;
            String strSchema;
            String diffGram;

            // Console.Writeline('DataSet Serialization constructor');
            try
            {
                //no call to base() needed here, default contructor of base class will be run anyway.

                FConstraints = new ArrayList();
                FRelations = new ArrayList();
                strSchema = (string)info.GetValue("XmlSchema", typeof(string));
                diffGram = (string)info.GetValue("XmlDiffGram", typeof(string));

                if (strSchema != null)
                {
                    // TLogging.Log('xmlSchema exists', [ToLogfile]);

                    // TLogging.Log(strSchema, TLoggingType.ToLogfile);

/*
 * SerializationInfoEnumerator it = info.GetEnumerator();
 * while (it.MoveNext())
 * {
 * TLogging.Log(it.Name +": " + it.Value.ToString());
 * }
 */

                    // it seems if the primary key constraint gets removed, then we are in trouble for deleted rows
                    strSchema = TypedDataSet.RemoveConstraintsFromSchema(strSchema);

                    // TLogging.Log("after: " + strSchema, TLoggingType.ToLogfile);
                    ds = new DataSet();
                    ds.ReadXmlSchema(new XmlTextReader(new System.IO.StringReader(strSchema)));

                    // TLogging.Log('before inittables(ds)', [ToLogfile]);
                    InitTables(ds);

                    // TLogging.Log('after inittables(ds)', [ToLogfile]);
                    this.DataSetName = ds.DataSetName;
                    this.Prefix = ds.Prefix;
                    this.Namespace = ds.Namespace;
                    this.Locale = ds.Locale;
                    this.CaseSensitive = ds.CaseSensitive;
                    this.EnforceConstraints = ds.EnforceConstraints;
                    ds.Relations.Clear();

                    // TLogging.Log('xmlschema import: ' + ds.GetXMLSchema(), [ToLogfile]);
                    // TLogging.Log('xmlschema local: ' + this.GetXMLSchema(), [ToLogfile]);
                    // TLogging.Log('before merge', [ToLogfile]);
                    foreach (DataTable RemoveExpressionsTable in ds.Tables)
                    {
                        foreach (DataColumn RemoveExpressionsColumn in RemoveExpressionsTable.Columns)
                        {
                            if (RemoveExpressionsColumn.Expression.Length != 0)
                            {
                                // TLogging.Log(RemoveExpressionsColumn.Expression, [ToLogFile]);
                                RemoveExpressionsColumn.Expression = "";
                            }
                        }
                    }

                    // Console.WriteLine('number of constraints: ' + tables['Partner'].Constraints.Count.ToString());
                    // Console.WriteLine('number of columns: ' + tables['Partner'].Columns.Count.ToString());
                    base.Merge(ds, false, System.Data.MissingSchemaAction.Add); // MissingSchemaAction.Ignore

                    // TLogging.Log('before InitVars', [ToLogfile]);
                    // Console.WriteLine('number of constraints: ' + tables['Partner'].Constraints.Count.ToString());
                    // Console.WriteLine('number of columns: ' + tables['Partner'].Columns.Count.ToString());
                    this.InitVars();

                    // Console.WriteLine('before serializationdata');

                    // it seems if the primary key constraint gets removed, then we are in trouble for deleted rows; this comment was related to bug 111
                    // but now it seems in c# and with .net 2.0, we get the original error again, and it works fine without the constraints; see bug 825
                    MyOwnGetSerializationData(strSchema, diffGram);

                    // GetSerializationData(info, context);
                    // Console.WriteLine('before initConstraints');
                    this.MapTables();
                    this.InitConstraints();
                }
                else
                {
                    // Console.Writeline('xmlSchema does not exists');
                    InitClass();
                    ds = new TOtherDataSet(info, context);
                    GetSerializationData(info, context);
                    this.InitVars();
                    this.InitConstraints();
                    EnforceConstraints = ds.EnforceConstraints;
                }

                // start default behaviour
                // check if relation is enabled
                if (ds.Relations.Count != 0)
                {
                    // ms.net client and mono server: relations.count is 0

                    foreach (TTypedRelation Relation in FRelations)
                    {
                        Relation.FEnabled = (ds.Relations.IndexOf(Relation.FName) != -1);
                    }
                }
                else if (FRelations.Count != 0)
                {
                    foreach (TTypedRelation Relation in FRelations)
                    {
                        Relation.FEnabled = true;
                    }
                }

                i = 0;

                while (i < Tables.Count)
                {
                    table = (DataTable)Tables[i];

                    if (ds.Tables.IndexOf(table.TableName) == -1)
                    {
                        RemoveTable(table.TableName);
                    }
                    else
                    {
                        i = i + 1;
                    }
                }

                EnableConstraints();
                EnableRelations();
            }
            catch (Exception e)
            {
                TLogging.Log("PROBLEM: " + e.Message, TLoggingType.ToLogfile);
                TLogging.Log("PROBLEM: " + e.StackTrace, TLoggingType.ToLogfile);
                throw;
            }
        }