This commit is contained in:
2008-08-12 11:21:19 +00:00
parent 610f408c6d
commit d0dba2aad4
14 changed files with 937 additions and 240 deletions

View File

@@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
protected static List<AssignmentInfo> _AllList = new List<AssignmentInfo>();
private static Dictionary<string, List<AssignmentInfo>> _AllByPrimaryKey = new Dictionary<string, List<AssignmentInfo>>();
private static List<AssignmentInfo> _CacheList = new List<AssignmentInfo>();
protected static void AddToCache(AssignmentInfo assignmentInfo)
{
if (!_CacheList.Contains(assignmentInfo)) _CacheList.Add(assignmentInfo); // In AddToCache
}
protected static void RemoveFromCache(AssignmentInfo assignmentInfo)
{
while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache
}
private static Dictionary<string, List<AssignmentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AssignmentInfo>>();
private static void ConvertListToDictionary()
{
List<AssignmentInfo> remove = new List<AssignmentInfo>();
foreach (AssignmentInfo tmp in _AllList)
foreach (AssignmentInfo tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.AID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString()))
{
_AllByPrimaryKey[tmp.AID.ToString()] = new List<AssignmentInfo>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.AID.ToString()] = new List<AssignmentInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list
_CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (AssignmentInfo tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
internal static void AddList(AssignmentInfoList lst)
{
foreach (AssignmentInfo item in lst) _AllList.Add(item);
foreach (AssignmentInfo item in lst) AddToCache(item);
}
public static AssignmentInfo GetExistingByPrimaryKey(int aid)
protected static AssignmentInfo GetCachedByPrimaryKey(int aid)
{
ConvertListToDictionary();
string key = aid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
@@ -220,24 +228,23 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Factory Methods
private static int _AssignmentInfoUnique = 0;
private int _MyAssignmentInfoUnique;
private static int AssignmentInfoUnique
{ get { return ++_AssignmentInfoUnique; } }
private int _MyAssignmentInfoUnique = AssignmentInfoUnique;
public int MyAssignmentInfoUnique
{
get { return _MyAssignmentInfoUnique; }
}
private AssignmentInfo()
{ get { return _MyAssignmentInfoUnique; } }
protected AssignmentInfo()
{/* require use of factory methods */
_MyAssignmentInfoUnique = ++_AssignmentInfoUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(AID.ToString())) return;
List<AssignmentInfo> listAssignmentInfo = _AllByPrimaryKey[AID.ToString()]; // Get the list of items
listAssignmentInfo.Remove(this); // Remove the item from the list
RemoveFromCache(this);
if (!_CacheByPrimaryKey.ContainsKey(AID.ToString())) return;
List<AssignmentInfo> listAssignmentInfo = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items
while (listAssignmentInfo.Contains(this)) listAssignmentInfo.Remove(this); // Remove the item from the list
if (listAssignmentInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(AID.ToString()); // remove the list
_CacheByPrimaryKey.Remove(AID.ToString()); // remove the list
}
public virtual Assignment Get()
{
@@ -247,29 +254,29 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.AID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Assignment tmp)
protected virtual void RefreshFields(Assignment tmp)
{
if (_GID != tmp.GID)
{
MyGroup.RefreshGroupAssignments(); // Update List for old value
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value
_GID = tmp.GID; // Update the value
}
_MyGroup = null; // Reset list so that the next line gets a new list
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value
if (_RID != tmp.RID)
{
MyRole.RefreshRoleAssignments(); // Update List for old value
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value
_RID = tmp.RID; // Update the value
}
_MyRole = null; // Reset list so that the next line gets a new list
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value
if (_FolderID != tmp.FolderID)
{
MyFolder.RefreshFolderAssignments(); // Update List for old value
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value
}
_MyFolder = null; // Reset list so that the next line gets a new list
@@ -288,22 +295,22 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.AID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(FolderAssignment tmp)
protected virtual void RefreshFields(FolderAssignment tmp)
{
if (_GID != tmp.GID)
{
MyGroup.RefreshGroupAssignments(); // Update List for old value
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value
_GID = tmp.GID; // Update the value
}
_MyGroup = null; // Reset list so that the next line gets a new list
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value
if (_RID != tmp.RID)
{
MyRole.RefreshRoleAssignments(); // Update List for old value
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value
_RID = tmp.RID; // Update the value
}
_MyRole = null; // Reset list so that the next line gets a new list
@@ -322,22 +329,22 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.AID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(GroupAssignment tmp)
protected virtual void RefreshFields(GroupAssignment tmp)
{
if (_RID != tmp.RID)
{
MyRole.RefreshRoleAssignments(); // Update List for old value
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value
_RID = tmp.RID; // Update the value
}
_MyRole = null; // Reset list so that the next line gets a new list
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value
if (_FolderID != tmp.FolderID)
{
MyFolder.RefreshFolderAssignments(); // Update List for old value
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value
}
_MyFolder = null; // Reset list so that the next line gets a new list
@@ -356,22 +363,22 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.AID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(RoleAssignment tmp)
protected virtual void RefreshFields(RoleAssignment tmp)
{
if (_GID != tmp.GID)
{
MyGroup.RefreshGroupAssignments(); // Update List for old value
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value
_GID = tmp.GID; // Update the value
}
_MyGroup = null; // Reset list so that the next line gets a new list
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value
if (_FolderID != tmp.FolderID)
{
MyFolder.RefreshFolderAssignments(); // Update List for old value
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value
}
_MyFolder = null; // Reset list so that the next line gets a new list
@@ -392,13 +399,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Assignment");
try
{
AssignmentInfo tmp = GetExistingByPrimaryKey(aid);
AssignmentInfo tmp = GetCachedByPrimaryKey(aid);
if (tmp == null)
{
tmp = DataPortal.Fetch<AssignmentInfo>(new PKCriteria(aid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up AssignmentInfo
tmp = null;
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
}
catch (Exception ex)
@@ -410,7 +421,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal AssignmentInfo(SafeDataReader dr)
{
_MyAssignmentInfoUnique = ++_AssignmentInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.Constructor", GetHashCode());
try
{