Exemplo n.º 1
0
        /// <summary>
        /// Override Equals
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            //
            // Initialize result
            bool result = false;


            //
            // Check
            if (obj is UniqueColumnSnapshot)
            {
                UniqueColumnSnapshot uniqueColumn = (UniqueColumnSnapshot)obj;
                if (uniqueColumn.Name.Equals(this.Name))
                {
                    if (uniqueColumn.Value != null && uniqueColumn.Value.Equals(this.Value))
                    {
                        result = true;
                    }
                }
            }


            //
            // 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 unique column snapshot to list snapshot
 /// </summary>
 /// <param name="uniqueColumnSnapshot"></param>
 public void Add(UniqueColumnSnapshot uniqueColumnSnapshot)
 {
     this._listUniqueColumnSnapshot.Add(uniqueColumnSnapshot);
 }
 /// <summary>
 /// Add unique column snapshot to list snapshot
 /// </summary>
 /// <param name="uniqueColumnSnapshot"></param>
 public void Add(UniqueColumnSnapshot uniqueColumnSnapshot)
 {
     this._listUniqueColumnSnapshot.Add(uniqueColumnSnapshot);
 }
        /// <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;
        }