diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs index 7e50b3db..1e2b701e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs @@ -117,28 +117,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(Content content) + { + if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache + } + protected static void RemoveFromCache(Content content) + { + while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Content tmp in _AllList) + foreach (Content 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 (Content tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Content GetExistingByPrimaryKey(int contentID) + protected static Content 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,7 +262,7 @@ namespace VEPROMS.CSLA.Library set { CanWriteProperty("MyFormat", true); - if (_MyFormat != value) + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) { _MyFormat = value; _FormatID = (value == null ? null : (int?)value.FormatID); @@ -714,24 +722,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _ContentUnique = 0; - private int _MyContentUnique; + protected static int ContentUnique + { get { return ++_ContentUnique; } } + private int _MyContentUnique = ContentUnique; public int MyContentUnique - { - get { return _MyContentUnique; } - } + { get { return _MyContentUnique; } } protected Content() {/* require use of factory methods */ - _MyContentUnique = ++_ContentUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listContent = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items - listContent.Remove(this); // Remove the item from the list - if (listContent.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 listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list + if (listContent.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } } public static Content New() { @@ -762,7 +775,11 @@ namespace VEPROMS.CSLA.Library { Content tmp = Content.New(number, text, type, myFormat, config, dts, userID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Content tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -788,7 +805,11 @@ namespace VEPROMS.CSLA.Library { Content tmp = Content.New(number, text, type, myFormat, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Content tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -806,13 +827,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Content"); try { - Content tmp = GetExistingByPrimaryKey(contentID); + Content 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 Content + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -854,7 +879,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Content content = base.Save(); - _AllList.Add(content);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(content);//Refresh the item in AllList ProcessRefreshList(); return content; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs index c291cbc9..b4a1c950 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.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(ContentInfo contentInfo) + { + if (!_CacheList.Contains(contentInfo)) _CacheList.Add(contentInfo); // In AddToCache + } + protected static void RemoveFromCache(ContentInfo contentInfo) + { + while (_CacheList.Contains(contentInfo)) _CacheList.Remove(contentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (ContentInfo tmp in _AllList) + foreach (ContentInfo 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 (ContentInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(ContentInfoList lst) { - foreach (ContentInfo item in lst) _AllList.Add(item); + foreach (ContentInfo item in lst) AddToCache(item); } - public static ContentInfo GetExistingByPrimaryKey(int contentID) + protected static ContentInfo 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 @@ -206,11 +214,11 @@ namespace VEPROMS.CSLA.Library return _ContentDetails; } } - internal void RefreshContentDetails() + public void RefreshContentDetails() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _AllByPrimaryKey[_ContentID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) tmp._ContentDetailCount = -1; // This will cause the data to be requeried } private int _ContentEntryCount = 0; @@ -234,8 +242,11 @@ namespace VEPROMS.CSLA.Library get { CanReadProperty("MyEntry", true); - if (_ContentEntryCount > 0 && _MyEntry == null) + if (_ContentEntryCount != 0 && _MyEntry == null) + { _MyEntry = EntryInfo.Get(_ContentID); + _ContentEntryCount = _MyEntry == null ? 0 : 1; + } return _MyEntry; } } @@ -267,11 +278,11 @@ namespace VEPROMS.CSLA.Library return _ContentItems; } } - internal void RefreshContentItems() + public void RefreshContentItems() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _AllByPrimaryKey[_ContentID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) tmp._ContentItemCount = -1; // This will cause the data to be requeried } private int _ContentPartCount = 0; @@ -302,11 +313,11 @@ namespace VEPROMS.CSLA.Library return _ContentParts; } } - internal void RefreshContentParts() + public void RefreshContentParts() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _AllByPrimaryKey[_ContentID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) tmp._ContentPartCount = -1; // This will cause the data to be requeried } private int _ContentRoUsageCount = 0; @@ -337,11 +348,11 @@ namespace VEPROMS.CSLA.Library return _ContentRoUsages; } } - internal void RefreshContentRoUsages() + public void RefreshContentRoUsages() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _AllByPrimaryKey[_ContentID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) tmp._ContentRoUsageCount = -1; // This will cause the data to be requeried } private int _ContentTransitionCount = 0; @@ -372,11 +383,11 @@ namespace VEPROMS.CSLA.Library return _ContentTransitions; } } - internal void RefreshContentTransitions() + public void RefreshContentTransitions() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _AllByPrimaryKey[_ContentID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) tmp._ContentTransitionCount = -1; // This will cause the data to be requeried } private int _ContentZContentCount = 0; @@ -400,8 +411,11 @@ namespace VEPROMS.CSLA.Library get { CanReadProperty("MyZContent", true); - if (_ContentZContentCount > 0 && _MyZContent == null) + if (_ContentZContentCount != 0 && _MyZContent == null) + { _MyZContent = ZContentInfo.Get(_ContentID); + _ContentZContentCount = _MyZContent == null ? 0 : 1; + } return _MyZContent; } } @@ -426,24 +440,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _ContentInfoUnique = 0; - private int _MyContentInfoUnique; + private static int ContentInfoUnique + { get { return ++_ContentInfoUnique; } } + private int _MyContentInfoUnique = ContentInfoUnique; public int MyContentInfoUnique - { - get { return _MyContentInfoUnique; } - } - private ContentInfo() + { get { return _MyContentInfoUnique; } } + protected ContentInfo() {/* require use of factory methods */ - _MyContentInfoUnique = ++_ContentInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listContentInfo = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items - listContentInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listContentInfo.Contains(this)) listContentInfo.Remove(this); // Remove the item from the list if (listContentInfo.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 Content Get() { @@ -453,18 +466,18 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ContentID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Content tmp) + protected virtual void RefreshFields(Content tmp) { _Number = tmp.Number; _Text = tmp.Text; _Type = tmp.Type; if (_FormatID != tmp.FormatID) { - MyFormat.RefreshFormatContents(); // Update List for old value + if (MyFormat != null) MyFormat.RefreshFormatContents(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list @@ -474,19 +487,21 @@ namespace VEPROMS.CSLA.Library _UserID = tmp.UserID; _ContentInfoExtension.Refresh(this); _MyFormat = null; - _MyEntry = null;// - _MyZContent = null;// + _MyEntry = null;// Reset related value + _ContentEntryCount = -1;// Reset Count + _MyZContent = null;// Reset related value + _ContentZContentCount = -1;// Reset Count OnChange();// raise an event } public static void Refresh(FormatContent tmp) { string key = tmp.ContentID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(FormatContent tmp) + protected virtual void RefreshFields(FormatContent tmp) { _Number = tmp.Number; _Text = tmp.Text; @@ -496,8 +511,10 @@ namespace VEPROMS.CSLA.Library _UserID = tmp.UserID; _ContentInfoExtension.Refresh(this); _MyFormat = null; - _MyEntry = null;// - _MyZContent = null;// + _MyEntry = null;// Reset related value + _ContentEntryCount = -1;// Reset Count + _MyZContent = null;// Reset related value + _ContentZContentCount = -1;// Reset Count OnChange();// raise an event } public static ContentInfo Get(int contentID) @@ -506,13 +523,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Content"); try { - ContentInfo tmp = GetExistingByPrimaryKey(contentID); + ContentInfo 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 ContentInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -524,7 +545,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal ContentInfo(SafeDataReader dr) { - _MyContentInfoUnique = ++_ContentInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs index 4f8081ef..13580ade 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs @@ -84,7 +84,7 @@ namespace VEPROMS.CSLA.Library set { CanWriteProperty("MyPrevious", true); - if (_MyPrevious != value) + if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) { _MyPrevious = value; _PreviousID = (value == null ? null : (int?)value.ItemID);