2022-03-15 16:59:24 +00:00
|
|
|
|
namespace ASC.Data.Backup.Tasks.Data;
|
2022-02-09 18:49:52 +00:00
|
|
|
|
|
|
|
|
|
public enum RelationImportance
|
2021-08-31 13:59:32 +00:00
|
|
|
|
{
|
2022-02-09 18:49:52 +00:00
|
|
|
|
Low,
|
|
|
|
|
Normal
|
|
|
|
|
}
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
[DebuggerDisplay("({ParentTable},{ParentColumn})->({ChildTable},{ChildColumn})")]
|
|
|
|
|
public class RelationInfo
|
|
|
|
|
{
|
|
|
|
|
public string ParentTable { get; private set; }
|
|
|
|
|
public string ParentColumn { get; private set; }
|
|
|
|
|
public string ChildTable { get; private set; }
|
|
|
|
|
public string ChildColumn { get; private set; }
|
|
|
|
|
public Type ParentModule { get; private set; }
|
|
|
|
|
public RelationImportance Importance { get; private set; }
|
|
|
|
|
public Func<DataRowInfo, bool> CollisionResolver { get; private set; }
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public RelationInfo(string parentTable, string parentColumn, string childTable, string childColumn)
|
|
|
|
|
: this(parentTable, parentColumn, childTable, childColumn, null, null) { }
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public RelationInfo(string parentTable, string parentColumn, string childTable, string childColumn, Func<DataRowInfo, bool> collisionResolver)
|
|
|
|
|
: this(parentTable, parentColumn, childTable, childColumn, null, collisionResolver) { }
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public RelationInfo(string parentTable, string parentColumn, string childTable, string childColumn, Type parentModule)
|
|
|
|
|
: this(parentTable, parentColumn, childTable, childColumn, parentModule, null) { }
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public RelationInfo(string parentTable, string parentColumn, string childTable, string childColumn, Type parentModule, Func<DataRowInfo, bool> collisionResolver)
|
|
|
|
|
: this(parentTable, parentColumn, childTable, childColumn, parentModule, collisionResolver, RelationImportance.Normal) { }
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public RelationInfo(string parentTable, string parentColumn, string childTable, string childColumn, Type parentModule, Func<DataRowInfo, bool> collisionResolver, RelationImportance importance)
|
|
|
|
|
{
|
|
|
|
|
ParentTable = parentTable;
|
|
|
|
|
ParentColumn = parentColumn;
|
|
|
|
|
ChildTable = childTable;
|
|
|
|
|
ChildColumn = childColumn;
|
|
|
|
|
ParentModule = parentModule;
|
|
|
|
|
CollisionResolver = collisionResolver;
|
|
|
|
|
Importance = importance;
|
|
|
|
|
}
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public bool FitsForTable(string tableName)
|
|
|
|
|
{
|
|
|
|
|
return string.Equals(tableName, ChildTable, StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
}
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public bool FitsForRow(DataRowInfo row)
|
|
|
|
|
{
|
|
|
|
|
return FitsForTable(row.TableName) && (CollisionResolver == null || CollisionResolver(row));
|
|
|
|
|
}
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public bool IsExternal()
|
|
|
|
|
{
|
|
|
|
|
return ParentModule != null;
|
|
|
|
|
}
|
2021-08-31 13:59:32 +00:00
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
|
public bool IsSelfRelation()
|
|
|
|
|
{
|
|
|
|
|
return string.Equals(ParentTable, ChildTable, StringComparison.InvariantCultureIgnoreCase);
|
2021-08-31 13:59:32 +00:00
|
|
|
|
}
|
2022-02-09 18:49:52 +00:00
|
|
|
|
}
|