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,28 +36,36 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
protected static List<ZContentInfo> _AllList = new List<ZContentInfo>();
private static Dictionary<string, List<ZContentInfo>> _AllByPrimaryKey = new Dictionary<string, List<ZContentInfo>>();
private static List<ZContentInfo> _CacheList = new List<ZContentInfo>();
protected static void AddToCache(ZContentInfo zContentInfo)
{
if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache
}
protected static void RemoveFromCache(ZContentInfo zContentInfo)
{
while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache
}
private static Dictionary<string, List<ZContentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ZContentInfo>>();
private static void ConvertListToDictionary()
{
List<ZContentInfo> remove = new List<ZContentInfo>();
foreach (ZContentInfo tmp in _AllList)
foreach (ZContentInfo tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
{
_AllByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContentInfo>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContentInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list
_CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (ZContentInfo tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
public static ZContentInfo GetExistingByPrimaryKey(int contentID)
protected static ZContentInfo GetCachedByPrimaryKey(int contentID)
{
ConvertListToDictionary();
string key = contentID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
@@ -133,24 +141,23 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Factory Methods
private static int _ZContentInfoUnique = 0;
private int _MyZContentInfoUnique;
private static int ZContentInfoUnique
{ get { return ++_ZContentInfoUnique; } }
private int _MyZContentInfoUnique = ZContentInfoUnique;
public int MyZContentInfoUnique
{
get { return _MyZContentInfoUnique; }
}
private ZContentInfo()
{ get { return _MyZContentInfoUnique; } }
protected ZContentInfo()
{/* require use of factory methods */
_MyZContentInfoUnique = ++_ZContentInfoUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return;
List<ZContentInfo> listZContentInfo = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items
listZContentInfo.Remove(this); // Remove the item from the list
RemoveFromCache(this);
if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return;
List<ZContentInfo> listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items
while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list
if (listZContentInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
public virtual ZContent Get()
{
@@ -160,11 +167,11 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.ContentID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (ZContentInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ZContent tmp)
protected virtual void RefreshFields(ZContent tmp)
{
_OldStepSequence = tmp.OldStepSequence;
_ZContentInfoExtension.Refresh(this);
@@ -177,15 +184,16 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a ZContent");
try
{
ZContentInfo tmp = GetExistingByPrimaryKey(contentID);
ZContentInfo tmp = GetCachedByPrimaryKey(contentID);
if (tmp == null)
{
tmp = DataPortal.Fetch<ZContentInfo>(new PKCriteria(contentID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp._ContentID = contentID;
tmp.Dispose(); // Clean-up ZContentInfo
tmp = null;
}
return tmp;
}
@@ -198,7 +206,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal ZContentInfo(SafeDataReader dr)
{
_MyZContentInfoUnique = ++_ZContentInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode());
try
{