This commit is contained in:
Jsj
2008-05-16 18:07:47 +00:00
parent 9d0b3cd543
commit cda0291dbd
116 changed files with 4257 additions and 3382 deletions

View File

@@ -42,14 +42,14 @@ namespace VEPROMS.CSLA.Library
{
foreach (GroupAssignment tmp in _GroupAssignments)
{
if(tmp.IsDirty)refreshGroupAssignments.Add(tmp);
if (tmp.IsDirty) refreshGroupAssignments.Add(tmp);
}
}
if (_GroupMemberships != null && _GroupMemberships.IsDirty)
{
foreach (GroupMembership tmp in _GroupMemberships)
{
if(tmp.IsDirty)refreshGroupMemberships.Add(tmp);
if (tmp.IsDirty) refreshGroupMemberships.Add(tmp);
}
}
}
@@ -78,15 +78,20 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<Group> _AllList = new List<Group>();
private static Dictionary<string, Group> _AllByPrimaryKey = new Dictionary<string, Group>();
private static Dictionary<string, Group> _AllByGroupName = new Dictionary<string, Group>();
private static Dictionary<string, List<Group>> _AllByPrimaryKey = new Dictionary<string, List<Group>>();
private static Dictionary<string, List<Group>> _AllByGroupName = new Dictionary<string, List<Group>>();
private static void ConvertListToDictionary()
{
List<Group> remove = new List<Group>();
foreach (Group tmp in _AllList)
{
_AllByPrimaryKey[tmp.GID.ToString()]=tmp; // Primary Key
_AllByGroupName[tmp.GroupName.ToString()] = tmp; // Unique Index
if (!_AllByPrimaryKey.ContainsKey(tmp.GID.ToString()))
{
_AllByPrimaryKey[tmp.GID.ToString()] = new List<Group>(); // Add new list for PrimaryKey
_AllByGroupName[tmp.GroupName.ToString()] = new List<Group>(); // Add new list for GroupName
}
_AllByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list
_AllByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index
remove.Add(tmp);
}
foreach (Group tmp in remove)
@@ -96,14 +101,14 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = gid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
return null;
}
public static Group GetExistingByGroupName(string groupName)
{
ConvertListToDictionary();
string key = groupName.ToString();
if (_AllByGroupName.ContainsKey(key)) return _AllByGroupName[key];
if (_AllByGroupName.ContainsKey(key)) return _AllByGroupName[key][0];
return null;
}
#endregion
@@ -125,7 +130,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GID",true);
CanReadProperty("GID", true);
return _GID;
}
}
@@ -135,13 +140,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupName",true);
CanReadProperty("GroupName", true);
return _GroupName;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("GroupName",true);
CanWriteProperty("GroupName", true);
if (value == null) value = string.Empty;
if (_GroupName != value)
{
@@ -156,13 +161,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupType",true);
CanReadProperty("GroupType", true);
return _GroupType;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("GroupType",true);
CanWriteProperty("GroupType", true);
if (_GroupType != value)
{
_GroupType = value;
@@ -176,13 +181,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("Config",true);
CanWriteProperty("Config", true);
if (value == null) value = string.Empty;
if (_Config != value)
{
@@ -197,13 +202,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DTS",true);
CanWriteProperty("DTS", true);
if (_DTS != value)
{
_DTS = value;
@@ -217,13 +222,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("UsrID",true);
CanWriteProperty("UsrID", true);
if (value == null) value = string.Empty;
if (_UsrID != value)
{
@@ -242,7 +247,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupAssignmentCount",true);
CanReadProperty("GroupAssignmentCount", true);
return _GroupAssignmentCount;
}
}
@@ -256,10 +261,10 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupAssignments",true);
if(_GroupAssignmentCount > 0 && _GroupAssignments == null)
CanReadProperty("GroupAssignments", true);
if (_GroupAssignmentCount > 0 && _GroupAssignments == null)
_GroupAssignments = GroupAssignments.GetByGID(GID);
else if(_GroupAssignments == null)
else if (_GroupAssignments == null)
_GroupAssignments = GroupAssignments.New();
return _GroupAssignments;
}
@@ -273,7 +278,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupMembershipCount",true);
CanReadProperty("GroupMembershipCount", true);
return _GroupMembershipCount;
}
}
@@ -287,21 +292,21 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupMemberships",true);
if(_GroupMembershipCount > 0 && _GroupMemberships == null)
CanReadProperty("GroupMemberships", true);
if (_GroupMembershipCount > 0 && _GroupMemberships == null)
_GroupMemberships = GroupMemberships.GetByGID(GID);
else if(_GroupMemberships == null)
else if (_GroupMemberships == null)
_GroupMemberships = GroupMemberships.New();
return _GroupMemberships;
}
}
public override bool IsDirty
{
get { return base.IsDirty || (_GroupAssignments == null? false : _GroupAssignments.IsDirty) || (_GroupMemberships == null? false : _GroupMemberships.IsDirty); }
get { return base.IsDirty || (_GroupAssignments == null ? false : _GroupAssignments.IsDirty) || (_GroupMemberships == null ? false : _GroupMemberships.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_GroupAssignments == null? true : _GroupAssignments.IsValid) && (_GroupMemberships == null? true : _GroupMemberships.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_GroupAssignments == null ? true : _GroupAssignments.IsValid) && (_GroupMemberships == null ? true : _GroupMemberships.IsValid); }
}
// TODO: Replace base Group.ToString function as necessary
/// <summary>
@@ -324,23 +329,24 @@ namespace VEPROMS.CSLA.Library
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules=false;
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
get {
if(_CheckingBrokenRules)return null;
get
{
if (_CheckingBrokenRules) return null;
if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
try
{
_CheckingBrokenRules=true;
_CheckingBrokenRules = true;
IVEHasBrokenRules hasBrokenRules = null;
if (_GroupAssignments != null && (hasBrokenRules = _GroupAssignments.HasBrokenRules) != null) return hasBrokenRules;
if (_GroupMemberships != null && (hasBrokenRules = _GroupMemberships.HasBrokenRules) != null) return hasBrokenRules;
if (_GroupAssignments != null && (hasBrokenRules = _GroupAssignments.HasBrokenRules) != null) return hasBrokenRules;
if (_GroupMemberships != null && (hasBrokenRules = _GroupMemberships.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -455,15 +461,29 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _GroupUnique = 0;
private int _MyGroupUnique;
public int MyGroupUnique
{
get { return _MyGroupUnique; }
}
protected Group()
{/* require use of factory methods */
_MyGroupUnique = ++_GroupUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(GID.ToString());
_AllByGroupName.Remove(GroupName.ToString());
if (!_AllByPrimaryKey.ContainsKey(GID.ToString())) return;
List<Group> listGroup = _AllByPrimaryKey[GID.ToString()]; // Get the list of items
listGroup.Remove(this); // Remove the item from the list
if (listGroup.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(GID.ToString()); // remove the list
listGroup = _AllByGroupName[GID.ToString()]; // Get the list of items
listGroup.Remove(this); // Remove the item from the list
if (listGroup.Count == 0) //If there are no items left in the list
_AllByGroupName.Remove(GID.ToString()); // remove the list
}
public static Group New()
{
@@ -544,7 +564,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<Group>(new PKCriteria(gid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -563,8 +583,8 @@ namespace VEPROMS.CSLA.Library
Group tmp = GetExistingByGroupName(groupName);
if (tmp == null)
{
tmp=DataPortal.Fetch<Group>(new GroupNameCriteria(groupName));
_AllList.Add(tmp);
tmp = DataPortal.Fetch<Group>(new GroupNameCriteria(groupName));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -654,7 +674,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.ReadData", GetHashCode());
try
{
_GID = dr.GetInt32("GID");
@@ -670,14 +690,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Group.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -711,14 +731,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Group.DataPortal_Fetch", ex);
}
}
private void DataPortal_Fetch(GroupNameCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -746,7 +766,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Group.DataPortal_Fetch", ex);
}
@@ -767,13 +787,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Group.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -810,11 +830,11 @@ namespace VEPROMS.CSLA.Library
// update child objects
if (_GroupAssignments != null) _GroupAssignments.Update(this);
if (_GroupMemberships != null) _GroupMemberships.Update(this);
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Group.SQLInsert", ex);
}
@@ -822,7 +842,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int gid, string groupName, int? groupType, string config, DateTime dts, string usrID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -851,7 +871,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Add", ex);
throw new DbCslaException("Group.Add", ex);
}
}
@@ -859,7 +879,7 @@ namespace VEPROMS.CSLA.Library
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -873,7 +893,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -882,7 +902,7 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
@@ -917,7 +937,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -940,7 +960,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int gid, string groupName, int? groupType, string config, DateTime dts, string usrID, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -967,7 +987,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Update", ex);
throw new DbCslaException("Group.Update", ex);
}
}
@@ -979,7 +999,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -995,7 +1015,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Group.DataPortal_Delete", ex);
}
@@ -1003,7 +1023,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int gid)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -1018,7 +1038,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Remove", ex);
throw new DbCslaException("Group.Remove", ex);
}
}
@@ -1052,7 +1072,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -1070,7 +1090,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Group.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Execute", ex);
throw new DbCslaException("Group.DataPortal_Execute", ex);
}
}