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<PermissionInfo> _AllList = new List<PermissionInfo>();
|
||||
private static Dictionary<string, List<PermissionInfo>> _AllByPrimaryKey = new Dictionary<string, List<PermissionInfo>>();
|
||||
private static List<PermissionInfo> _CacheList = new List<PermissionInfo>();
|
||||
protected static void AddToCache(PermissionInfo permissionInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(PermissionInfo permissionInfo)
|
||||
{
|
||||
while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<PermissionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PermissionInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<PermissionInfo> remove = new List<PermissionInfo>();
|
||||
foreach (PermissionInfo tmp in _AllList)
|
||||
foreach (PermissionInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.PID.ToString()] = new List<PermissionInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.PID.ToString()] = new List<PermissionInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (PermissionInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(PermissionInfoList lst)
|
||||
{
|
||||
foreach (PermissionInfo item in lst) _AllList.Add(item);
|
||||
foreach (PermissionInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static PermissionInfo GetExistingByPrimaryKey(int pid)
|
||||
protected static PermissionInfo GetCachedByPrimaryKey(int pid)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = pid.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -238,24 +246,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _PermissionInfoUnique = 0;
|
||||
private int _MyPermissionInfoUnique;
|
||||
private static int PermissionInfoUnique
|
||||
{ get { return ++_PermissionInfoUnique; } }
|
||||
private int _MyPermissionInfoUnique = PermissionInfoUnique;
|
||||
public int MyPermissionInfoUnique
|
||||
{
|
||||
get { return _MyPermissionInfoUnique; }
|
||||
}
|
||||
private PermissionInfo()
|
||||
{ get { return _MyPermissionInfoUnique; } }
|
||||
protected PermissionInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyPermissionInfoUnique = ++_PermissionInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return;
|
||||
List<PermissionInfo> listPermissionInfo = _AllByPrimaryKey[PID.ToString()]; // Get the list of items
|
||||
listPermissionInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return;
|
||||
List<PermissionInfo> listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items
|
||||
while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list
|
||||
if (listPermissionInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(PID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(PID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Permission Get()
|
||||
{
|
||||
@@ -265,15 +272,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.PID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Permission tmp)
|
||||
protected virtual void RefreshFields(Permission tmp)
|
||||
{
|
||||
if (_RID != tmp.RID)
|
||||
{
|
||||
MyRole.RefreshRolePermissions(); // Update List for old value
|
||||
if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value
|
||||
_RID = tmp.RID; // Update the value
|
||||
}
|
||||
_MyRole = null; // Reset list so that the next line gets a new list
|
||||
@@ -295,11 +302,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.PID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(RolePermission tmp)
|
||||
protected virtual void RefreshFields(RolePermission tmp)
|
||||
{
|
||||
_PermLevel = tmp.PermLevel;
|
||||
_VersionType = tmp.VersionType;
|
||||
@@ -320,13 +327,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Permission");
|
||||
try
|
||||
{
|
||||
PermissionInfo tmp = GetExistingByPrimaryKey(pid);
|
||||
PermissionInfo tmp = GetCachedByPrimaryKey(pid);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<PermissionInfo>(new PKCriteria(pid));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up PermissionInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -338,7 +349,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal PermissionInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyPermissionInfoUnique = ++_PermissionInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user