/// <summary>
        /// Check table contains this record or not
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="record"></param>
        /// <returns></returns>
        public bool Contains(string tableName, object record)
        {
            //
            // Initialize result
            bool result = false;


            //
            // First, try to extract main information of record
            RecordSnapshot recordSnapshot = this.GetRecordSnapshot(tableName, record);
            TableSnapshot  tableSnapshot  = this._listTableSnapshot.FirstOrDefault(x => x.TableName.Equals(tableName));

            if (tableSnapshot != null)
            {
                result = tableSnapshot.Contains(recordSnapshot);
                if (result == false)
                {
                    result = tableSnapshot.IsDuplicatedUniqueColumn(recordSnapshot);
                }
            }


            //
            // Return result
            return(result);
        }
 /// <summary>
 /// Add new record snapshot to table
 /// </summary>
 /// <param name="record"></param>
 public void Add(RecordSnapshot record)
 {
     if (this.Contains(record) == false)
     {
         this._listRecordSnapshot.Add(record);
     }
 }
示例#3
0
        /// <summary>
        /// Check two record snapshot duplicated unique column or grouped unique column or not
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool IsDuplicatedUniqueColumn(object obj)
        {
            //
            // Initialize result
            bool result = false;

            //
            // Cast type
            if (obj is RecordSnapshot)
            {
                RecordSnapshot recordSnapshot = obj as RecordSnapshot;
                if (recordSnapshot.GetNumberOfGroupUniqueColumn() == this.GetNumberOfGroupUniqueColumn() && this.GetNumberOfGroupUniqueColumn() != 0)
                {
                    //
                    // If all group unique column are equal, return true (mean two record have duplicated unique field)
                    // Else return false
                    result = true;
                    foreach (GroupUniqueColumnSnapshot groupUniqueColumnSnapshot in recordSnapshot._listGroupUniqueColumnSnapshot)
                    {
                        if (this._listGroupUniqueColumnSnapshot.Any(x => x.Equals(groupUniqueColumnSnapshot)) == false)
                        {
                            result = false;
                            break;
                        }
                    }
                }
            }


            //
            // Return result
            return(result);
        }
示例#4
0
        /// <summary>
        /// Compare two record snapshot base on primary key name and value
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            //
            // Initialize result
            bool result = false;


            //
            // Check
            if (obj is RecordSnapshot)
            {
                result = true;
                RecordSnapshot recordSnapshot = (RecordSnapshot)obj;
                foreach (PrimaryKeySnapshot pkSnapshot in recordSnapshot._listPrimaryKeySnapshot)
                {
                    if (this._listPrimaryKeySnapshot.Any(x => x.Equals(pkSnapshot)) == false)
                    {
                        result = false;
                        break;
                    }
                }
            }


            //
            // Return result
            return(result);
        }
        /// <summary>
        /// Get tablesnapshot by name
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public TableSnapshot GetTableSnapshot(string tableName)
        {
            //
            // Initialize result
            TableSnapshot result = new TableSnapshot(tableName);


            //
            // Get list of primary keys
            // For each primary key
            // Try to get it's properties in entity
            // Then add to hasTable
            DbSet dbSet = this._mapDatabase.GetTable(tableName);

            dbSet.Load();
            List <string> listPrimaryKeys = this._mapDatabase.GetPrimaryKeyName(tableName);
            List <GroupUniqueColumnInformation> listGroupUniqueInformation = this._mapDatabase.GetGroupUniqueColumnInformation(tableName);
            TypeAccessor typeAccessor = this._mapDatabase.GetTableTypeAccessor(tableName);


            //
            // Foreach record in database
            // Try to get RecordSnapshot
            foreach (object record in dbSet)
            {
                RecordSnapshot recordSnapshot = new RecordSnapshot();

                //
                // Get primary key value
                foreach (string primaryKey in listPrimaryKeys)
                {
                    PrimaryKeySnapshot primaryKeySnapshot = new PrimaryKeySnapshot(primaryKey, typeAccessor[record, primaryKey]);
                    recordSnapshot.Add(primaryKeySnapshot);
                }


                //
                // Get unqiue column value
                foreach (GroupUniqueColumnInformation groupUnique in listGroupUniqueInformation)
                {
                    GroupUniqueColumnSnapshot groupUniqueSnapshot = new GroupUniqueColumnSnapshot(groupUnique.ConstraintName);
                    foreach (UniqueColumnInformation uniqueColumnInfo in groupUnique.ListUniqueColumn)
                    {
                        UniqueColumnSnapshot uniqueColumnSnapshot = new UniqueColumnSnapshot(uniqueColumnInfo.ColumnName, typeAccessor[record, uniqueColumnInfo.ColumnName]);
                        groupUniqueSnapshot.Add(uniqueColumnSnapshot);
                    }
                    recordSnapshot.Add(groupUniqueSnapshot);
                }


                result.Add(recordSnapshot);
            }


            //
            // Return result
            return(result);
        }
        /// <summary>
        /// Add new record to table snapshot
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="record"></param>
        public void Add(string tableName, object record)
        {
            //
            // Check
            // Are there any table in this snapshot contains tableName
            // If not, just continue
            if (this._tableTypeReflection.ContainsKey(tableName) == false)
            {
                return;
            }


            //
            // Firt, try to get record snapshot from original record
            RecordSnapshot recordSnapshot = this.GetRecordSnapshot(tableName, record);

            if (recordSnapshot == null)
            {
                return;
            }


            //
            // Then try to add to tableSnapshot
            TableSnapshot tableSnapshot = this._listTableSnapshot.FirstOrDefault(x => x.TableName.Equals(tableName));

            if (tableSnapshot == null)
            {
                tableSnapshot = new TableSnapshot(tableName);
                tableSnapshot.Add(recordSnapshot);
                this._listTableSnapshot.Add(tableSnapshot);
            }
            else
            {
                tableSnapshot.Add(recordSnapshot);
            }
        }
 /// <summary>
 /// Check table contains record or not
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public bool Contains(RecordSnapshot record)
 {
     return(this._listRecordSnapshot.Any(x => x.Equals(record)));
 }
 /// <summary>
 /// Check is duplicated unique field
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public bool IsDuplicatedUniqueColumn(RecordSnapshot record)
 {
     return(this._listRecordSnapshot.Any(x => x.IsDuplicatedUniqueColumn(record)));
 }
        /// <summary>
        /// Get tablesnapshot by name
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public TableSnapshot GetTableSnapshot(string tableName)
        {
            //
            // Initialize result
            TableSnapshot result = new TableSnapshot(tableName);

            //
            // Get list of primary keys
            // For each primary key
            // Try to get it's properties in entity
            // Then add to hasTable
            DbSet dbSet = this._mapDatabase.GetTable(tableName);
            dbSet.Load();
            List<string> listPrimaryKeys = this._mapDatabase.GetPrimaryKeyName(tableName);
            List<GroupUniqueColumnInformation> listGroupUniqueInformation = this._mapDatabase.GetGroupUniqueColumnInformation(tableName);
            TypeAccessor typeAccessor = this._mapDatabase.GetTableTypeAccessor(tableName);

            //
            // Foreach record in database
            // Try to get RecordSnapshot
            foreach (object record in dbSet)
            {
                RecordSnapshot recordSnapshot = new RecordSnapshot();

                //
                // Get primary key value
                foreach (string primaryKey in listPrimaryKeys)
                {
                    PrimaryKeySnapshot primaryKeySnapshot = new PrimaryKeySnapshot(primaryKey, typeAccessor[record, primaryKey]);
                    recordSnapshot.Add(primaryKeySnapshot);
                }

                //
                // Get unqiue column value
                foreach (GroupUniqueColumnInformation groupUnique in listGroupUniqueInformation)
                {
                    GroupUniqueColumnSnapshot groupUniqueSnapshot = new GroupUniqueColumnSnapshot(groupUnique.ConstraintName);
                    foreach (UniqueColumnInformation uniqueColumnInfo in groupUnique.ListUniqueColumn)
                    {
                        UniqueColumnSnapshot uniqueColumnSnapshot = new UniqueColumnSnapshot(uniqueColumnInfo.ColumnName, typeAccessor[record, uniqueColumnInfo.ColumnName]);
                        groupUniqueSnapshot.Add(uniqueColumnSnapshot);
                    }
                    recordSnapshot.Add(groupUniqueSnapshot);
                }

                result.Add(recordSnapshot);
            }

            //
            // Return result
            return result;
        }
 /// <summary>
 /// Check is duplicated unique field
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public bool IsDuplicatedUniqueColumn(RecordSnapshot record)
 {
     return this._listRecordSnapshot.Any(x => x.IsDuplicatedUniqueColumn(record));
 }
 /// <summary>
 /// Check table contains record or not
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public bool Contains(RecordSnapshot record)
 {
     return this._listRecordSnapshot.Any(x => x.Equals(record));
 }
 /// <summary>
 /// Add new record snapshot to table
 /// </summary>
 /// <param name="record"></param>
 public void Add(RecordSnapshot record)
 {
     if (this.Contains(record) == false)
     {
         this._listRecordSnapshot.Add(record);
     }
 }