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

@@ -51,28 +51,36 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
protected static List<ZTransition> _AllList = new List<ZTransition>();
private static Dictionary<string, List<ZTransition>> _AllByPrimaryKey = new Dictionary<string, List<ZTransition>>();
private static List<ZTransition> _CacheList = new List<ZTransition>();
protected static void AddToCache(ZTransition zTransition)
{
if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache
}
protected static void RemoveFromCache(ZTransition zTransition)
{
while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache
}
private static Dictionary<string, List<ZTransition>> _CacheByPrimaryKey = new Dictionary<string, List<ZTransition>>();
private static void ConvertListToDictionary()
{
List<ZTransition> remove = new List<ZTransition>();
foreach (ZTransition tmp in _AllList)
foreach (ZTransition tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransition>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransition>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
_CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (ZTransition tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
public static ZTransition GetExistingByPrimaryKey(int transitionID)
protected static ZTransition GetCachedByPrimaryKey(int transitionID)
{
ConvertListToDictionary();
string key = transitionID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
@@ -254,24 +262,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _ZTransitionUnique = 0;
private int _MyZTransitionUnique;
protected static int ZTransitionUnique
{ get { return ++_ZTransitionUnique; } }
private int _MyZTransitionUnique = ZTransitionUnique;
public int MyZTransitionUnique
{
get { return _MyZTransitionUnique; }
}
{ get { return _MyZTransitionUnique; } }
protected ZTransition()
{/* require use of factory methods */
_MyZTransitionUnique = ++_ZTransitionUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
List<ZTransition> listZTransition = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items
listZTransition.Remove(this); // Remove the item from the list
if (listZTransition.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
RemoveFromDictionaries();
}
private void RemoveFromDictionaries()
{
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString()))
{
List<ZTransition> listZTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
while (listZTransition.Contains(this)) listZTransition.Remove(this); // Remove the item from the list
if (listZTransition.Count == 0) //If there are no items left in the list
_CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
}
}
public static ZTransition New()
{
@@ -297,7 +310,11 @@ namespace VEPROMS.CSLA.Library
{
ZTransition tmp = ZTransition.New(myTransition, oldto);
if (tmp.IsSavable)
tmp = tmp.Save();
{
ZTransition tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@@ -323,13 +340,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a ZTransition");
try
{
ZTransition tmp = GetExistingByPrimaryKey(transitionID);
ZTransition tmp = GetCachedByPrimaryKey(transitionID);
if (tmp == null)
{
tmp = DataPortal.Fetch<ZTransition>(new PKCriteria(transitionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up ZTransition
tmp = null;
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
}
catch (Exception ex)
@@ -371,7 +392,8 @@ namespace VEPROMS.CSLA.Library
{
BuildRefreshList();
ZTransition zTransition = base.Save();
_AllList.Add(zTransition);//Refresh the item in AllList
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(zTransition);//Refresh the item in AllList
ProcessRefreshList();
return zTransition;
}