This commit is contained in:
2008-08-12 11:42:50 +00:00
parent dfafac5a3a
commit d81b4d8af0
19 changed files with 941 additions and 569 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<RoUsageInfo> _AllList = new List<RoUsageInfo>();
private static Dictionary<string, List<RoUsageInfo>> _AllByPrimaryKey = new Dictionary<string, List<RoUsageInfo>>();
private static List<RoUsageInfo> _CacheList = new List<RoUsageInfo>();
protected static void AddToCache(RoUsageInfo roUsageInfo)
{
if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache
}
protected static void RemoveFromCache(RoUsageInfo roUsageInfo)
{
while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache
}
private static Dictionary<string, List<RoUsageInfo>> _CacheByPrimaryKey = new Dictionary<string, List<RoUsageInfo>>();
private static void ConvertListToDictionary()
{
List<RoUsageInfo> remove = new List<RoUsageInfo>();
foreach (RoUsageInfo tmp in _AllList)
foreach (RoUsageInfo tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString()))
{
_AllByPrimaryKey[tmp.ROUsageID.ToString()] = new List<RoUsageInfo>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List<RoUsageInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list
_CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (RoUsageInfo tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
internal static void AddList(RoUsageInfoList lst)
{
foreach (RoUsageInfo item in lst) _AllList.Add(item);
foreach (RoUsageInfo item in lst) AddToCache(item);
}
public static RoUsageInfo GetExistingByPrimaryKey(int rOUsageID)
protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID)
{
ConvertListToDictionary();
string key = rOUsageID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
@@ -176,24 +184,23 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Factory Methods
private static int _RoUsageInfoUnique = 0;
private int _MyRoUsageInfoUnique;
private static int RoUsageInfoUnique
{ get { return ++_RoUsageInfoUnique; } }
private int _MyRoUsageInfoUnique = RoUsageInfoUnique;
public int MyRoUsageInfoUnique
{
get { return _MyRoUsageInfoUnique; }
}
private RoUsageInfo()
{ get { return _MyRoUsageInfoUnique; } }
protected RoUsageInfo()
{/* require use of factory methods */
_MyRoUsageInfoUnique = ++_RoUsageInfoUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(ROUsageID.ToString())) return;
List<RoUsageInfo> listRoUsageInfo = _AllByPrimaryKey[ROUsageID.ToString()]; // Get the list of items
listRoUsageInfo.Remove(this); // Remove the item from the list
RemoveFromCache(this);
if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return;
List<RoUsageInfo> listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items
while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list
if (listRoUsageInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list
_CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list
}
public virtual RoUsage Get()
{
@@ -203,15 +210,15 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.ROUsageID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (RoUsageInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(RoUsage tmp)
protected virtual void RefreshFields(RoUsage tmp)
{
if (_ContentID != tmp.ContentID)
{
MyContent.RefreshContentRoUsages(); // Update List for old value
if (MyContent != null) MyContent.RefreshContentRoUsages(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value
}
_MyContent = null; // Reset list so that the next line gets a new list
@@ -228,11 +235,11 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.ROUsageID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (RoUsageInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ContentRoUsage tmp)
protected virtual void RefreshFields(ContentRoUsage tmp)
{
_ROID = tmp.ROID;
_Config = tmp.Config;
@@ -248,13 +255,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a RoUsage");
try
{
RoUsageInfo tmp = GetExistingByPrimaryKey(rOUsageID);
RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID);
if (tmp == null)
{
tmp = DataPortal.Fetch<RoUsageInfo>(new PKCriteria(rOUsageID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up RoUsageInfo
tmp = null;
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
}
catch (Exception ex)
@@ -266,7 +277,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal RoUsageInfo(SafeDataReader dr)
{
_MyRoUsageInfoUnique = ++_RoUsageInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode());
try
{