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<DetailInfo> _AllList = new List<DetailInfo>();
|
||||
private static Dictionary<string, List<DetailInfo>> _AllByPrimaryKey = new Dictionary<string, List<DetailInfo>>();
|
||||
private static List<DetailInfo> _CacheList = new List<DetailInfo>();
|
||||
protected static void AddToCache(DetailInfo detailInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(detailInfo)) _CacheList.Add(detailInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(DetailInfo detailInfo)
|
||||
{
|
||||
while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<DetailInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DetailInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<DetailInfo> remove = new List<DetailInfo>();
|
||||
foreach (DetailInfo tmp in _AllList)
|
||||
foreach (DetailInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()] = new List<DetailInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()] = new List<DetailInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (DetailInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(DetailInfoList lst)
|
||||
{
|
||||
foreach (DetailInfo item in lst) _AllList.Add(item);
|
||||
foreach (DetailInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static DetailInfo GetExistingByPrimaryKey(int detailID)
|
||||
protected static DetailInfo GetCachedByPrimaryKey(int detailID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = detailID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -186,24 +194,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _DetailInfoUnique = 0;
|
||||
private int _MyDetailInfoUnique;
|
||||
private static int DetailInfoUnique
|
||||
{ get { return ++_DetailInfoUnique; } }
|
||||
private int _MyDetailInfoUnique = DetailInfoUnique;
|
||||
public int MyDetailInfoUnique
|
||||
{
|
||||
get { return _MyDetailInfoUnique; }
|
||||
}
|
||||
private DetailInfo()
|
||||
{ get { return _MyDetailInfoUnique; } }
|
||||
protected DetailInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyDetailInfoUnique = ++_DetailInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(DetailID.ToString())) return;
|
||||
List<DetailInfo> listDetailInfo = _AllByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
listDetailInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) return;
|
||||
List<DetailInfo> listDetailInfo = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
while (listDetailInfo.Contains(this)) listDetailInfo.Remove(this); // Remove the item from the list
|
||||
if (listDetailInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Detail Get()
|
||||
{
|
||||
@@ -213,15 +220,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.DetailID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Detail tmp)
|
||||
protected virtual void RefreshFields(Detail tmp)
|
||||
{
|
||||
if (_ContentID != tmp.ContentID)
|
||||
{
|
||||
MyContent.RefreshContentDetails(); // Update List for old value
|
||||
if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for old value
|
||||
_ContentID = tmp.ContentID; // Update the value
|
||||
}
|
||||
_MyContent = null; // Reset list so that the next line gets a new list
|
||||
@@ -239,11 +246,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.DetailID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ContentDetail tmp)
|
||||
protected virtual void RefreshFields(ContentDetail tmp)
|
||||
{
|
||||
_ItemType = tmp.ItemType;
|
||||
_Text = tmp.Text;
|
||||
@@ -260,13 +267,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Detail");
|
||||
try
|
||||
{
|
||||
DetailInfo tmp = GetExistingByPrimaryKey(detailID);
|
||||
DetailInfo tmp = GetCachedByPrimaryKey(detailID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<DetailInfo>(new PKCriteria(detailID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up DetailInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -278,7 +289,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal DetailInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyDetailInfoUnique = ++_DetailInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user