Esempio n. 1
0
        internal DmRelation Clone(DmSet destination)
        {
            DmTable parent    = destination.Tables[ParentTable.TableName];
            DmTable child     = destination.Tables[ChildTable.TableName];
            int     keyLength = parentKey.Columns.Length;

            DmColumn[] parentColumns = new DmColumn[keyLength];
            DmColumn[] childColumns  = new DmColumn[keyLength];

            for (int i = 0; i < keyLength; i++)
            {
                parentColumns[i] = parent.Columns[ParentKey.Columns[i].ColumnName];
                childColumns[i]  = child.Columns[ChildKey.Columns[i].ColumnName];
            }

            DmRelation clone = new DmRelation(RelationName, parentColumns, childColumns);

            return(clone);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a clone of the current DmTable
        /// </summary>
        public DmTable Clone()
        {
            DmTable clone = new DmTable
            {
                // Set All properties
                TableName              = tableName,
                Schema                 = schema,
                Culture                = culture,
                CaseSensitive          = caseSensitive,
                OriginalProvider       = OriginalProvider,
                SyncDirection          = SyncDirection,
                TrackingTablesPrefix   = TrackingTablesPrefix,
                TrackingTablesSuffix   = TrackingTablesSuffix,
                StoredProceduresPrefix = StoredProceduresPrefix,
                StoredProceduresSuffix = StoredProceduresSuffix,
                TriggersPrefix         = TriggersPrefix,
                TriggersSuffix         = TriggersSuffix
            };

            // add all columns
            var clmns = this.Columns;

            for (int i = 0; i < clmns.Count; i++)
            {
                clone.Columns.Add(clmns[i].Clone());
            }

            // Create PrimaryKey
            DmColumn[] pkey = PrimaryKey.Columns;
            if (pkey != null && pkey.Length > 0)
            {
                DmColumn[] key = new DmColumn[pkey.Length];

                for (int i = 0; i < pkey.Length; i++)
                {
                    key[i] = clone.Columns[pkey[i].Ordinal];
                }

                clone.PrimaryKey = new DmKey(key);
            }

            return(clone);
        }
Esempio n. 3
0
        /// <summary>
        /// Copy a record, whatever the state (Added, Modified, Deleted etc...)
        /// </summary>
        internal void CopyRecords(DmTable src, int srcRecord, int newRecord)
        {
            // Parcours de toutes les colonnes de destination
            for (int i = 0; i < this.Columns.Count; ++i)
            {
                // colonne de destination
                DmColumn dstColumn = this.Columns[i];
                // colonne à copier
                DmColumn srcColumn = src.Columns.FirstOrDefault(c => this.IsEqual(c.ColumnName, dstColumn.ColumnName));

                if (srcColumn == null)
                {
                    dstColumn.Init(newRecord);
                    continue;
                }

                if (dstColumn.IsValueType)
                {
                    dstColumn[newRecord] = srcColumn[srcRecord];
                    continue;
                }

                if (dstColumn.DataType == typeof(byte[]))
                {
                    byte[] srcArray  = (byte[])srcColumn[srcRecord];
                    byte[] destArray = (byte[])dstColumn[newRecord];

                    Buffer.BlockCopy(srcArray, 0, destArray, 0, srcArray.Length);
                    continue;
                }
                if (dstColumn.DataType == typeof(char[]))
                {
                    char[] srcArray  = (char[])srcColumn[srcRecord];
                    char[] destArray = (char[])dstColumn[newRecord];

                    Buffer.BlockCopy(srcArray, 0, destArray, 0, srcArray.Length);
                    continue;
                }

                dstColumn[newRecord] = srcColumn[srcRecord];
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Get Changes from the DmTable, with a DmRowState value
        /// </summary>
        public DmTable GetChanges(DmRowState rowStates)
        {
            DmTable dtChanges = this.Clone();
            DmRow   row       = null;

            for (int i = 0; i < Rows.Count; i++)
            {
                row = Rows[i];
                if ((row.RowState & rowStates) == row.RowState)
                {
                    dtChanges.ImportRow(row);
                }
            }

            if (dtChanges.Rows.Count == 0)
            {
                return(null);
            }

            return(dtChanges);
        }
Esempio n. 5
0
        /// <summary>
        /// Get Changes from the DmTable
        /// </summary>
        public DmTable GetChanges()
        {
            DmTable dtChanges = this.Clone();
            DmRow   row       = null;

            for (int i = 0; i < Rows.Count; i++)
            {
                row = Rows[i];
                if (row.oldRecord != row.newRecord)
                {
                    dtChanges.ImportRow(row);
                }
            }

            if (dtChanges.Rows.Count == 0)
            {
                return(null);
            }

            return(dtChanges);
        }
Esempio n. 6
0
        DmKey GetSrcKey(DmTable src, DmTable dst)
        {
            if (src.PrimaryKey != null)
            {
                return(src.PrimaryKey);
            }

            DmKey key = default(DmKey);

            if (dst.PrimaryKey != null)
            {
                DmColumn[] dstColumns = dst.PrimaryKey.Columns;
                DmColumn[] srcColumns = new DmColumn[dstColumns.Length];
                for (int j = 0; j < dstColumns.Length; j++)
                {
                    srcColumns[j] = src.Columns[dstColumns[j].ColumnName];
                }

                key = new DmKey(srcColumns); // DmKey will take ownership of srcColumns
            }

            return(key);
        }
Esempio n. 7
0
        /// <summary>
        /// Create a clone of the current DmTable
        /// </summary>
        public DmTable Clone()
        {
            DmTable clone = new DmTable();

            // Set All properties
            clone.TableName        = tableName;
            clone.Schema           = schema;
            clone.Culture          = culture;
            clone.CaseSensitive    = caseSensitive;
            clone.OriginalProvider = OriginalProvider;
            clone.SyncDirection    = SyncDirection;

            // add all columns
            var clmns = this.Columns;

            for (int i = 0; i < clmns.Count; i++)
            {
                clone.Columns.Add(clmns[i].Clone());
            }

            // Create PrimaryKey
            DmColumn[] pkey = PrimaryKey.Columns;
            if (pkey.Length > 0)
            {
                DmColumn[] key = new DmColumn[pkey.Length];

                for (int i = 0; i < pkey.Length; i++)
                {
                    key[i] = clone.Columns[pkey[i].Ordinal];
                }

                clone.PrimaryKey = new DmKey(key);
            }

            return(clone);
        }
Esempio n. 8
0
        public virtual DmSet Clone()
        {
            DmSet ds = new DmSet();

            ds.DmSetName     = this.DmSetName;
            ds.CaseSensitive = this.CaseSensitive;
            ds.Culture       = this.Culture;

            for (int i = 0; i < Tables.Count; i++)
            {
                DmTable dt = Tables[i].Clone();
                ds.Tables.Add(dt);
            }

            List <DmRelation> rels = Relations;

            for (int i = 0; i < rels.Count; i++)
            {
                DmRelation rel = rels[i].Clone(ds);
                ds.Relations.Add(rel);
            }

            return(ds);
        }
Esempio n. 9
0
 internal DmRowCollection(DmTable dt)
 {
     this.table = dt;
 }
Esempio n. 10
0
 public void Dispose()
 {
     internalRows.Clear();
     internalRows = null;
     this.Table   = null;
 }
Esempio n. 11
0
 internal abstract void SetTable(DmTable table);
Esempio n. 12
0
 /// <summary>
 /// Merge a dmTable in this dmTable without perserving changes
 /// </summary>
 public void Merge(DmTable table)
 {
     Merge(table, false);
 }
Esempio n. 13
0
 internal DmMerger(DmTable dataTable, bool preserveChanges)
 {
     this.dataTable       = dataTable;
     this.preserveChanges = preserveChanges;
 }
Esempio n. 14
0
        DmTable MergeSchema(DmTable table)
        {
            if (dataTable == null)
            {
                dataTable = table.Clone();

                if (dataTable.DmSet != null)
                {
                    dataTable.DmSet.Tables.Add(dataTable);
                }
            }
            else
            {
                // Do the columns
                int oldCount = dataTable.Columns.Count;
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    DmColumn src  = table.Columns[i];
                    DmColumn dest = (dataTable.Columns.Contains(src.ColumnName, true)) ? dataTable.Columns[src.ColumnName] : null;

                    // If columns doesn't exist, create it
                    if (dest == null)
                    {
                        dest = src.Clone();
                        dataTable.Columns.Add(dest);
                    }
                }

                // check the PrimaryKey
                DmColumn[] targetPKey = dataTable.PrimaryKey.Columns;
                DmColumn[] tablePKey  = table.PrimaryKey.Columns;
                if (targetPKey.Length != tablePKey.Length)
                {
                    if (tablePKey.Length != 0)
                    {
                        throw new Exception("Merge Failed, keys are differents");
                    }

                    // special case when the target table does not have the PrimaryKey
                    if (targetPKey.Length == 0)
                    {
                        DmColumn[] key = new DmColumn[tablePKey.Length];
                        for (int i = 0; i < tablePKey.Length; i++)
                        {
                            key[i] = dataTable.Columns[tablePKey[i].ColumnName];
                        }

                        dataTable.PrimaryKey = new DmKey(key);
                    }
                }
                else
                {
                    // Check the keys are same
                    for (int i = 0; i < targetPKey.Length; i++)
                    {
                        if (!table.IsEqual(targetPKey[i].ColumnName, tablePKey[i].ColumnName))
                        {
                            throw new Exception("Merge Failed, keys are differents");
                        }
                    }
                }
            }

            return(dataTable);
        }
Esempio n. 15
0
 public DmColumnCollection(DmTable dt)
 {
     this.table = dt;
 }