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

@@ -54,28 +54,36 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
protected static List<Transition> _AllList = new List<Transition>();
private static Dictionary<string, List<Transition>> _AllByPrimaryKey = new Dictionary<string, List<Transition>>();
private static List<Transition> _CacheList = new List<Transition>();
protected static void AddToCache(Transition transition)
{
if (!_CacheList.Contains(transition)) _CacheList.Add(transition); // In AddToCache
}
protected static void RemoveFromCache(Transition transition)
{
while (_CacheList.Contains(transition)) _CacheList.Remove(transition); // In RemoveFromCache
}
private static Dictionary<string, List<Transition>> _CacheByPrimaryKey = new Dictionary<string, List<Transition>>();
private static void ConvertListToDictionary()
{
List<Transition> remove = new List<Transition>();
foreach (Transition tmp in _AllList)
foreach (Transition tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<Transition>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<Transition>(); // 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 (Transition tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
public static Transition GetExistingByPrimaryKey(int transitionID)
protected static Transition 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
@@ -503,24 +511,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _TransitionUnique = 0;
private int _MyTransitionUnique;
protected static int TransitionUnique
{ get { return ++_TransitionUnique; } }
private int _MyTransitionUnique = TransitionUnique;
public int MyTransitionUnique
{
get { return _MyTransitionUnique; }
}
{ get { return _MyTransitionUnique; } }
protected Transition()
{/* require use of factory methods */
_MyTransitionUnique = ++_TransitionUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
List<Transition> listTransition = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items
listTransition.Remove(this); // Remove the item from the list
if (listTransition.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<Transition> listTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
while (listTransition.Contains(this)) listTransition.Remove(this); // Remove the item from the list
if (listTransition.Count == 0) //If there are no items left in the list
_CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
}
}
public static Transition New()
{
@@ -559,7 +572,11 @@ namespace VEPROMS.CSLA.Library
{
Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, tranType, config, dts, userID);
if (tmp.IsSavable)
tmp = tmp.Save();
{
Transition tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@@ -584,7 +601,11 @@ namespace VEPROMS.CSLA.Library
{
Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config);
if (tmp.IsSavable)
tmp = tmp.Save();
{
Transition tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@@ -602,13 +623,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Transition");
try
{
Transition tmp = GetExistingByPrimaryKey(transitionID);
Transition tmp = GetCachedByPrimaryKey(transitionID);
if (tmp == null)
{
tmp = DataPortal.Fetch<Transition>(new PKCriteria(transitionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Transition
tmp = null;
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
}
catch (Exception ex)
@@ -650,7 +675,8 @@ namespace VEPROMS.CSLA.Library
{
BuildRefreshList();
Transition transition = base.Save();
_AllList.Add(transition);//Refresh the item in AllList
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(transition);//Refresh the item in AllList
ProcessRefreshList();
return transition;
}