diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs index 3215b47f..ff3397f4 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.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(DocVersion docVersion) + { + if (!_CacheList.Contains(docVersion)) _CacheList.Add(docVersion); // In AddToCache + } + protected static void RemoveFromCache(DocVersion docVersion) + { + while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (DocVersion tmp in _AllList) + foreach (DocVersion tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) { - _AllByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (DocVersion tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static DocVersion GetExistingByPrimaryKey(int versionID) + protected static DocVersion GetCachedByPrimaryKey(int versionID) { ConvertListToDictionary(); string key = versionID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -223,7 +231,7 @@ namespace VEPROMS.CSLA.Library set { CanWriteProperty("MyItem", true); - if (_MyItem != value) + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) { _MyItem = value; _ItemID = (value == null ? null : (int?)value.ItemID); @@ -256,7 +264,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); @@ -497,24 +505,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _DocVersionUnique = 0; - private int _MyDocVersionUnique; + protected static int DocVersionUnique + { get { return ++_DocVersionUnique; } } + private int _MyDocVersionUnique = DocVersionUnique; public int MyDocVersionUnique - { - get { return _MyDocVersionUnique; } - } + { get { return _MyDocVersionUnique; } } protected DocVersion() {/* require use of factory methods */ - _MyDocVersionUnique = ++_DocVersionUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(VersionID.ToString())) return; - List listDocVersion = _AllByPrimaryKey[VersionID.ToString()]; // Get the list of items - listDocVersion.Remove(this); // Remove the item from the list - if (listDocVersion.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(VersionID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) + { + List listDocVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listDocVersion.Contains(this)) listDocVersion.Remove(this); // Remove the item from the list + if (listDocVersion.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } } public static DocVersion New() { @@ -554,7 +567,11 @@ namespace VEPROMS.CSLA.Library { DocVersion tmp = DocVersion.New(myFolder, versionType, name, title, myItem, myFormat, config, dts, userID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + DocVersion tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -581,7 +598,11 @@ namespace VEPROMS.CSLA.Library { DocVersion tmp = DocVersion.New(myFolder, name, title, myItem, myFormat, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + DocVersion tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -599,13 +620,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a DocVersion"); try { - DocVersion tmp = GetExistingByPrimaryKey(versionID); + DocVersion tmp = GetCachedByPrimaryKey(versionID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(versionID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersion + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -647,7 +672,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); DocVersion docVersion = base.Save(); - _AllList.Add(docVersion);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(docVersion);//Refresh the item in AllList ProcessRefreshList(); return docVersion; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs index dddea2d3..b0c100e1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.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(DocVersionInfo docVersionInfo) + { + if (!_CacheList.Contains(docVersionInfo)) _CacheList.Add(docVersionInfo); // In AddToCache + } + protected static void RemoveFromCache(DocVersionInfo docVersionInfo) + { + while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (DocVersionInfo tmp in _AllList) + foreach (DocVersionInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) { - _AllByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (DocVersionInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(DocVersionInfoList lst) { - foreach (DocVersionInfo item in lst) _AllList.Add(item); + foreach (DocVersionInfo item in lst) AddToCache(item); } - public static DocVersionInfo GetExistingByPrimaryKey(int versionID) + protected static DocVersionInfo GetCachedByPrimaryKey(int versionID) { ConvertListToDictionary(); string key = versionID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -243,24 +251,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _DocVersionInfoUnique = 0; - private int _MyDocVersionInfoUnique; + private static int DocVersionInfoUnique + { get { return ++_DocVersionInfoUnique; } } + private int _MyDocVersionInfoUnique = DocVersionInfoUnique; public int MyDocVersionInfoUnique - { - get { return _MyDocVersionInfoUnique; } - } - private DocVersionInfo() + { get { return _MyDocVersionInfoUnique; } } + protected DocVersionInfo() {/* require use of factory methods */ - _MyDocVersionInfoUnique = ++_DocVersionInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(VersionID.ToString())) return; - List listDocVersionInfo = _AllByPrimaryKey[VersionID.ToString()]; // Get the list of items - listDocVersionInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; + List listDocVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listDocVersionInfo.Contains(this)) listDocVersionInfo.Remove(this); // Remove the item from the list if (listDocVersionInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(VersionID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list } public virtual DocVersion Get() { @@ -270,15 +277,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.VersionID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(DocVersion tmp) + protected virtual void RefreshFields(DocVersion tmp) { if (_FolderID != tmp.FolderID) { - MyFolder.RefreshFolderDocVersions(); // Update List for old value + if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value _FolderID = tmp.FolderID; // Update the value } _MyFolder = null; // Reset list so that the next line gets a new list @@ -288,14 +295,14 @@ namespace VEPROMS.CSLA.Library _Title = tmp.Title; if (_ItemID != tmp.ItemID) { - MyItem.RefreshItemDocVersions(); // Update List for old value + if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value if (_FormatID != tmp.FormatID) { - MyFormat.RefreshFormatDocVersions(); // Update List for old value + if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list @@ -313,25 +320,25 @@ namespace VEPROMS.CSLA.Library { string key = tmp.VersionID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(FolderDocVersion tmp) + protected virtual void RefreshFields(FolderDocVersion tmp) { _VersionType = tmp.VersionType; _Name = tmp.Name; _Title = tmp.Title; if (_ItemID != tmp.ItemID) { - MyItem.RefreshItemDocVersions(); // Update List for old value + if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value if (_FormatID != tmp.FormatID) { - MyFormat.RefreshFormatDocVersions(); // Update List for old value + if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list @@ -349,15 +356,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.VersionID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(FormatDocVersion tmp) + protected virtual void RefreshFields(FormatDocVersion tmp) { if (_FolderID != tmp.FolderID) { - MyFolder.RefreshFolderDocVersions(); // Update List for old value + if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value _FolderID = tmp.FolderID; // Update the value } _MyFolder = null; // Reset list so that the next line gets a new list @@ -367,7 +374,7 @@ namespace VEPROMS.CSLA.Library _Title = tmp.Title; if (_ItemID != tmp.ItemID) { - MyItem.RefreshItemDocVersions(); // Update List for old value + if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list @@ -385,15 +392,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.VersionID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ItemDocVersion tmp) + protected virtual void RefreshFields(ItemDocVersion tmp) { if (_FolderID != tmp.FolderID) { - MyFolder.RefreshFolderDocVersions(); // Update List for old value + if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value _FolderID = tmp.FolderID; // Update the value } _MyFolder = null; // Reset list so that the next line gets a new list @@ -403,7 +410,7 @@ namespace VEPROMS.CSLA.Library _Title = tmp.Title; if (_FormatID != tmp.FormatID) { - MyFormat.RefreshFormatDocVersions(); // Update List for old value + if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list @@ -423,13 +430,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a DocVersion"); try { - DocVersionInfo tmp = GetExistingByPrimaryKey(versionID); + DocVersionInfo tmp = GetCachedByPrimaryKey(versionID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(versionID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersionInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -441,7 +452,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal DocVersionInfo(SafeDataReader dr) { - _MyDocVersionInfoUnique = ++_DocVersionInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs index ff2a1df5..11d99026 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Entry.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(Entry entry) + { + if (!_CacheList.Contains(entry)) _CacheList.Add(entry); // In AddToCache + } + protected static void RemoveFromCache(Entry entry) + { + while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Entry tmp in _AllList) + foreach (Entry 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 (Entry tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Entry GetExistingByPrimaryKey(int contentID) + protected static Entry 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 @@ -326,24 +334,29 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _EntryUnique = 0; - private int _MyEntryUnique; + protected static int EntryUnique + { get { return ++_EntryUnique; } } + private int _MyEntryUnique = EntryUnique; public int MyEntryUnique - { - get { return _MyEntryUnique; } - } + { get { return _MyEntryUnique; } } protected Entry() {/* require use of factory methods */ - _MyEntryUnique = ++_EntryUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listEntry = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items - listEntry.Remove(this); // Remove the item from the list - if (listEntry.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 listEntry = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listEntry.Contains(this)) listEntry.Remove(this); // Remove the item from the list + if (listEntry.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } } public static Entry New() { @@ -365,6 +378,26 @@ namespace VEPROMS.CSLA.Library tmp.MyDocument = myDocument; return tmp; } + public static Entry MakeEntry(Content myContent, Document myDocument) + { + Entry tmp = Entry.New(myContent, myDocument); + if (tmp.IsSavable) + { + Entry 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 Entry New(Content myContent, Document myDocument, DateTime dts, string userID) { Entry tmp = Entry.New(); @@ -378,7 +411,11 @@ namespace VEPROMS.CSLA.Library { Entry tmp = Entry.New(myContent, myDocument, dts, userID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Entry tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -404,13 +441,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Entry"); try { - Entry tmp = GetExistingByPrimaryKey(contentID); + Entry 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 Entry + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -452,7 +493,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Entry entry = base.Save(); - _AllList.Add(entry);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(entry);//Refresh the item in AllList ProcessRefreshList(); return entry; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs index 2d5dae3c..d16882ea 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.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(EntryInfo entryInfo) + { + if (!_CacheList.Contains(entryInfo)) _CacheList.Add(entryInfo); // In AddToCache + } + protected static void RemoveFromCache(EntryInfo entryInfo) + { + while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (EntryInfo tmp in _AllList) + foreach (EntryInfo 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 (EntryInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(EntryInfoList lst) { - foreach (EntryInfo item in lst) _AllList.Add(item); + foreach (EntryInfo item in lst) AddToCache(item); } - public static EntryInfo GetExistingByPrimaryKey(int contentID) + protected static EntryInfo 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 @@ -169,24 +177,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _EntryInfoUnique = 0; - private int _MyEntryInfoUnique; + private static int EntryInfoUnique + { get { return ++_EntryInfoUnique; } } + private int _MyEntryInfoUnique = EntryInfoUnique; public int MyEntryInfoUnique - { - get { return _MyEntryInfoUnique; } - } - private EntryInfo() + { get { return _MyEntryInfoUnique; } } + protected EntryInfo() {/* require use of factory methods */ - _MyEntryInfoUnique = ++_EntryInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listEntryInfo = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items - listEntryInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listEntryInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listEntryInfo.Contains(this)) listEntryInfo.Remove(this); // Remove the item from the list if (listEntryInfo.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 Entry Get() { @@ -196,15 +203,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ContentID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (EntryInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Entry tmp) + protected virtual void RefreshFields(Entry tmp) { if (_DocID != tmp.DocID) { - MyDocument.RefreshDocumentEntries(); // Update List for old value + if (MyDocument != null) MyDocument.RefreshDocumentEntries(); // Update List for old value _DocID = tmp.DocID; // Update the value } _MyDocument = null; // Reset list so that the next line gets a new list @@ -220,11 +227,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.ContentID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (EntryInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(DocumentEntry tmp) + protected virtual void RefreshFields(DocumentEntry tmp) { _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -239,15 +246,16 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Entry"); try { - EntryInfo tmp = GetExistingByPrimaryKey(contentID); + EntryInfo 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 EntryInfo + tmp = null; } return tmp; } @@ -260,7 +268,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal EntryInfo(SafeDataReader dr) { - _MyEntryInfoUnique = ++_EntryInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.Constructor", GetHashCode()); try { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs index 6e64588d..db5a4c6e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs @@ -86,38 +86,46 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); - private static Dictionary> _AllByParentID_Name = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(Folder folder) + { + if (!_CacheList.Contains(folder)) _CacheList.Add(folder); // In AddToCache + } + protected static void RemoveFromCache(Folder folder) + { + while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByParentID_Name = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Folder tmp in _AllList) + foreach (Folder tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) { - _AllByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey - _AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name + _CacheByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name } - _AllByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list - _AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index remove.Add(tmp); } foreach (Folder tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Folder GetExistingByPrimaryKey(int folderID) + protected static Folder GetCachedByPrimaryKey(int folderID) { ConvertListToDictionary(); string key = folderID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } - public static Folder GetExistingByParentID_Name(int parentID, string name) + protected static Folder GetCachedByParentID_Name(int parentID, string name) { ConvertListToDictionary(); string key = parentID.ToString() + "_" + name.ToString(); - if (_AllByParentID_Name.ContainsKey(key)) return _AllByParentID_Name[key][0]; + if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; return null; } #endregion @@ -295,7 +303,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); @@ -303,6 +311,26 @@ namespace VEPROMS.CSLA.Library } } } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ManualOrder", true); + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ManualOrder", true); + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } private string _Config = string.Empty; public string Config { @@ -586,6 +614,7 @@ namespace VEPROMS.CSLA.Library //AuthorizationRules.AllowRead(Title, ""); //AuthorizationRules.AllowRead(ShortName, ""); //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); //AuthorizationRules.AllowRead(Config, ""); //AuthorizationRules.AllowRead(DTS, ""); //AuthorizationRules.AllowRead(UsrID, ""); @@ -595,6 +624,7 @@ namespace VEPROMS.CSLA.Library //AuthorizationRules.AllowWrite(Title, ""); //AuthorizationRules.AllowWrite(ShortName, ""); //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); //AuthorizationRules.AllowWrite(Config, ""); //AuthorizationRules.AllowWrite(DTS, ""); //AuthorizationRules.AllowWrite(UsrID, ""); @@ -651,28 +681,41 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _FolderUnique = 0; - private int _MyFolderUnique; + protected static int FolderUnique + { get { return ++_FolderUnique; } } + private int _MyFolderUnique = FolderUnique; public int MyFolderUnique - { - get { return _MyFolderUnique; } - } + { get { return _MyFolderUnique; } } protected Folder() {/* require use of factory methods */ - _MyFolderUnique = ++_FolderUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(FolderID.ToString())) return; - List listFolder = _AllByPrimaryKey[FolderID.ToString()]; // Get the list of items - listFolder.Remove(this); // Remove the item from the list - if (listFolder.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(FolderID.ToString()); // remove the list - listFolder = _AllByParentID_Name[FolderID.ToString()]; // Get the list of items - listFolder.Remove(this); // Remove the item from the list - if (listFolder.Count == 0) //If there are no items left in the list - _AllByParentID_Name.Remove(FolderID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) + { + List listFolder = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items + while (listFolder.Contains(this)) listFolder.Remove(this); // Remove the item from the list + if (listFolder.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByParentID_Name.Keys) + if (_CacheByParentID_Name[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listFolder = _CacheByParentID_Name[myKey]; // Get the list of items + listFolder.Remove(this); // Remove the item from the list + if (listFolder.Count == 0) //If there are no items left in the list + _CacheByParentID_Name.Remove(myKey); // remove the list + } } public static Folder New() { @@ -695,7 +738,7 @@ namespace VEPROMS.CSLA.Library tmp.ShortName = shortName; return tmp; } - public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID) + public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) { Folder tmp = Folder.New(); tmp.MyParent = myParent; @@ -704,16 +747,21 @@ namespace VEPROMS.CSLA.Library tmp.Title = title; tmp.ShortName = shortName; tmp.MyFormat = myFormat; + tmp.ManualOrder = manualOrder; tmp.Config = config; tmp.DTS = dts; tmp.UsrID = usrID; return tmp; } - public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID) + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) { - Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, config, dts, usrID); + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config, dts, usrID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Folder tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -725,7 +773,7 @@ namespace VEPROMS.CSLA.Library } return tmp; } - public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config) + public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) { Folder tmp = Folder.New(); tmp.MyParent = myParent; @@ -734,14 +782,19 @@ namespace VEPROMS.CSLA.Library tmp.Title = title; tmp.ShortName = shortName; tmp.MyFormat = myFormat; + tmp.ManualOrder = manualOrder; tmp.Config = config; return tmp; } - public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config) + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) { - Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, config); + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Folder tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -759,13 +812,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Folder"); try { - Folder tmp = GetExistingByPrimaryKey(folderID); + Folder tmp = GetCachedByPrimaryKey(folderID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(folderID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Folder + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -773,19 +830,23 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on Folder.Get", ex); } } - private static Folder GetByParentID_Name(int parentID, string name) + public static Folder GetByParentID_Name(int parentID, string name) { if (!CanGetObject()) throw new System.Security.SecurityException("User not authorized to view a Folder"); try { - Folder tmp = GetExistingByParentID_Name(parentID, name); + Folder tmp = GetCachedByParentID_Name(parentID, name); if (tmp == null) { tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Folder + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -837,7 +898,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Folder folder = base.Save(); - _AllList.Add(folder);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(folder);//Refresh the item in AllList ProcessRefreshList(); return folder; } @@ -899,6 +961,7 @@ namespace VEPROMS.CSLA.Library _Title = dr.GetString("Title"); _ShortName = dr.GetString("ShortName"); _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); _Config = dr.GetString("Config"); _DTS = dr.GetDateTime("DTS"); _UsrID = dr.GetString("UsrID"); @@ -1037,6 +1100,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Title", _Title); cm.Parameters.AddWithValue("@ShortName", _ShortName); cm.Parameters.AddWithValue("@FormatID", FormatID); + cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder); cm.Parameters.AddWithValue("@Config", _Config); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@UsrID", _UsrID); @@ -1068,7 +1132,7 @@ namespace VEPROMS.CSLA.Library } } [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID) + public static byte[] Add(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Add", 0); try @@ -1084,6 +1148,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Title", title); cm.Parameters.AddWithValue("@ShortName", shortName); if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.FormatID); + cm.Parameters.AddWithValue("@ManualOrder", manualOrder); cm.Parameters.AddWithValue("@Config", config); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UsrID", usrID); @@ -1154,6 +1219,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Title", _Title); cm.Parameters.AddWithValue("@ShortName", _ShortName); cm.Parameters.AddWithValue("@FormatID", FormatID); + cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder); cm.Parameters.AddWithValue("@Config", _Config); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@UsrID", _UsrID); @@ -1188,9 +1254,9 @@ namespace VEPROMS.CSLA.Library { SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; if (IsNew) - _LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _Config, _DTS, _UsrID); + _LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID); else - _LastChanged = Folder.Update(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _Config, _DTS, _UsrID, ref _LastChanged); + _LastChanged = Folder.Update(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); MarkOld(); } if (_FolderAssignments != null) _FolderAssignments.Update(this); @@ -1208,7 +1274,7 @@ namespace VEPROMS.CSLA.Library MarkNew(); } [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID, ref byte[] lastChanged) + public static byte[] Update(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID, ref byte[] lastChanged) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Update", 0); try @@ -1225,6 +1291,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Title", title); cm.Parameters.AddWithValue("@ShortName", shortName); if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.FormatID); + cm.Parameters.AddWithValue("@ManualOrder", manualOrder); cm.Parameters.AddWithValue("@Config", config); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UsrID", usrID); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs index 9f22af30..733f6aff 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs @@ -149,7 +149,7 @@ namespace VEPROMS.CSLA.Library set { CanWriteProperty("MyItem", true); - if (_MyItem != value) + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) { _MyItem = value; _ItemID = (value == null ? null : (int?)value.ItemID); @@ -182,7 +182,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); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs index 581ea051..45426054 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.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(FolderInfo folderInfo) + { + if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache + } + protected static void RemoveFromCache(FolderInfo folderInfo) + { + while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (FolderInfo tmp in _AllList) + foreach (FolderInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) { - _AllByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (FolderInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(FolderInfoList lst) { - foreach (FolderInfo item in lst) _AllList.Add(item); + foreach (FolderInfo item in lst) AddToCache(item); } - public static FolderInfo GetExistingByPrimaryKey(int folderID) + protected static FolderInfo GetCachedByPrimaryKey(int folderID) { ConvertListToDictionary(); string key = folderID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -189,6 +197,16 @@ namespace VEPROMS.CSLA.Library return _MyFormat; } } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ManualOrder", true); + return _ManualOrder; + } + } private string _Config = string.Empty; public string Config { @@ -247,11 +265,11 @@ namespace VEPROMS.CSLA.Library return _FolderAssignments; } } - internal void RefreshFolderAssignments() + public void RefreshFolderAssignments() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _AllByPrimaryKey[_FolderID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried } private int _FolderDocVersionCount = 0; @@ -282,11 +300,11 @@ namespace VEPROMS.CSLA.Library return _FolderDocVersions; } } - internal void RefreshFolderDocVersions() + public void RefreshFolderDocVersions() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _AllByPrimaryKey[_FolderID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried } private int _ChildFolderCount = 0; @@ -317,11 +335,11 @@ namespace VEPROMS.CSLA.Library return _ChildFolders; } } - internal void RefreshChildFolders() + public void RefreshChildFolders() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _AllByPrimaryKey[_FolderID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) tmp._ChildFolderCount = -1; // This will cause the data to be requeried } // TODO: Replace base FolderInfo.ToString function as necessary @@ -345,24 +363,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _FolderInfoUnique = 0; - private int _MyFolderInfoUnique; + private static int FolderInfoUnique + { get { return ++_FolderInfoUnique; } } + private int _MyFolderInfoUnique = FolderInfoUnique; public int MyFolderInfoUnique - { - get { return _MyFolderInfoUnique; } - } - private FolderInfo() + { get { return _MyFolderInfoUnique; } } + protected FolderInfo() {/* require use of factory methods */ - _MyFolderInfoUnique = ++_FolderInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(FolderID.ToString())) return; - List listFolderInfo = _AllByPrimaryKey[FolderID.ToString()]; // Get the list of items - listFolderInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return; + List listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items + while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list if (listFolderInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(FolderID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list } public virtual Folder Get() { @@ -372,22 +389,22 @@ namespace VEPROMS.CSLA.Library { string key = tmp.FolderID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Folder tmp) + protected virtual void RefreshFields(Folder tmp) { if (_ParentID != tmp.ParentID) { - MyParent.RefreshChildFolders(); // Update List for old value + if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value _ParentID = tmp.ParentID; // Update the value } _MyParent = null; // Reset list so that the next line gets a new list if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value if (_DBID != tmp.DBID) { - MyConnection.RefreshConnectionFolders(); // Update List for old value + if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value _DBID = tmp.DBID; // Update the value } _MyConnection = null; // Reset list so that the next line gets a new list @@ -397,11 +414,12 @@ namespace VEPROMS.CSLA.Library _ShortName = tmp.ShortName; if (_FormatID != tmp.FormatID) { - MyFormat.RefreshFormatFolders(); // Update List for old value + if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value + _ManualOrder = tmp.ManualOrder; _Config = tmp.Config; _DTS = tmp.DTS; _UsrID = tmp.UsrID; @@ -415,15 +433,15 @@ namespace VEPROMS.CSLA.Library { string key = tmp.FolderID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(ConnectionFolder tmp) + protected virtual void RefreshFields(ConnectionFolder tmp) { if (_ParentID != tmp.ParentID) { - MyParent.RefreshChildFolders(); // Update List for old value + if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value _ParentID = tmp.ParentID; // Update the value } _MyParent = null; // Reset list so that the next line gets a new list @@ -433,11 +451,12 @@ namespace VEPROMS.CSLA.Library _ShortName = tmp.ShortName; if (_FormatID != tmp.FormatID) { - MyFormat.RefreshFormatFolders(); // Update List for old value + if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value + _ManualOrder = tmp.ManualOrder; _Config = tmp.Config; _DTS = tmp.DTS; _UsrID = tmp.UsrID; @@ -451,22 +470,22 @@ namespace VEPROMS.CSLA.Library { string key = tmp.FolderID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(FormatFolder tmp) + protected virtual void RefreshFields(FormatFolder tmp) { if (_ParentID != tmp.ParentID) { - MyParent.RefreshChildFolders(); // Update List for old value + if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value _ParentID = tmp.ParentID; // Update the value } _MyParent = null; // Reset list so that the next line gets a new list if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value if (_DBID != tmp.DBID) { - MyConnection.RefreshConnectionFolders(); // Update List for old value + if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value _DBID = tmp.DBID; // Update the value } _MyConnection = null; // Reset list so that the next line gets a new list @@ -474,6 +493,7 @@ namespace VEPROMS.CSLA.Library _Name = tmp.Name; _Title = tmp.Title; _ShortName = tmp.ShortName; + _ManualOrder = tmp.ManualOrder; _Config = tmp.Config; _DTS = tmp.DTS; _UsrID = tmp.UsrID; @@ -489,13 +509,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Folder"); try { - FolderInfo tmp = GetExistingByPrimaryKey(folderID); + FolderInfo tmp = GetCachedByPrimaryKey(folderID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(folderID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FolderInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -507,7 +531,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal FolderInfo(SafeDataReader dr) { - _MyFolderInfoUnique = ++_FolderInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode()); try { @@ -542,6 +565,7 @@ namespace VEPROMS.CSLA.Library _Title = dr.GetString("Title"); _ShortName = dr.GetString("ShortName"); _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); _Config = dr.GetString("Config"); _DTS = dr.GetDateTime("DTS"); _UsrID = dr.GetString("UsrID"); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs index e27da111..c57d1137 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs @@ -97,38 +97,46 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection - protected static List _AllList = new List(); - private static Dictionary> _AllByPrimaryKey = new Dictionary>(); - private static Dictionary> _AllByParentID_Name = new Dictionary>(); + private static List _CacheList = new List(); + protected static void AddToCache(Format format) + { + if (!_CacheList.Contains(format)) _CacheList.Add(format); // In AddToCache + } + protected static void RemoveFromCache(Format format) + { + while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByParentID_Name = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Format tmp in _AllList) + foreach (Format tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.FormatID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString())) { - _AllByPrimaryKey[tmp.FormatID.ToString()] = new List(); // Add new list for PrimaryKey - _AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name + _CacheByPrimaryKey[tmp.FormatID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name } - _AllByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list - _AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index remove.Add(tmp); } foreach (Format tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Format GetExistingByPrimaryKey(int formatID) + protected static Format GetCachedByPrimaryKey(int formatID) { ConvertListToDictionary(); string key = formatID.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } - public static Format GetExistingByParentID_Name(int parentID, string name) + protected static Format GetCachedByParentID_Name(int parentID, string name) { ConvertListToDictionary(); string key = parentID.ToString() + "_" + name.ToString(); - if (_AllByParentID_Name.ContainsKey(key)) return _AllByParentID_Name[key][0]; + if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; return null; } #endregion @@ -614,28 +622,41 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _FormatUnique = 0; - private int _MyFormatUnique; + protected static int FormatUnique + { get { return ++_FormatUnique; } } + private int _MyFormatUnique = FormatUnique; public int MyFormatUnique - { - get { return _MyFormatUnique; } - } + { get { return _MyFormatUnique; } } protected Format() {/* require use of factory methods */ - _MyFormatUnique = ++_FormatUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(FormatID.ToString())) return; - List listFormat = _AllByPrimaryKey[FormatID.ToString()]; // Get the list of items - listFormat.Remove(this); // Remove the item from the list - if (listFormat.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(FormatID.ToString()); // remove the list - listFormat = _AllByParentID_Name[FormatID.ToString()]; // Get the list of items - listFormat.Remove(this); // Remove the item from the list - if (listFormat.Count == 0) //If there are no items left in the list - _AllByParentID_Name.Remove(FormatID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) + { + List listFormat = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items + while (listFormat.Contains(this)) listFormat.Remove(this); // Remove the item from the list + if (listFormat.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByParentID_Name.Keys) + if (_CacheByParentID_Name[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listFormat = _CacheByParentID_Name[myKey]; // Get the list of items + listFormat.Remove(this); // Remove the item from the list + if (listFormat.Count == 0) //If there are no items left in the list + _CacheByParentID_Name.Remove(myKey); // remove the list + } } public static Format New() { @@ -674,7 +695,11 @@ namespace VEPROMS.CSLA.Library { Format tmp = Format.New(myParent, name, description, data, genMac, dts, userID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Format tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -700,7 +725,11 @@ namespace VEPROMS.CSLA.Library { Format tmp = Format.New(myParent, name, description, data, genMac); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Format tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -718,13 +747,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Format"); try { - Format tmp = GetExistingByPrimaryKey(formatID); + Format tmp = GetCachedByPrimaryKey(formatID); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(formatID)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Format + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -732,19 +765,23 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on Format.Get", ex); } } - private static Format GetByParentID_Name(int parentID, string name) + public static Format GetByParentID_Name(int parentID, string name) { if (!CanGetObject()) throw new System.Security.SecurityException("User not authorized to view a Format"); try { - Format tmp = GetExistingByParentID_Name(parentID, name); + Format tmp = GetCachedByParentID_Name(parentID, name); if (tmp == null) { tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Format + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -796,7 +833,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Format format = base.Save(); - _AllList.Add(format);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(format);//Refresh the item in AllList ProcessRefreshList(); return format; }