This commit is contained in:
@@ -53,28 +53,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Annotation> _AllList = new List<Annotation>();
|
||||
private static Dictionary<string, List<Annotation>> _AllByPrimaryKey = new Dictionary<string, List<Annotation>>();
|
||||
private static List<Annotation> _CacheList = new List<Annotation>();
|
||||
protected static void AddToCache(Annotation annotation)
|
||||
{
|
||||
if (!_CacheList.Contains(annotation)) _CacheList.Add(annotation); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Annotation annotation)
|
||||
{
|
||||
while (_CacheList.Contains(annotation)) _CacheList.Remove(annotation); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Annotation>> _CacheByPrimaryKey = new Dictionary<string, List<Annotation>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Annotation> remove = new List<Annotation>();
|
||||
foreach (Annotation tmp in _AllList)
|
||||
foreach (Annotation tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.AnnotationID.ToString()] = new List<Annotation>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.AnnotationID.ToString()] = new List<Annotation>(); // 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 (Annotation tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Annotation GetExistingByPrimaryKey(int annotationID)
|
||||
protected static Annotation 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
|
||||
@@ -442,24 +450,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _AnnotationUnique = 0;
|
||||
private int _MyAnnotationUnique;
|
||||
protected static int AnnotationUnique
|
||||
{ get { return ++_AnnotationUnique; } }
|
||||
private int _MyAnnotationUnique = AnnotationUnique;
|
||||
public int MyAnnotationUnique
|
||||
{
|
||||
get { return _MyAnnotationUnique; }
|
||||
}
|
||||
{ get { return _MyAnnotationUnique; } }
|
||||
protected Annotation()
|
||||
{/* require use of factory methods */
|
||||
_MyAnnotationUnique = ++_AnnotationUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(AnnotationID.ToString())) return;
|
||||
List<Annotation> listAnnotation = _AllByPrimaryKey[AnnotationID.ToString()]; // Get the list of items
|
||||
listAnnotation.Remove(this); // Remove the item from the list
|
||||
if (listAnnotation.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(AnnotationID.ToString()))
|
||||
{
|
||||
List<Annotation> listAnnotation = _CacheByPrimaryKey[AnnotationID.ToString()]; // Get the list of items
|
||||
while (listAnnotation.Contains(this)) listAnnotation.Remove(this); // Remove the item from the list
|
||||
if (listAnnotation.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Annotation New()
|
||||
{
|
||||
@@ -497,7 +510,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Annotation tmp = Annotation.New(myItem, myAnnotationType, rtfText, searchText, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Annotation tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -523,7 +540,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Annotation tmp = Annotation.New(myItem, myAnnotationType, rtfText, searchText, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Annotation tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -541,13 +562,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Annotation");
|
||||
try
|
||||
{
|
||||
Annotation tmp = GetExistingByPrimaryKey(annotationID);
|
||||
Annotation tmp = GetCachedByPrimaryKey(annotationID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Annotation>(new PKCriteria(annotationID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Annotation
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -589,7 +614,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Annotation annotation = base.Save();
|
||||
_AllList.Add(annotation);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(annotation);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return annotation;
|
||||
}
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -64,38 +64,46 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<AnnotationType> _AllList = new List<AnnotationType>();
|
||||
private static Dictionary<string, List<AnnotationType>> _AllByPrimaryKey = new Dictionary<string, List<AnnotationType>>();
|
||||
private static Dictionary<string, List<AnnotationType>> _AllByName = new Dictionary<string, List<AnnotationType>>();
|
||||
private static List<AnnotationType> _CacheList = new List<AnnotationType>();
|
||||
protected static void AddToCache(AnnotationType annotationType)
|
||||
{
|
||||
if (!_CacheList.Contains(annotationType)) _CacheList.Add(annotationType); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(AnnotationType annotationType)
|
||||
{
|
||||
while (_CacheList.Contains(annotationType)) _CacheList.Remove(annotationType); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<AnnotationType>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationType>>();
|
||||
private static Dictionary<string, List<AnnotationType>> _CacheByName = new Dictionary<string, List<AnnotationType>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<AnnotationType> remove = new List<AnnotationType>();
|
||||
foreach (AnnotationType tmp in _AllList)
|
||||
foreach (AnnotationType tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.TypeID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.TypeID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.TypeID.ToString()] = new List<AnnotationType>(); // Add new list for PrimaryKey
|
||||
_AllByName[tmp.Name.ToString()] = new List<AnnotationType>(); // Add new list for Name
|
||||
_CacheByPrimaryKey[tmp.TypeID.ToString()] = new List<AnnotationType>(); // Add new list for PrimaryKey
|
||||
_CacheByName[tmp.Name.ToString()] = new List<AnnotationType>(); // Add new list for Name
|
||||
}
|
||||
_AllByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_AllByName[tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||
_CacheByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (AnnotationType tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static AnnotationType GetExistingByPrimaryKey(int typeID)
|
||||
protected static AnnotationType GetCachedByPrimaryKey(int typeID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = typeID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
public static AnnotationType GetExistingByName(string name)
|
||||
protected static AnnotationType GetCachedByName(string name)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = name.ToString();
|
||||
if (_AllByName.ContainsKey(key)) return _AllByName[key][0];
|
||||
if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -394,28 +402,41 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _AnnotationTypeUnique = 0;
|
||||
private int _MyAnnotationTypeUnique;
|
||||
protected static int AnnotationTypeUnique
|
||||
{ get { return ++_AnnotationTypeUnique; } }
|
||||
private int _MyAnnotationTypeUnique = AnnotationTypeUnique;
|
||||
public int MyAnnotationTypeUnique
|
||||
{
|
||||
get { return _MyAnnotationTypeUnique; }
|
||||
}
|
||||
{ get { return _MyAnnotationTypeUnique; } }
|
||||
protected AnnotationType()
|
||||
{/* require use of factory methods */
|
||||
_MyAnnotationTypeUnique = ++_AnnotationTypeUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(TypeID.ToString())) return;
|
||||
List<AnnotationType> listAnnotationType = _AllByPrimaryKey[TypeID.ToString()]; // Get the list of items
|
||||
listAnnotationType.Remove(this); // Remove the item from the list
|
||||
if (listAnnotationType.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(TypeID.ToString()); // remove the list
|
||||
listAnnotationType = _AllByName[TypeID.ToString()]; // Get the list of items
|
||||
listAnnotationType.Remove(this); // Remove the item from the list
|
||||
if (listAnnotationType.Count == 0) //If there are no items left in the list
|
||||
_AllByName.Remove(TypeID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(TypeID.ToString()))
|
||||
{
|
||||
List<AnnotationType> listAnnotationType = _CacheByPrimaryKey[TypeID.ToString()]; // Get the list of items
|
||||
while (listAnnotationType.Contains(this)) listAnnotationType.Remove(this); // Remove the item from the list
|
||||
if (listAnnotationType.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list
|
||||
}
|
||||
string myKey;
|
||||
myKey = null;
|
||||
foreach (string key in _CacheByName.Keys)
|
||||
if (_CacheByName[key].Contains(this))
|
||||
myKey = key;
|
||||
if (myKey != null)
|
||||
{
|
||||
List<AnnotationType> listAnnotationType = _CacheByName[myKey]; // Get the list of items
|
||||
listAnnotationType.Remove(this); // Remove the item from the list
|
||||
if (listAnnotationType.Count == 0) //If there are no items left in the list
|
||||
_CacheByName.Remove(myKey); // remove the list
|
||||
}
|
||||
}
|
||||
public static AnnotationType New()
|
||||
{
|
||||
@@ -449,7 +470,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
AnnotationType tmp = AnnotationType.New(name, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
AnnotationType tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -472,7 +497,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
AnnotationType tmp = AnnotationType.New(name, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
AnnotationType tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -490,13 +519,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
|
||||
try
|
||||
{
|
||||
AnnotationType tmp = GetExistingByPrimaryKey(typeID);
|
||||
AnnotationType tmp = GetCachedByPrimaryKey(typeID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<AnnotationType>(new PKCriteria(typeID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up AnnotationType
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -504,19 +537,23 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on AnnotationType.Get", ex);
|
||||
}
|
||||
}
|
||||
private static AnnotationType GetByName(string name)
|
||||
public static AnnotationType GetByName(string name)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
|
||||
try
|
||||
{
|
||||
AnnotationType tmp = GetExistingByName(name);
|
||||
AnnotationType tmp = GetCachedByName(name);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<AnnotationType>(new NameCriteria(name));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up AnnotationType
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -558,7 +595,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
AnnotationType annotationType = base.Save();
|
||||
_AllList.Add(annotationType);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(annotationType);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return annotationType;
|
||||
}
|
||||
|
@@ -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<AnnotationTypeInfo> _AllList = new List<AnnotationTypeInfo>();
|
||||
private static Dictionary<string, List<AnnotationTypeInfo>> _AllByPrimaryKey = new Dictionary<string, List<AnnotationTypeInfo>>();
|
||||
private static List<AnnotationTypeInfo> _CacheList = new List<AnnotationTypeInfo>();
|
||||
protected static void AddToCache(AnnotationTypeInfo annotationTypeInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(annotationTypeInfo)) _CacheList.Add(annotationTypeInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(AnnotationTypeInfo annotationTypeInfo)
|
||||
{
|
||||
while (_CacheList.Contains(annotationTypeInfo)) _CacheList.Remove(annotationTypeInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<AnnotationTypeInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationTypeInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<AnnotationTypeInfo> remove = new List<AnnotationTypeInfo>();
|
||||
foreach (AnnotationTypeInfo tmp in _AllList)
|
||||
foreach (AnnotationTypeInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.TypeID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.TypeID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.TypeID.ToString()] = new List<AnnotationTypeInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.TypeID.ToString()] = new List<AnnotationTypeInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (AnnotationTypeInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(AnnotationTypeInfoList lst)
|
||||
{
|
||||
foreach (AnnotationTypeInfo item in lst) _AllList.Add(item);
|
||||
foreach (AnnotationTypeInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static AnnotationTypeInfo GetExistingByPrimaryKey(int typeID)
|
||||
protected static AnnotationTypeInfo GetCachedByPrimaryKey(int typeID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = typeID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -161,11 +169,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _AnnotationTypeAnnotations;
|
||||
}
|
||||
}
|
||||
internal void RefreshAnnotationTypeAnnotations()
|
||||
public void RefreshAnnotationTypeAnnotations()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_TypeID.ToString()))
|
||||
foreach (AnnotationTypeInfo tmp in _AllByPrimaryKey[_TypeID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_TypeID.ToString()))
|
||||
foreach (AnnotationTypeInfo tmp in _CacheByPrimaryKey[_TypeID.ToString()])
|
||||
tmp._AnnotationTypeAnnotationCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base AnnotationTypeInfo.ToString function as necessary
|
||||
@@ -189,24 +197,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _AnnotationTypeInfoUnique = 0;
|
||||
private int _MyAnnotationTypeInfoUnique;
|
||||
private static int AnnotationTypeInfoUnique
|
||||
{ get { return ++_AnnotationTypeInfoUnique; } }
|
||||
private int _MyAnnotationTypeInfoUnique = AnnotationTypeInfoUnique;
|
||||
public int MyAnnotationTypeInfoUnique
|
||||
{
|
||||
get { return _MyAnnotationTypeInfoUnique; }
|
||||
}
|
||||
private AnnotationTypeInfo()
|
||||
{ get { return _MyAnnotationTypeInfoUnique; } }
|
||||
protected AnnotationTypeInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyAnnotationTypeInfoUnique = ++_AnnotationTypeInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(TypeID.ToString())) return;
|
||||
List<AnnotationTypeInfo> listAnnotationTypeInfo = _AllByPrimaryKey[TypeID.ToString()]; // Get the list of items
|
||||
listAnnotationTypeInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(TypeID.ToString())) return;
|
||||
List<AnnotationTypeInfo> listAnnotationTypeInfo = _CacheByPrimaryKey[TypeID.ToString()]; // Get the list of items
|
||||
while (listAnnotationTypeInfo.Contains(this)) listAnnotationTypeInfo.Remove(this); // Remove the item from the list
|
||||
if (listAnnotationTypeInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(TypeID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list
|
||||
}
|
||||
public virtual AnnotationType Get()
|
||||
{
|
||||
@@ -216,11 +223,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.TypeID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationTypeInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AnnotationTypeInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(AnnotationType tmp)
|
||||
protected virtual void RefreshFields(AnnotationType tmp)
|
||||
{
|
||||
_Name = tmp.Name;
|
||||
_Config = tmp.Config;
|
||||
@@ -235,13 +242,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
|
||||
try
|
||||
{
|
||||
AnnotationTypeInfo tmp = GetExistingByPrimaryKey(typeID);
|
||||
AnnotationTypeInfo tmp = GetCachedByPrimaryKey(typeID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<AnnotationTypeInfo>(new PKCriteria(typeID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up AnnotationTypeInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -253,7 +264,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal AnnotationTypeInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyAnnotationTypeInfoUnique = ++_AnnotationTypeInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
@@ -54,28 +54,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Assignment> _AllList = new List<Assignment>();
|
||||
private static Dictionary<string, List<Assignment>> _AllByPrimaryKey = new Dictionary<string, List<Assignment>>();
|
||||
private static List<Assignment> _CacheList = new List<Assignment>();
|
||||
protected static void AddToCache(Assignment assignment)
|
||||
{
|
||||
if (!_CacheList.Contains(assignment)) _CacheList.Add(assignment); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Assignment assignment)
|
||||
{
|
||||
while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Assignment>> _CacheByPrimaryKey = new Dictionary<string, List<Assignment>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Assignment> remove = new List<Assignment>();
|
||||
foreach (Assignment tmp in _AllList)
|
||||
foreach (Assignment tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.AID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.AID.ToString()] = new List<Assignment>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.AID.ToString()] = new List<Assignment>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (Assignment tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Assignment GetExistingByPrimaryKey(int aid)
|
||||
protected static Assignment GetCachedByPrimaryKey(int aid)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = aid.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -504,24 +512,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _AssignmentUnique = 0;
|
||||
private int _MyAssignmentUnique;
|
||||
protected static int AssignmentUnique
|
||||
{ get { return ++_AssignmentUnique; } }
|
||||
private int _MyAssignmentUnique = AssignmentUnique;
|
||||
public int MyAssignmentUnique
|
||||
{
|
||||
get { return _MyAssignmentUnique; }
|
||||
}
|
||||
{ get { return _MyAssignmentUnique; } }
|
||||
protected Assignment()
|
||||
{/* require use of factory methods */
|
||||
_MyAssignmentUnique = ++_AssignmentUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(AID.ToString())) return;
|
||||
List<Assignment> listAssignment = _AllByPrimaryKey[AID.ToString()]; // Get the list of items
|
||||
listAssignment.Remove(this); // Remove the item from the list
|
||||
if (listAssignment.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(AID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(AID.ToString()))
|
||||
{
|
||||
List<Assignment> listAssignment = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items
|
||||
while (listAssignment.Contains(this)) listAssignment.Remove(this); // Remove the item from the list
|
||||
if (listAssignment.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(AID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Assignment New()
|
||||
{
|
||||
@@ -560,7 +573,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Assignment tmp = Assignment.New(myGroup, myRole, myFolder, startDate, endDate, dts, usrID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Assignment tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -585,7 +602,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Assignment tmp = Assignment.New(myGroup, myRole, myFolder, endDate);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Assignment tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -603,13 +624,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Assignment");
|
||||
try
|
||||
{
|
||||
Assignment tmp = GetExistingByPrimaryKey(aid);
|
||||
Assignment tmp = GetCachedByPrimaryKey(aid);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Assignment>(new PKCriteria(aid));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Assignment
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -651,7 +676,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Assignment assignment = base.Save();
|
||||
_AllList.Add(assignment);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(assignment);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return assignment;
|
||||
}
|
||||
|
@@ -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<AssignmentInfo> _AllList = new List<AssignmentInfo>();
|
||||
private static Dictionary<string, List<AssignmentInfo>> _AllByPrimaryKey = new Dictionary<string, List<AssignmentInfo>>();
|
||||
private static List<AssignmentInfo> _CacheList = new List<AssignmentInfo>();
|
||||
protected static void AddToCache(AssignmentInfo assignmentInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(assignmentInfo)) _CacheList.Add(assignmentInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(AssignmentInfo assignmentInfo)
|
||||
{
|
||||
while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<AssignmentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AssignmentInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<AssignmentInfo> remove = new List<AssignmentInfo>();
|
||||
foreach (AssignmentInfo tmp in _AllList)
|
||||
foreach (AssignmentInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.AID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.AID.ToString()] = new List<AssignmentInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.AID.ToString()] = new List<AssignmentInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (AssignmentInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(AssignmentInfoList lst)
|
||||
{
|
||||
foreach (AssignmentInfo item in lst) _AllList.Add(item);
|
||||
foreach (AssignmentInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static AssignmentInfo GetExistingByPrimaryKey(int aid)
|
||||
protected static AssignmentInfo GetCachedByPrimaryKey(int aid)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = aid.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -220,24 +228,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _AssignmentInfoUnique = 0;
|
||||
private int _MyAssignmentInfoUnique;
|
||||
private static int AssignmentInfoUnique
|
||||
{ get { return ++_AssignmentInfoUnique; } }
|
||||
private int _MyAssignmentInfoUnique = AssignmentInfoUnique;
|
||||
public int MyAssignmentInfoUnique
|
||||
{
|
||||
get { return _MyAssignmentInfoUnique; }
|
||||
}
|
||||
private AssignmentInfo()
|
||||
{ get { return _MyAssignmentInfoUnique; } }
|
||||
protected AssignmentInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyAssignmentInfoUnique = ++_AssignmentInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(AID.ToString())) return;
|
||||
List<AssignmentInfo> listAssignmentInfo = _AllByPrimaryKey[AID.ToString()]; // Get the list of items
|
||||
listAssignmentInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(AID.ToString())) return;
|
||||
List<AssignmentInfo> listAssignmentInfo = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items
|
||||
while (listAssignmentInfo.Contains(this)) listAssignmentInfo.Remove(this); // Remove the item from the list
|
||||
if (listAssignmentInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(AID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(AID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Assignment Get()
|
||||
{
|
||||
@@ -247,29 +254,29 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Assignment tmp)
|
||||
protected virtual void RefreshFields(Assignment tmp)
|
||||
{
|
||||
if (_GID != tmp.GID)
|
||||
{
|
||||
MyGroup.RefreshGroupAssignments(); // Update List for old value
|
||||
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value
|
||||
_GID = tmp.GID; // Update the value
|
||||
}
|
||||
_MyGroup = null; // Reset list so that the next line gets a new list
|
||||
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value
|
||||
if (_RID != tmp.RID)
|
||||
{
|
||||
MyRole.RefreshRoleAssignments(); // Update List for old value
|
||||
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value
|
||||
_RID = tmp.RID; // Update the value
|
||||
}
|
||||
_MyRole = null; // Reset list so that the next line gets a new list
|
||||
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value
|
||||
if (_FolderID != tmp.FolderID)
|
||||
{
|
||||
MyFolder.RefreshFolderAssignments(); // Update List for old value
|
||||
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value
|
||||
_FolderID = tmp.FolderID; // Update the value
|
||||
}
|
||||
_MyFolder = null; // Reset list so that the next line gets a new list
|
||||
@@ -288,22 +295,22 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(FolderAssignment tmp)
|
||||
protected virtual void RefreshFields(FolderAssignment tmp)
|
||||
{
|
||||
if (_GID != tmp.GID)
|
||||
{
|
||||
MyGroup.RefreshGroupAssignments(); // Update List for old value
|
||||
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value
|
||||
_GID = tmp.GID; // Update the value
|
||||
}
|
||||
_MyGroup = null; // Reset list so that the next line gets a new list
|
||||
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value
|
||||
if (_RID != tmp.RID)
|
||||
{
|
||||
MyRole.RefreshRoleAssignments(); // Update List for old value
|
||||
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value
|
||||
_RID = tmp.RID; // Update the value
|
||||
}
|
||||
_MyRole = null; // Reset list so that the next line gets a new list
|
||||
@@ -322,22 +329,22 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(GroupAssignment tmp)
|
||||
protected virtual void RefreshFields(GroupAssignment tmp)
|
||||
{
|
||||
if (_RID != tmp.RID)
|
||||
{
|
||||
MyRole.RefreshRoleAssignments(); // Update List for old value
|
||||
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value
|
||||
_RID = tmp.RID; // Update the value
|
||||
}
|
||||
_MyRole = null; // Reset list so that the next line gets a new list
|
||||
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value
|
||||
if (_FolderID != tmp.FolderID)
|
||||
{
|
||||
MyFolder.RefreshFolderAssignments(); // Update List for old value
|
||||
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value
|
||||
_FolderID = tmp.FolderID; // Update the value
|
||||
}
|
||||
_MyFolder = null; // Reset list so that the next line gets a new list
|
||||
@@ -356,22 +363,22 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.AID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(RoleAssignment tmp)
|
||||
protected virtual void RefreshFields(RoleAssignment tmp)
|
||||
{
|
||||
if (_GID != tmp.GID)
|
||||
{
|
||||
MyGroup.RefreshGroupAssignments(); // Update List for old value
|
||||
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value
|
||||
_GID = tmp.GID; // Update the value
|
||||
}
|
||||
_MyGroup = null; // Reset list so that the next line gets a new list
|
||||
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value
|
||||
if (_FolderID != tmp.FolderID)
|
||||
{
|
||||
MyFolder.RefreshFolderAssignments(); // Update List for old value
|
||||
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value
|
||||
_FolderID = tmp.FolderID; // Update the value
|
||||
}
|
||||
_MyFolder = null; // Reset list so that the next line gets a new list
|
||||
@@ -392,13 +399,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Assignment");
|
||||
try
|
||||
{
|
||||
AssignmentInfo tmp = GetExistingByPrimaryKey(aid);
|
||||
AssignmentInfo tmp = GetCachedByPrimaryKey(aid);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<AssignmentInfo>(new PKCriteria(aid));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up AssignmentInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -410,7 +421,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal AssignmentInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyAssignmentInfoUnique = ++_AssignmentInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user