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<AnnotationInfo> _AllList = new List<AnnotationInfo>();
|
||||
private static Dictionary<string, List<AnnotationInfo>> _AllByPrimaryKey = new Dictionary<string, List<AnnotationInfo>>();
|
||||
private static List<AnnotationInfo> _CacheList = new List<AnnotationInfo>();
|
||||
protected static void AddToCache(AnnotationInfo annotationInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(annotationInfo)) _CacheList.Add(annotationInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(AnnotationInfo annotationInfo)
|
||||
{
|
||||
while (_CacheList.Contains(annotationInfo)) _CacheList.Remove(annotationInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<AnnotationInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<AnnotationInfo> remove = new List<AnnotationInfo>();
|
||||
foreach (AnnotationInfo tmp in _AllList)
|
||||
foreach (AnnotationInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.AnnotationID.ToString()] = new List<AnnotationInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.AnnotationID.ToString()] = new List<AnnotationInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (AnnotationInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(AnnotationInfoList lst)
|
||||
{
|
||||
foreach (AnnotationInfo item in lst) _AllList.Add(item);
|
||||
foreach (AnnotationInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static AnnotationInfo GetExistingByPrimaryKey(int annotationID)
|
||||
protected static AnnotationInfo GetCachedByPrimaryKey(int annotationID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = annotationID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -208,24 +216,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _AnnotationInfoUnique = 0;
|
||||
private int _MyAnnotationInfoUnique;
|
||||
private static int AnnotationInfoUnique
|
||||
{ get { return ++_AnnotationInfoUnique; } }
|
||||
private int _MyAnnotationInfoUnique = AnnotationInfoUnique;
|
||||
public int MyAnnotationInfoUnique
|
||||
{
|
||||
get { return _MyAnnotationInfoUnique; }
|
||||
}
|
||||
private AnnotationInfo()
|
||||
{ get { return _MyAnnotationInfoUnique; } }
|
||||
protected AnnotationInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyAnnotationInfoUnique = ++_AnnotationInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(AnnotationID.ToString())) return;
|
||||
List<AnnotationInfo> listAnnotationInfo = _AllByPrimaryKey[AnnotationID.ToString()]; // Get the list of items
|
||||
listAnnotationInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(AnnotationID.ToString())) return;
|
||||
List<AnnotationInfo> listAnnotationInfo = _CacheByPrimaryKey[AnnotationID.ToString()]; // Get the list of items
|
||||
while (listAnnotationInfo.Contains(this)) listAnnotationInfo.Remove(this); // Remove the item from the list
|
||||
if (listAnnotationInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Annotation Get()
|
||||
{
|
||||
@@ -235,22 +242,22 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AnnotationID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Annotation tmp)
|
||||
protected virtual void RefreshFields(Annotation tmp)
|
||||
{
|
||||
if (_ItemID != tmp.ItemID)
|
||||
{
|
||||
MyItem.RefreshItemAnnotations(); // Update List for old value
|
||||
if (MyItem != null) MyItem.RefreshItemAnnotations(); // Update List for old value
|
||||
_ItemID = tmp.ItemID; // Update the value
|
||||
}
|
||||
_MyItem = null; // Reset list so that the next line gets a new list
|
||||
if (MyItem != null) MyItem.RefreshItemAnnotations(); // Update List for new value
|
||||
if (_TypeID != tmp.TypeID)
|
||||
{
|
||||
MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value
|
||||
if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value
|
||||
_TypeID = tmp.TypeID; // Update the value
|
||||
}
|
||||
_MyAnnotationType = null; // Reset list so that the next line gets a new list
|
||||
@@ -269,15 +276,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AnnotationID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(AnnotationTypeAnnotation tmp)
|
||||
protected virtual void RefreshFields(AnnotationTypeAnnotation tmp)
|
||||
{
|
||||
if (_ItemID != tmp.ItemID)
|
||||
{
|
||||
MyItem.RefreshItemAnnotations(); // Update List for old value
|
||||
if (MyItem != null) MyItem.RefreshItemAnnotations(); // Update List for old value
|
||||
_ItemID = tmp.ItemID; // Update the value
|
||||
}
|
||||
_MyItem = null; // Reset list so that the next line gets a new list
|
||||
@@ -296,15 +303,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AnnotationID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ItemAnnotation tmp)
|
||||
protected virtual void RefreshFields(ItemAnnotation tmp)
|
||||
{
|
||||
if (_TypeID != tmp.TypeID)
|
||||
{
|
||||
MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value
|
||||
if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value
|
||||
_TypeID = tmp.TypeID; // Update the value
|
||||
}
|
||||
_MyAnnotationType = null; // Reset list so that the next line gets a new list
|
||||
@@ -325,13 +332,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Annotation");
|
||||
try
|
||||
{
|
||||
AnnotationInfo tmp = GetExistingByPrimaryKey(annotationID);
|
||||
AnnotationInfo tmp = GetCachedByPrimaryKey(annotationID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<AnnotationInfo>(new PKCriteria(annotationID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up AnnotationInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -343,7 +354,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal AnnotationInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyAnnotationInfoUnique = ++_AnnotationInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user