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

@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<GroupInfo> _AllList = new List<GroupInfo>();
private static Dictionary<string, GroupInfo> _AllByPrimaryKey = new Dictionary<string, GroupInfo>();
private static Dictionary<string, List<GroupInfo>> _AllByPrimaryKey = new Dictionary<string, List<GroupInfo>>();
private static void ConvertListToDictionary()
{
List<GroupInfo> remove = new List<GroupInfo>();
foreach (GroupInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.GID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.GID.ToString()))
{
_AllByPrimaryKey[tmp.GID.ToString()] = new List<GroupInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (GroupInfo tmp in remove)
@@ -57,7 +61,7 @@ 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;
}
#endregion
@@ -85,7 +89,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GID",true);
CanReadProperty("GID", true);
return _GID;
}
}
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupName",true);
CanReadProperty("GroupName", true);
return _GroupName;
}
}
@@ -105,7 +109,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupType",true);
CanReadProperty("GroupType", true);
return _GroupType;
}
}
@@ -115,7 +119,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
}
@@ -125,7 +129,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -135,7 +139,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
}
@@ -148,7 +152,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupAssignmentCount",true);
CanReadProperty("GroupAssignmentCount", true);
return _GroupAssignmentCount;
}
}
@@ -159,7 +163,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupAssignments",true);
CanReadProperty("GroupAssignments", true);
if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null))
_GroupAssignments = AssignmentInfoList.GetByGID(_GID);
if (_GroupAssignmentCount < 0)
@@ -169,7 +173,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshGroupAssignments()
{
_GroupAssignmentCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_GID.ToString()))
foreach (GroupInfo tmp in _AllByPrimaryKey[_GID.ToString()])
tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried
}
private int _GroupMembershipCount = 0;
/// <summary>
@@ -180,7 +187,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupMembershipCount",true);
CanReadProperty("GroupMembershipCount", true);
return _GroupMembershipCount;
}
}
@@ -191,7 +198,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GroupMemberships",true);
CanReadProperty("GroupMemberships", true);
if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null))
_GroupMemberships = MembershipInfoList.GetByGID(_GID);
if (_GroupMembershipCount < 0)
@@ -201,7 +208,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshGroupMemberships()
{
_GroupMembershipCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_GID.ToString()))
foreach (GroupInfo tmp in _AllByPrimaryKey[_GID.ToString()])
tmp._GroupMembershipCount = -1; // This will cause the data to be requeried
}
// TODO: Replace base GroupInfo.ToString function as necessary
/// <summary>
@@ -223,14 +233,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _GroupInfoUnique = 0;
private int _MyGroupInfoUnique;
public int MyGroupInfoUnique
{
get { return _MyGroupInfoUnique; }
}
private GroupInfo()
{/* require use of factory methods */
_MyGroupInfoUnique = ++_GroupInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(GID.ToString());
if (!_AllByPrimaryKey.ContainsKey(GID.ToString())) return;
List<GroupInfo> listGroupInfo = _AllByPrimaryKey[GID.ToString()]; // Get the list of items
listGroupInfo.Remove(this); // Remove the item from the list
if (listGroupInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(GID.ToString()); // remove the list
}
public virtual Group Get()
{
@@ -238,9 +259,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Group tmp)
{
GroupInfo tmpInfo = GetExistingByPrimaryKey(tmp.GID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.GID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (GroupInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Group tmp)
{
@@ -262,7 +285,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<GroupInfo>(new PKCriteria(gid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -276,14 +299,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal GroupInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode());
_MyGroupInfoUnique = ++_GroupInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("GroupInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.Constructor", ex);
throw new DbCslaException("GroupInfo.Constructor", ex);
}
}
@@ -300,7 +324,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] GroupInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.ReadData", GetHashCode());
try
{
_GID = dr.GetInt32("GID");
@@ -314,14 +338,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("GroupInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("GroupInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] GroupInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -349,7 +373,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("GroupInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("GroupInfo.DataPortal_Fetch", ex);
}
@@ -359,7 +383,7 @@ namespace VEPROMS.CSLA.Library
#region extension
GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension();
[Serializable()]
partial class GroupInfoExtension : extensionBase {}
partial class GroupInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{