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<TransitionInfo> _AllList = new List<TransitionInfo>();
|
||||
private static Dictionary<string, List<TransitionInfo>> _AllByPrimaryKey = new Dictionary<string, List<TransitionInfo>>();
|
||||
private static List<TransitionInfo> _CacheList = new List<TransitionInfo>();
|
||||
protected static void AddToCache(TransitionInfo transitionInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(transitionInfo)) _CacheList.Add(transitionInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(TransitionInfo transitionInfo)
|
||||
{
|
||||
while (_CacheList.Contains(transitionInfo)) _CacheList.Remove(transitionInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<TransitionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<TransitionInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<TransitionInfo> remove = new List<TransitionInfo>();
|
||||
foreach (TransitionInfo tmp in _AllList)
|
||||
foreach (TransitionInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<TransitionInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<TransitionInfo>(); // 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 (TransitionInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(TransitionInfoList lst)
|
||||
{
|
||||
foreach (TransitionInfo item in lst) _AllList.Add(item);
|
||||
foreach (TransitionInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static TransitionInfo GetExistingByPrimaryKey(int transitionID)
|
||||
protected static TransitionInfo 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
|
||||
@@ -223,8 +231,11 @@ namespace VEPROMS.CSLA.Library
|
||||
get
|
||||
{
|
||||
CanReadProperty("MyZTransition", true);
|
||||
if (_TransitionZTransitionCount > 0 && _MyZTransition == null)
|
||||
if (_TransitionZTransitionCount != 0 && _MyZTransition == null)
|
||||
{
|
||||
_MyZTransition = ZTransitionInfo.Get(_TransitionID);
|
||||
_TransitionZTransitionCount = _MyZTransition == null ? 0 : 1;
|
||||
}
|
||||
return _MyZTransition;
|
||||
}
|
||||
}
|
||||
@@ -249,24 +260,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _TransitionInfoUnique = 0;
|
||||
private int _MyTransitionInfoUnique;
|
||||
private static int TransitionInfoUnique
|
||||
{ get { return ++_TransitionInfoUnique; } }
|
||||
private int _MyTransitionInfoUnique = TransitionInfoUnique;
|
||||
public int MyTransitionInfoUnique
|
||||
{
|
||||
get { return _MyTransitionInfoUnique; }
|
||||
}
|
||||
private TransitionInfo()
|
||||
{ get { return _MyTransitionInfoUnique; } }
|
||||
protected TransitionInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyTransitionInfoUnique = ++_TransitionInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
|
||||
List<TransitionInfo> listTransitionInfo = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items
|
||||
listTransitionInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
|
||||
List<TransitionInfo> listTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
|
||||
while (listTransitionInfo.Contains(this)) listTransitionInfo.Remove(this); // Remove the item from the list
|
||||
if (listTransitionInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Transition Get()
|
||||
{
|
||||
@@ -276,29 +286,29 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.TransitionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Transition tmp)
|
||||
protected virtual void RefreshFields(Transition tmp)
|
||||
{
|
||||
if (_FromID != tmp.FromID)
|
||||
{
|
||||
MyContent.RefreshContentTransitions(); // Update List for old value
|
||||
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value
|
||||
_FromID = tmp.FromID; // Update the value
|
||||
}
|
||||
_MyContent = null; // Reset list so that the next line gets a new list
|
||||
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value
|
||||
if (_ToID != tmp.ToID)
|
||||
{
|
||||
MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
|
||||
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
|
||||
_ToID = tmp.ToID; // Update the value
|
||||
}
|
||||
_MyItemToID = null; // Reset list so that the next line gets a new list
|
||||
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value
|
||||
if (_RangeID != tmp.RangeID)
|
||||
{
|
||||
MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
|
||||
if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
|
||||
_RangeID = tmp.RangeID; // Update the value
|
||||
}
|
||||
_MyItemRangeID = null; // Reset list so that the next line gets a new list
|
||||
@@ -311,29 +321,30 @@ namespace VEPROMS.CSLA.Library
|
||||
_MyContent = null;
|
||||
_MyItemToID = null;
|
||||
_MyItemRangeID = null;
|
||||
_MyZTransition = null;//
|
||||
_MyZTransition = null;// Reset related value
|
||||
_TransitionZTransitionCount = -1;// Reset Count
|
||||
OnChange();// raise an event
|
||||
}
|
||||
public static void Refresh(ContentTransition tmp)
|
||||
{
|
||||
string key = tmp.TransitionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ContentTransition tmp)
|
||||
protected virtual void RefreshFields(ContentTransition tmp)
|
||||
{
|
||||
if (_ToID != tmp.ToID)
|
||||
{
|
||||
MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
|
||||
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
|
||||
_ToID = tmp.ToID; // Update the value
|
||||
}
|
||||
_MyItemToID = null; // Reset list so that the next line gets a new list
|
||||
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value
|
||||
if (_RangeID != tmp.RangeID)
|
||||
{
|
||||
MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
|
||||
if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
|
||||
_RangeID = tmp.RangeID; // Update the value
|
||||
}
|
||||
_MyItemRangeID = null; // Reset list so that the next line gets a new list
|
||||
@@ -346,29 +357,30 @@ namespace VEPROMS.CSLA.Library
|
||||
_MyContent = null;
|
||||
_MyItemToID = null;
|
||||
_MyItemRangeID = null;
|
||||
_MyZTransition = null;//
|
||||
_MyZTransition = null;// Reset related value
|
||||
_TransitionZTransitionCount = -1;// Reset Count
|
||||
OnChange();// raise an event
|
||||
}
|
||||
public static void Refresh(ItemTransition_RangeID tmp)
|
||||
{
|
||||
string key = tmp.TransitionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ItemTransition_RangeID tmp)
|
||||
protected virtual void RefreshFields(ItemTransition_RangeID tmp)
|
||||
{
|
||||
if (_FromID != tmp.FromID)
|
||||
{
|
||||
MyContent.RefreshContentTransitions(); // Update List for old value
|
||||
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value
|
||||
_FromID = tmp.FromID; // Update the value
|
||||
}
|
||||
_MyContent = null; // Reset list so that the next line gets a new list
|
||||
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value
|
||||
if (_ToID != tmp.ToID)
|
||||
{
|
||||
MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
|
||||
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
|
||||
_ToID = tmp.ToID; // Update the value
|
||||
}
|
||||
_MyItemToID = null; // Reset list so that the next line gets a new list
|
||||
@@ -381,29 +393,30 @@ namespace VEPROMS.CSLA.Library
|
||||
_MyContent = null;
|
||||
_MyItemToID = null;
|
||||
_MyItemRangeID = null;
|
||||
_MyZTransition = null;//
|
||||
_MyZTransition = null;// Reset related value
|
||||
_TransitionZTransitionCount = -1;// Reset Count
|
||||
OnChange();// raise an event
|
||||
}
|
||||
public static void Refresh(ItemTransition_ToID tmp)
|
||||
{
|
||||
string key = tmp.TransitionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ItemTransition_ToID tmp)
|
||||
protected virtual void RefreshFields(ItemTransition_ToID tmp)
|
||||
{
|
||||
if (_FromID != tmp.FromID)
|
||||
{
|
||||
MyContent.RefreshContentTransitions(); // Update List for old value
|
||||
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value
|
||||
_FromID = tmp.FromID; // Update the value
|
||||
}
|
||||
_MyContent = null; // Reset list so that the next line gets a new list
|
||||
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value
|
||||
if (_RangeID != tmp.RangeID)
|
||||
{
|
||||
MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
|
||||
if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
|
||||
_RangeID = tmp.RangeID; // Update the value
|
||||
}
|
||||
_MyItemRangeID = null; // Reset list so that the next line gets a new list
|
||||
@@ -416,7 +429,8 @@ namespace VEPROMS.CSLA.Library
|
||||
_MyContent = null;
|
||||
_MyItemToID = null;
|
||||
_MyItemRangeID = null;
|
||||
_MyZTransition = null;//
|
||||
_MyZTransition = null;// Reset related value
|
||||
_TransitionZTransitionCount = -1;// Reset Count
|
||||
OnChange();// raise an event
|
||||
}
|
||||
public static TransitionInfo Get(int transitionID)
|
||||
@@ -425,13 +439,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Transition");
|
||||
try
|
||||
{
|
||||
TransitionInfo tmp = GetExistingByPrimaryKey(transitionID);
|
||||
TransitionInfo tmp = GetCachedByPrimaryKey(transitionID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<TransitionInfo>(new PKCriteria(transitionID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up TransitionInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -443,7 +461,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal TransitionInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyTransitionInfoUnique = ++_TransitionInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user