This commit is contained in:
@@ -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<RoleInfo> _AllList = new List<RoleInfo>();
|
||||
private static Dictionary<string, List<RoleInfo>> _AllByPrimaryKey = new Dictionary<string, List<RoleInfo>>();
|
||||
private static List<RoleInfo> _CacheList = new List<RoleInfo>();
|
||||
protected static void AddToCache(RoleInfo roleInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(RoleInfo roleInfo)
|
||||
{
|
||||
while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<RoleInfo>> _CacheByPrimaryKey = new Dictionary<string, List<RoleInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<RoleInfo> remove = new List<RoleInfo>();
|
||||
foreach (RoleInfo tmp in _AllList)
|
||||
foreach (RoleInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.RID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.RID.ToString()] = new List<RoleInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.RID.ToString()] = new List<RoleInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (RoleInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(RoleInfoList lst)
|
||||
{
|
||||
foreach (RoleInfo item in lst) _AllList.Add(item);
|
||||
foreach (RoleInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static RoleInfo GetExistingByPrimaryKey(int rid)
|
||||
protected static RoleInfo GetCachedByPrimaryKey(int rid)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = rid.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -161,11 +169,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _RoleAssignments;
|
||||
}
|
||||
}
|
||||
internal void RefreshRoleAssignments()
|
||||
public void RefreshRoleAssignments()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_RID.ToString()))
|
||||
foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_RID.ToString()))
|
||||
foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()])
|
||||
tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _RolePermissionCount = 0;
|
||||
@@ -196,11 +204,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _RolePermissions;
|
||||
}
|
||||
}
|
||||
internal void RefreshRolePermissions()
|
||||
public void RefreshRolePermissions()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_RID.ToString()))
|
||||
foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_RID.ToString()))
|
||||
foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()])
|
||||
tmp._RolePermissionCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base RoleInfo.ToString function as necessary
|
||||
@@ -224,24 +232,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _RoleInfoUnique = 0;
|
||||
private int _MyRoleInfoUnique;
|
||||
private static int RoleInfoUnique
|
||||
{ get { return ++_RoleInfoUnique; } }
|
||||
private int _MyRoleInfoUnique = RoleInfoUnique;
|
||||
public int MyRoleInfoUnique
|
||||
{
|
||||
get { return _MyRoleInfoUnique; }
|
||||
}
|
||||
private RoleInfo()
|
||||
{ get { return _MyRoleInfoUnique; } }
|
||||
protected RoleInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyRoleInfoUnique = ++_RoleInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(RID.ToString())) return;
|
||||
List<RoleInfo> listRoleInfo = _AllByPrimaryKey[RID.ToString()]; // Get the list of items
|
||||
listRoleInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return;
|
||||
List<RoleInfo> listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items
|
||||
while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list
|
||||
if (listRoleInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(RID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(RID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Role Get()
|
||||
{
|
||||
@@ -251,11 +258,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.RID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (RoleInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Role tmp)
|
||||
protected virtual void RefreshFields(Role tmp)
|
||||
{
|
||||
_Name = tmp.Name;
|
||||
_Title = tmp.Title;
|
||||
@@ -270,13 +277,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Role");
|
||||
try
|
||||
{
|
||||
RoleInfo tmp = GetExistingByPrimaryKey(rid);
|
||||
RoleInfo tmp = GetCachedByPrimaryKey(rid);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<RoleInfo>(new PKCriteria(rid));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up RoleInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -288,7 +299,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal RoleInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyRoleInfoUnique = ++_RoleInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user