diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs index 6e92c167..c5fe3e86 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs @@ -53,28 +53,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(Membership membership) + { + if (!_CacheList.Contains(membership)) _CacheList.Add(membership); // In AddToCache + } + protected static void RemoveFromCache(Membership membership) + { + while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Membership tmp in _AllList) + foreach (Membership tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.UGID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString())) { - _AllByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (Membership tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Membership GetExistingByPrimaryKey(int ugid) + protected static Membership GetCachedByPrimaryKey(int ugid) { ConvertListToDictionary(); string key = ugid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -484,24 +492,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _MembershipUnique = 0; - private int _MyMembershipUnique; + protected static int MembershipUnique + { get { return ++_MembershipUnique; } } + private int _MyMembershipUnique = MembershipUnique; public int MyMembershipUnique - { - get { return _MyMembershipUnique; } - } + { get { return _MyMembershipUnique; } } protected Membership() {/* require use of factory methods */ - _MyMembershipUnique = ++_MembershipUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(UGID.ToString())) return; - List listMembership = _AllByPrimaryKey[UGID.ToString()]; // Get the list of items - listMembership.Remove(this); // Remove the item from the list - if (listMembership.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(UGID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(UGID.ToString())) + { + List listMembership = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items + while (listMembership.Contains(this)) listMembership.Remove(this); // Remove the item from the list + if (listMembership.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list + } } public static Membership New() { @@ -539,7 +552,11 @@ namespace VEPROMS.CSLA.Library { Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Membership tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -564,7 +581,11 @@ namespace VEPROMS.CSLA.Library { Membership tmp = Membership.New(myUser, myGroup, endDate, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Membership tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -582,13 +603,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Membership"); try { - Membership tmp = GetExistingByPrimaryKey(ugid); + Membership tmp = GetCachedByPrimaryKey(ugid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(ugid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Membership + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -630,7 +655,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Membership membership = base.Save(); - _AllList.Add(membership);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(membership);//Refresh the item in AllList ProcessRefreshList(); return membership; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs index 704aa509..f30e5dae 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(MembershipInfo membershipInfo) + { + if (!_CacheList.Contains(membershipInfo)) _CacheList.Add(membershipInfo); // In AddToCache + } + protected static void RemoveFromCache(MembershipInfo membershipInfo) + { + while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (MembershipInfo tmp in _AllList) + foreach (MembershipInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.UGID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString())) { - _AllByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (MembershipInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(MembershipInfoList lst) { - foreach (MembershipInfo item in lst) _AllList.Add(item); + foreach (MembershipInfo item in lst) AddToCache(item); } - public static MembershipInfo GetExistingByPrimaryKey(int ugid) + protected static MembershipInfo GetCachedByPrimaryKey(int ugid) { ConvertListToDictionary(); string key = ugid.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 _MembershipInfoUnique = 0; - private int _MyMembershipInfoUnique; + private static int MembershipInfoUnique + { get { return ++_MembershipInfoUnique; } } + private int _MyMembershipInfoUnique = MembershipInfoUnique; public int MyMembershipInfoUnique - { - get { return _MyMembershipInfoUnique; } - } - private MembershipInfo() + { get { return _MyMembershipInfoUnique; } } + protected MembershipInfo() {/* require use of factory methods */ - _MyMembershipInfoUnique = ++_MembershipInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(UGID.ToString())) return; - List listMembershipInfo = _AllByPrimaryKey[UGID.ToString()]; // Get the list of items - listMembershipInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(UGID.ToString())) return; + List listMembershipInfo = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items + while (listMembershipInfo.Contains(this)) listMembershipInfo.Remove(this); // Remove the item from the list if (listMembershipInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(UGID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list } public virtual Membership Get() { @@ -235,22 +242,22 @@ namespace VEPROMS.CSLA.Library { string key = tmp.UGID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Membership tmp) + protected virtual void RefreshFields(Membership tmp) { if (_UID != tmp.UID) { - MyUser.RefreshUserMemberships(); // Update List for old value + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value _UID = tmp.UID; // Update the value } _MyUser = null; // Reset list so that the next line gets a new list if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value if (_GID != tmp.GID) { - MyGroup.RefreshGroupMemberships(); // Update List for old value + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value _GID = tmp.GID; // Update the value } _MyGroup = null; // Reset list so that the next line gets a new list @@ -269,15 +276,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.UGID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(GroupMembership tmp) + protected virtual void RefreshFields(GroupMembership tmp) { if (_UID != tmp.UID) { - MyUser.RefreshUserMemberships(); // Update List for old value + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value _UID = tmp.UID; // Update the value } _MyUser = null; // Reset list so that the next line gets a new list @@ -296,15 +303,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.UGID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(UserMembership tmp) + protected virtual void RefreshFields(UserMembership tmp) { if (_GID != tmp.GID) { - MyGroup.RefreshGroupMemberships(); // Update List for old value + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value _GID = tmp.GID; // Update the value } _MyGroup = 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 Membership"); try { - MembershipInfo tmp = GetExistingByPrimaryKey(ugid); + MembershipInfo tmp = GetCachedByPrimaryKey(ugid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(ugid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up MembershipInfo + 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 MembershipInfo(SafeDataReader dr) { - _MyMembershipInfoUnique = ++_MembershipInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs index 5a0ec6f9..01303193 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs @@ -53,28 +53,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(Part part) + { + if (!_CacheList.Contains(part)) _CacheList.Add(part); // In AddToCache + } + protected static void RemoveFromCache(Part part) + { + while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Part tmp in _AllList) + foreach (Part tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) { - _AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (Part tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Part GetExistingByPrimaryKey(int contentID, int fromType) + protected static Part GetCachedByPrimaryKey(int contentID, int fromType) { ConvertListToDictionary(); string key = contentID.ToString() + "_" + fromType.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -339,24 +347,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _PartUnique = 0; - private int _MyPartUnique; + protected static int PartUnique + { get { return ++_PartUnique; } } + private int _MyPartUnique = PartUnique; public int MyPartUnique - { - get { return _MyPartUnique; } - } + { get { return _MyPartUnique; } } protected Part() {/* require use of factory methods */ - _MyPartUnique = ++_PartUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; - List listPart = _AllByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items - listPart.Remove(this); // Remove the item from the list - if (listPart.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) + { + List listPart = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items + while (listPart.Contains(this)) listPart.Remove(this); // Remove the item from the list + if (listPart.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + } } public static Part New() { @@ -379,6 +392,26 @@ namespace VEPROMS.CSLA.Library tmp.MyItem = myItem; return tmp; } + public static Part MakePart(Content myContent, int fromType, Item myItem) + { + Part tmp = Part.New(myContent, fromType, myItem); + if (tmp.IsSavable) + { + Part tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID) { Part tmp = Part.New(); @@ -393,7 +426,11 @@ namespace VEPROMS.CSLA.Library { Part tmp = Part.New(myContent, fromType, myItem, dts, userID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Part tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -411,13 +448,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Part"); try { - Part tmp = GetExistingByPrimaryKey(contentID, fromType); + Part tmp = GetCachedByPrimaryKey(contentID, fromType); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Part + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -459,7 +500,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Part part = base.Save(); - _AllList.Add(part);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(part);//Refresh the item in AllList ProcessRefreshList(); return part; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs index 42ed2e7a..3f51c54e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(PartInfo partInfo) + { + if (!_CacheList.Contains(partInfo)) _CacheList.Add(partInfo); // In AddToCache + } + protected static void RemoveFromCache(PartInfo partInfo) + { + while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (PartInfo tmp in _AllList) + foreach (PartInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) { - _AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (PartInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(PartInfoList lst) { - foreach (PartInfo item in lst) _AllList.Add(item); + foreach (PartInfo item in lst) AddToCache(item); } - public static PartInfo GetExistingByPrimaryKey(int contentID, int fromType) + protected static PartInfo GetCachedByPrimaryKey(int contentID, int fromType) { ConvertListToDictionary(); string key = contentID.ToString() + "_" + fromType.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -180,24 +188,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _PartInfoUnique = 0; - private int _MyPartInfoUnique; + private static int PartInfoUnique + { get { return ++_PartInfoUnique; } } + private int _MyPartInfoUnique = PartInfoUnique; public int MyPartInfoUnique - { - get { return _MyPartInfoUnique; } - } - private PartInfo() + { get { return _MyPartInfoUnique; } } + protected PartInfo() {/* require use of factory methods */ - _MyPartInfoUnique = ++_PartInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; - List listPartInfo = _AllByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items - listPartInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; + List listPartInfo = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items + while (listPartInfo.Contains(this)) listPartInfo.Remove(this); // Remove the item from the list if (listPartInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list } public virtual Part Get() { @@ -207,15 +214,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Part tmp) + protected virtual void RefreshFields(Part tmp) { if (_ItemID != tmp.ItemID) { - MyItem.RefreshItemParts(); // Update List for old value + if (MyItem != null) MyItem.RefreshItemParts(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list @@ -231,15 +238,15 @@ namespace VEPROMS.CSLA.Library { string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ContentPart tmp) + protected virtual void RefreshFields(ContentPart tmp) { if (_ItemID != tmp.ItemID) { - MyItem.RefreshItemParts(); // Update List for old value + if (MyItem != null) MyItem.RefreshItemParts(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list @@ -255,11 +262,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ItemPart tmp) + protected virtual void RefreshFields(ItemPart tmp) { _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -274,13 +281,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Part"); try { - PartInfo tmp = GetExistingByPrimaryKey(contentID, fromType); + PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -292,7 +303,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal PartInfo(SafeDataReader dr) { - _MyPartInfoUnique = ++_PartInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs index bc391a4e..1764ec4b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs @@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(Permission permission) + { + if (!_CacheList.Contains(permission)) _CacheList.Add(permission); // In AddToCache + } + protected static void RemoveFromCache(Permission permission) + { + while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Permission tmp in _AllList) + foreach (Permission tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString())) { - _AllByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (Permission tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Permission GetExistingByPrimaryKey(int pid) + protected static Permission GetCachedByPrimaryKey(int pid) { ConvertListToDictionary(); string key = pid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -538,24 +546,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _PermissionUnique = 0; - private int _MyPermissionUnique; + protected static int PermissionUnique + { get { return ++_PermissionUnique; } } + private int _MyPermissionUnique = PermissionUnique; public int MyPermissionUnique - { - get { return _MyPermissionUnique; } - } + { get { return _MyPermissionUnique; } } protected Permission() {/* require use of factory methods */ - _MyPermissionUnique = ++_PermissionUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return; - List listPermission = _AllByPrimaryKey[PID.ToString()]; // Get the list of items - listPermission.Remove(this); // Remove the item from the list - if (listPermission.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(PID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(PID.ToString())) + { + List listPermission = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items + while (listPermission.Contains(this)) listPermission.Remove(this); // Remove the item from the list + if (listPermission.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list + } } public static Permission New() { @@ -598,7 +611,11 @@ namespace VEPROMS.CSLA.Library { Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Permission tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -625,7 +642,11 @@ namespace VEPROMS.CSLA.Library { Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Permission tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -643,13 +664,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Permission"); try { - Permission tmp = GetExistingByPrimaryKey(pid); + Permission tmp = GetCachedByPrimaryKey(pid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(pid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Permission + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -691,7 +716,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Permission permission = base.Save(); - _AllList.Add(permission);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(permission);//Refresh the item in AllList ProcessRefreshList(); return permission; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs index 10ea54ef..51c668d4 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(PermissionInfo permissionInfo) + { + if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache + } + protected static void RemoveFromCache(PermissionInfo permissionInfo) + { + while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (PermissionInfo tmp in _AllList) + foreach (PermissionInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString())) { - _AllByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (PermissionInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(PermissionInfoList lst) { - foreach (PermissionInfo item in lst) _AllList.Add(item); + foreach (PermissionInfo item in lst) AddToCache(item); } - public static PermissionInfo GetExistingByPrimaryKey(int pid) + protected static PermissionInfo GetCachedByPrimaryKey(int pid) { ConvertListToDictionary(); string key = pid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -238,24 +246,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _PermissionInfoUnique = 0; - private int _MyPermissionInfoUnique; + private static int PermissionInfoUnique + { get { return ++_PermissionInfoUnique; } } + private int _MyPermissionInfoUnique = PermissionInfoUnique; public int MyPermissionInfoUnique - { - get { return _MyPermissionInfoUnique; } - } - private PermissionInfo() + { get { return _MyPermissionInfoUnique; } } + protected PermissionInfo() {/* require use of factory methods */ - _MyPermissionInfoUnique = ++_PermissionInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return; - List listPermissionInfo = _AllByPrimaryKey[PID.ToString()]; // Get the list of items - listPermissionInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return; + List listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items + while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list if (listPermissionInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(PID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list } public virtual Permission Get() { @@ -265,15 +272,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.PID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Permission tmp) + protected virtual void RefreshFields(Permission tmp) { if (_RID != tmp.RID) { - MyRole.RefreshRolePermissions(); // Update List for old value + if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value _RID = tmp.RID; // Update the value } _MyRole = null; // Reset list so that the next line gets a new list @@ -295,11 +302,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.PID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(RolePermission tmp) + protected virtual void RefreshFields(RolePermission tmp) { _PermLevel = tmp.PermLevel; _VersionType = tmp.VersionType; @@ -320,13 +327,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Permission"); try { - PermissionInfo tmp = GetExistingByPrimaryKey(pid); + PermissionInfo tmp = GetCachedByPrimaryKey(pid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(pid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PermissionInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -338,7 +349,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal PermissionInfo(SafeDataReader dr) { - _MyPermissionInfoUnique = ++_PermissionInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs index c7a8cf9b..d0f7739c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs @@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(RoUsage roUsage) + { + if (!_CacheList.Contains(roUsage)) _CacheList.Add(roUsage); // In AddToCache + } + protected static void RemoveFromCache(RoUsage roUsage) + { + while (_CacheList.Contains(roUsage)) _CacheList.Remove(roUsage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (RoUsage tmp in _AllList) + foreach (RoUsage tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) { - _AllByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (RoUsage tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static RoUsage GetExistingByPrimaryKey(int rOUsageID) + protected static RoUsage GetCachedByPrimaryKey(int rOUsageID) { ConvertListToDictionary(); string key = rOUsageID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -372,24 +380,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _RoUsageUnique = 0; - private int _MyRoUsageUnique; + protected static int RoUsageUnique + { get { return ++_RoUsageUnique; } } + private int _MyRoUsageUnique = RoUsageUnique; public int MyRoUsageUnique - { - get { return _MyRoUsageUnique; } - } + { get { return _MyRoUsageUnique; } } protected RoUsage() {/* require use of factory methods */ - _MyRoUsageUnique = ++_RoUsageUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; - List listRoUsage = _AllByPrimaryKey[ROUsageID.ToString()]; // Get the list of items - listRoUsage.Remove(this); // Remove the item from the list - if (listRoUsage.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) + { + List listRoUsage = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items + while (listRoUsage.Contains(this)) listRoUsage.Remove(this); // Remove the item from the list + if (listRoUsage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + } } public static RoUsage New() { @@ -424,7 +437,11 @@ namespace VEPROMS.CSLA.Library { RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + RoUsage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -448,7 +465,11 @@ namespace VEPROMS.CSLA.Library { RoUsage tmp = RoUsage.New(myContent, roid, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + RoUsage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -466,13 +487,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a RoUsage"); try { - RoUsage tmp = GetExistingByPrimaryKey(rOUsageID); + RoUsage tmp = GetCachedByPrimaryKey(rOUsageID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoUsage + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -514,7 +539,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); RoUsage roUsage = base.Save(); - _AllList.Add(roUsage);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(roUsage);//Refresh the item in AllList ProcessRefreshList(); return roUsage; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs index 0c354ce1..3a9eabc0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(RoUsageInfo roUsageInfo) + { + if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache + } + protected static void RemoveFromCache(RoUsageInfo roUsageInfo) + { + while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (RoUsageInfo tmp in _AllList) + foreach (RoUsageInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) { - _AllByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (RoUsageInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(RoUsageInfoList lst) { - foreach (RoUsageInfo item in lst) _AllList.Add(item); + foreach (RoUsageInfo item in lst) AddToCache(item); } - public static RoUsageInfo GetExistingByPrimaryKey(int rOUsageID) + protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID) { ConvertListToDictionary(); string key = rOUsageID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -176,24 +184,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _RoUsageInfoUnique = 0; - private int _MyRoUsageInfoUnique; + private static int RoUsageInfoUnique + { get { return ++_RoUsageInfoUnique; } } + private int _MyRoUsageInfoUnique = RoUsageInfoUnique; public int MyRoUsageInfoUnique - { - get { return _MyRoUsageInfoUnique; } - } - private RoUsageInfo() + { get { return _MyRoUsageInfoUnique; } } + protected RoUsageInfo() {/* require use of factory methods */ - _MyRoUsageInfoUnique = ++_RoUsageInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; - List listRoUsageInfo = _AllByPrimaryKey[ROUsageID.ToString()]; // Get the list of items - listRoUsageInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; + List listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items + while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list if (listRoUsageInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list } public virtual RoUsage Get() { @@ -203,15 +210,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ROUsageID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(RoUsage tmp) + protected virtual void RefreshFields(RoUsage tmp) { if (_ContentID != tmp.ContentID) { - MyContent.RefreshContentRoUsages(); // Update List for old value + if (MyContent != null) MyContent.RefreshContentRoUsages(); // Update List for old value _ContentID = tmp.ContentID; // Update the value } _MyContent = null; // Reset list so that the next line gets a new list @@ -228,11 +235,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ROUsageID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ContentRoUsage tmp) + protected virtual void RefreshFields(ContentRoUsage tmp) { _ROID = tmp.ROID; _Config = tmp.Config; @@ -248,13 +255,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a RoUsage"); try { - RoUsageInfo tmp = GetExistingByPrimaryKey(rOUsageID); + RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoUsageInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -266,7 +277,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal RoUsageInfo(SafeDataReader dr) { - _MyRoUsageInfoUnique = ++_RoUsageInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs index 69a78726..8a039745 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs @@ -77,38 +77,46 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); - private static Dictionary> _AllByName = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(Role role) + { + if (!_CacheList.Contains(role)) _CacheList.Add(role); // In AddToCache + } + protected static void RemoveFromCache(Role role) + { + while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Role tmp in _AllList) + foreach (Role tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.RID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString())) { - _AllByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey - _AllByName[tmp.Name.ToString()] = new List(); // Add new list for Name + _CacheByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name } - _AllByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list - _AllByName[tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index remove.Add(tmp); } foreach (Role tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Role GetExistingByPrimaryKey(int rid) + protected static Role GetCachedByPrimaryKey(int rid) { ConvertListToDictionary(); string key = rid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } - public static Role GetExistingByName(string name) + protected static Role 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 @@ -442,28 +450,41 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _RoleUnique = 0; - private int _MyRoleUnique; + protected static int RoleUnique + { get { return ++_RoleUnique; } } + private int _MyRoleUnique = RoleUnique; public int MyRoleUnique - { - get { return _MyRoleUnique; } - } + { get { return _MyRoleUnique; } } protected Role() {/* require use of factory methods */ - _MyRoleUnique = ++_RoleUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(RID.ToString())) return; - List listRole = _AllByPrimaryKey[RID.ToString()]; // Get the list of items - listRole.Remove(this); // Remove the item from the list - if (listRole.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(RID.ToString()); // remove the list - listRole = _AllByName[RID.ToString()]; // Get the list of items - listRole.Remove(this); // Remove the item from the list - if (listRole.Count == 0) //If there are no items left in the list - _AllByName.Remove(RID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RID.ToString())) + { + List listRole = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items + while (listRole.Contains(this)) listRole.Remove(this); // Remove the item from the list + if (listRole.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(RID.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 listRole = _CacheByName[myKey]; // Get the list of items + listRole.Remove(this); // Remove the item from the list + if (listRole.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } } public static Role New() { @@ -485,6 +506,26 @@ namespace VEPROMS.CSLA.Library tmp.Title = title; return tmp; } + public static Role MakeRole(string name, string title) + { + Role tmp = Role.New(name, title); + if (tmp.IsSavable) + { + Role tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } public static Role New(string name, string title, DateTime dts, string usrID) { Role tmp = Role.New(); @@ -498,7 +539,11 @@ namespace VEPROMS.CSLA.Library { Role tmp = Role.New(name, title, dts, usrID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Role tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -516,13 +561,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Role"); try { - Role tmp = GetExistingByPrimaryKey(rid); + Role tmp = GetCachedByPrimaryKey(rid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(rid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Role + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -530,19 +579,23 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on Role.Get", ex); } } - private static Role GetByName(string name) + public static Role GetByName(string name) { if (!CanGetObject()) throw new System.Security.SecurityException("User not authorized to view a Role"); try { - Role tmp = GetExistingByName(name); + Role tmp = GetCachedByName(name); if (tmp == null) { tmp = DataPortal.Fetch(new NameCriteria(name)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Role + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -584,7 +637,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Role role = base.Save(); - _AllList.Add(role);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(role);//Refresh the item in AllList ProcessRefreshList(); return role; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs index b004304f..a7fc0b23 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs @@ -285,6 +285,16 @@ namespace VEPROMS.CSLA.Library return _Folder_FormatID; } } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Folder_ManualOrder", true); + return _Folder_ManualOrder; + } + } private string _Folder_Config = string.Empty; public string Folder_Config { @@ -597,6 +607,7 @@ namespace VEPROMS.CSLA.Library _Folder_Title = dr.GetString("Folder_Title"); _Folder_ShortName = dr.GetString("Folder_ShortName"); _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); _Folder_Config = dr.GetString("Folder_Config"); _Folder_DTS = dr.GetDateTime("Folder_DTS"); _Folder_UsrID = dr.GetString("Folder_UsrID"); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs index af462424..95524c04 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(RoleInfo roleInfo) + { + if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache + } + protected static void RemoveFromCache(RoleInfo roleInfo) + { + while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (RoleInfo tmp in _AllList) + foreach (RoleInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.RID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString())) { - _AllByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (RoleInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(RoleInfoList lst) { - foreach (RoleInfo item in lst) _AllList.Add(item); + foreach (RoleInfo item in lst) AddToCache(item); } - public static RoleInfo GetExistingByPrimaryKey(int rid) + protected static RoleInfo GetCachedByPrimaryKey(int rid) { ConvertListToDictionary(); string key = rid.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 _RoleAssignments; } } - internal void RefreshRoleAssignments() + public void RefreshRoleAssignments() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_RID.ToString())) - foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) + foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried } private int _RolePermissionCount = 0; @@ -196,11 +204,11 @@ namespace VEPROMS.CSLA.Library return _RolePermissions; } } - internal void RefreshRolePermissions() + public void RefreshRolePermissions() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_RID.ToString())) - foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) + foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) tmp._RolePermissionCount = -1; // This will cause the data to be requeried } // TODO: Replace base RoleInfo.ToString function as necessary @@ -224,24 +232,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _RoleInfoUnique = 0; - private int _MyRoleInfoUnique; + private static int RoleInfoUnique + { get { return ++_RoleInfoUnique; } } + private int _MyRoleInfoUnique = RoleInfoUnique; public int MyRoleInfoUnique - { - get { return _MyRoleInfoUnique; } - } - private RoleInfo() + { get { return _MyRoleInfoUnique; } } + protected RoleInfo() {/* require use of factory methods */ - _MyRoleInfoUnique = ++_RoleInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(RID.ToString())) return; - List listRoleInfo = _AllByPrimaryKey[RID.ToString()]; // Get the list of items - listRoleInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return; + List listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items + while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list if (listRoleInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(RID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list } public virtual Role Get() { @@ -251,11 +258,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.RID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (RoleInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Role tmp) + protected virtual void RefreshFields(Role tmp) { _Name = tmp.Name; _Title = tmp.Title; @@ -270,13 +277,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Role"); try { - RoleInfo tmp = GetExistingByPrimaryKey(rid); + RoleInfo tmp = GetCachedByPrimaryKey(rid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(rid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoleInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -288,7 +299,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal RoleInfo(SafeDataReader dr) { - _MyRoleInfoUnique = ++_RoleInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs index 4dbaf6a4..4a92be9d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs @@ -54,28 +54,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + 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> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - 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(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // 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 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 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(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; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs index c8471df5..b4470461 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + 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> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - 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(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // 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 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 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(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 { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/User.cs b/PROMS/VEPROMS.CSLA.Library/Generated/User.cs index d6a634fe..aa48f537 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/User.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/User.cs @@ -64,28 +64,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(User user) + { + if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache + } + protected static void RemoveFromCache(User user) + { + while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (User tmp in _AllList) + foreach (User tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.UID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString())) { - _AllByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (User tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static User GetExistingByPrimaryKey(int uid) + protected static User GetCachedByPrimaryKey(int uid) { ConvertListToDictionary(); string key = uid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -618,24 +626,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _UserUnique = 0; - private int _MyUserUnique; + protected static int UserUnique + { get { return ++_UserUnique; } } + private int _MyUserUnique = UserUnique; public int MyUserUnique - { - get { return _MyUserUnique; } - } + { get { return _MyUserUnique; } } protected User() {/* require use of factory methods */ - _MyUserUnique = ++_UserUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(UID.ToString())) return; - List listUser = _AllByPrimaryKey[UID.ToString()]; // Get the list of items - listUser.Remove(this); // Remove the item from the list - if (listUser.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(UID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(UID.ToString())) + { + List listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items + while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list + if (listUser.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list + } } public static User New() { @@ -672,7 +685,11 @@ namespace VEPROMS.CSLA.Library { User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + User tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -703,7 +720,11 @@ namespace VEPROMS.CSLA.Library { User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + User tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -721,13 +742,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a User"); try { - User tmp = GetExistingByPrimaryKey(uid); + User tmp = GetCachedByPrimaryKey(uid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(uid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up User + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -769,7 +794,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); User user = base.Save(); - _AllList.Add(user);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(user);//Refresh the item in AllList ProcessRefreshList(); return user; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs index 9959debd..2134f120 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs @@ -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 _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(UserInfo userInfo) + { + if (!_CacheList.Contains(userInfo)) _CacheList.Add(userInfo); // In AddToCache + } + protected static void RemoveFromCache(UserInfo userInfo) + { + while (_CacheList.Contains(userInfo)) _CacheList.Remove(userInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (UserInfo tmp in _AllList) + foreach (UserInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.UID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString())) { - _AllByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (UserInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(UserInfoList lst) { - foreach (UserInfo item in lst) _AllList.Add(item); + foreach (UserInfo item in lst) AddToCache(item); } - public static UserInfo GetExistingByPrimaryKey(int uid) + protected static UserInfo GetCachedByPrimaryKey(int uid) { ConvertListToDictionary(); string key = uid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -251,11 +259,11 @@ namespace VEPROMS.CSLA.Library return _UserMemberships; } } - internal void RefreshUserMemberships() + public void RefreshUserMemberships() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_UID.ToString())) - foreach (UserInfo tmp in _AllByPrimaryKey[_UID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_UID.ToString())) + foreach (UserInfo tmp in _CacheByPrimaryKey[_UID.ToString()]) tmp._UserMembershipCount = -1; // This will cause the data to be requeried } // TODO: Replace base UserInfo.ToString function as necessary @@ -279,24 +287,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _UserInfoUnique = 0; - private int _MyUserInfoUnique; + private static int UserInfoUnique + { get { return ++_UserInfoUnique; } } + private int _MyUserInfoUnique = UserInfoUnique; public int MyUserInfoUnique - { - get { return _MyUserInfoUnique; } - } - private UserInfo() + { get { return _MyUserInfoUnique; } } + protected UserInfo() {/* require use of factory methods */ - _MyUserInfoUnique = ++_UserInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(UID.ToString())) return; - List listUserInfo = _AllByPrimaryKey[UID.ToString()]; // Get the list of items - listUserInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(UID.ToString())) return; + List listUserInfo = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items + while (listUserInfo.Contains(this)) listUserInfo.Remove(this); // Remove the item from the list if (listUserInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(UID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list } public virtual User Get() { @@ -306,11 +313,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.UID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (UserInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (UserInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(User tmp) + protected virtual void RefreshFields(User tmp) { _UserID = tmp.UserID; _FirstName = tmp.FirstName; @@ -334,13 +341,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a User"); try { - UserInfo tmp = GetExistingByPrimaryKey(uid); + UserInfo tmp = GetCachedByPrimaryKey(uid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(uid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up UserInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -352,7 +363,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal UserInfo(SafeDataReader dr) { - _MyUserInfoUnique = ++_UserInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs index bf974422..cee1a28c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs @@ -51,28 +51,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(ZContent zContent) + { + if (!_CacheList.Contains(zContent)) _CacheList.Add(zContent); // In AddToCache + } + protected static void RemoveFromCache(ZContent zContent) + { + while (_CacheList.Contains(zContent)) _CacheList.Remove(zContent); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (ZContent tmp in _AllList) + foreach (ZContent tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) { - _AllByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (ZContent tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static ZContent GetExistingByPrimaryKey(int contentID) + protected static ZContent GetCachedByPrimaryKey(int contentID) { ConvertListToDictionary(); string key = contentID.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 _ZContentUnique = 0; - private int _MyZContentUnique; + protected static int ZContentUnique + { get { return ++_ZContentUnique; } } + private int _MyZContentUnique = ZContentUnique; public int MyZContentUnique - { - get { return _MyZContentUnique; } - } + { get { return _MyZContentUnique; } } protected ZContent() {/* require use of factory methods */ - _MyZContentUnique = ++_ZContentUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listZContent = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items - listZContent.Remove(this); // Remove the item from the list - if (listZContent.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listZContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listZContent.Contains(this)) listZContent.Remove(this); // Remove the item from the list + if (listZContent.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } } public static ZContent New() { @@ -297,7 +310,11 @@ namespace VEPROMS.CSLA.Library { ZContent tmp = ZContent.New(myContent, oldStepSequence); if (tmp.IsSavable) - tmp = tmp.Save(); + { + ZContent 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 ZContent"); try { - ZContent tmp = GetExistingByPrimaryKey(contentID); + ZContent tmp = GetCachedByPrimaryKey(contentID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(contentID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZContent + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -371,7 +392,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); ZContent zContent = base.Save(); - _AllList.Add(zContent);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(zContent);//Refresh the item in AllList ProcessRefreshList(); return zContent; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs index d24533e6..d2f971e9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs @@ -36,28 +36,36 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(ZContentInfo zContentInfo) + { + if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache + } + protected static void RemoveFromCache(ZContentInfo zContentInfo) + { + while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (ZContentInfo tmp in _AllList) + foreach (ZContentInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) { - _AllByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (ZContentInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static ZContentInfo GetExistingByPrimaryKey(int contentID) + protected static ZContentInfo GetCachedByPrimaryKey(int contentID) { ConvertListToDictionary(); string key = contentID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -133,24 +141,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _ZContentInfoUnique = 0; - private int _MyZContentInfoUnique; + private static int ZContentInfoUnique + { get { return ++_ZContentInfoUnique; } } + private int _MyZContentInfoUnique = ZContentInfoUnique; public int MyZContentInfoUnique - { - get { return _MyZContentInfoUnique; } - } - private ZContentInfo() + { get { return _MyZContentInfoUnique; } } + protected ZContentInfo() {/* require use of factory methods */ - _MyZContentInfoUnique = ++_ZContentInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listZContentInfo = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items - listZContentInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list if (listZContentInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list } public virtual ZContent Get() { @@ -160,11 +167,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ContentID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (ZContentInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ZContent tmp) + protected virtual void RefreshFields(ZContent tmp) { _OldStepSequence = tmp.OldStepSequence; _ZContentInfoExtension.Refresh(this); @@ -177,15 +184,16 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a ZContent"); try { - ZContentInfo tmp = GetExistingByPrimaryKey(contentID); + ZContentInfo tmp = GetCachedByPrimaryKey(contentID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(contentID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); } if (tmp.ErrorMessage == "No Record Found") { - tmp._ContentID = contentID; + tmp.Dispose(); // Clean-up ZContentInfo + tmp = null; } return tmp; } @@ -198,7 +206,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal ZContentInfo(SafeDataReader dr) { - _MyZContentInfoUnique = ++_ZContentInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs index 291f42cc..de463d67 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs @@ -51,28 +51,36 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + 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> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - 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(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // 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 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 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(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; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs index 1774bb86..705bf476 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs @@ -36,28 +36,36 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(ZTransitionInfo zTransitionInfo) + { + if (!_CacheList.Contains(zTransitionInfo)) _CacheList.Add(zTransitionInfo); // In AddToCache + } + protected static void RemoveFromCache(ZTransitionInfo zTransitionInfo) + { + while (_CacheList.Contains(zTransitionInfo)) _CacheList.Remove(zTransitionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (ZTransitionInfo tmp in _AllList) + foreach (ZTransitionInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) { - _AllByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // 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 (ZTransitionInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static ZTransitionInfo GetExistingByPrimaryKey(int transitionID) + protected static ZTransitionInfo 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 @@ -133,24 +141,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _ZTransitionInfoUnique = 0; - private int _MyZTransitionInfoUnique; + private static int ZTransitionInfoUnique + { get { return ++_ZTransitionInfoUnique; } } + private int _MyZTransitionInfoUnique = ZTransitionInfoUnique; public int MyZTransitionInfoUnique - { - get { return _MyZTransitionInfoUnique; } - } - private ZTransitionInfo() + { get { return _MyZTransitionInfoUnique; } } + protected ZTransitionInfo() {/* require use of factory methods */ - _MyZTransitionInfoUnique = ++_ZTransitionInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return; - List listZTransitionInfo = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items - listZTransitionInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; + List listZTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listZTransitionInfo.Contains(this)) listZTransitionInfo.Remove(this); // Remove the item from the list if (listZTransitionInfo.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 ZTransition Get() { @@ -160,11 +167,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.TransitionID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (ZTransitionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ZTransitionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ZTransition tmp) + protected virtual void RefreshFields(ZTransition tmp) { _Oldto = tmp.Oldto; _ZTransitionInfoExtension.Refresh(this); @@ -177,15 +184,16 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a ZTransition"); try { - ZTransitionInfo tmp = GetExistingByPrimaryKey(transitionID); + ZTransitionInfo tmp = GetCachedByPrimaryKey(transitionID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); } if (tmp.ErrorMessage == "No Record Found") { - tmp._TransitionID = transitionID; + tmp.Dispose(); // Clean-up ZTransitionInfo + tmp = null; } return tmp; } @@ -198,7 +206,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal ZTransitionInfo(SafeDataReader dr) { - _MyZTransitionInfoUnique = ++_ZTransitionInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode()); try {