diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs index e8104cf7..b573ada2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs @@ -64,38 +64,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(Connection connection) + { + if (!_CacheList.Contains(connection)) _CacheList.Add(connection); // In AddToCache + } + protected static void RemoveFromCache(Connection connection) + { + while (_CacheList.Contains(connection)) _CacheList.Remove(connection); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (Connection tmp in _AllList) + foreach (Connection tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.DBID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.DBID.ToString())) { - _AllByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey - _AllByName[tmp.Name.ToString()] = new List(); // Add new list for Name + _CacheByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name } - _AllByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list - _AllByName[tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index remove.Add(tmp); } foreach (Connection tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } - public static Connection GetExistingByPrimaryKey(int dbid) + protected static Connection GetCachedByPrimaryKey(int dbid) { ConvertListToDictionary(); string key = dbid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } - public static Connection GetExistingByName(string name) + protected static Connection 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 @@ -469,28 +477,41 @@ namespace VEPROMS.CSLA.Library public int CurrentEditLevel { get { return EditLevel; } } private static int _ConnectionUnique = 0; - private int _MyConnectionUnique; + protected static int ConnectionUnique + { get { return ++_ConnectionUnique; } } + private int _MyConnectionUnique = ConnectionUnique; public int MyConnectionUnique - { - get { return _MyConnectionUnique; } - } + { get { return _MyConnectionUnique; } } protected Connection() {/* require use of factory methods */ - _MyConnectionUnique = ++_ConnectionUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(DBID.ToString())) return; - List listConnection = _AllByPrimaryKey[DBID.ToString()]; // Get the list of items - listConnection.Remove(this); // Remove the item from the list - if (listConnection.Count == 0) //If there are no items left in the list - _AllByPrimaryKey.Remove(DBID.ToString()); // remove the list - listConnection = _AllByName[DBID.ToString()]; // Get the list of items - listConnection.Remove(this); // Remove the item from the list - if (listConnection.Count == 0) //If there are no items left in the list - _AllByName.Remove(DBID.ToString()); // remove the list + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DBID.ToString())) + { + List listConnection = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items + while (listConnection.Contains(this)) listConnection.Remove(this); // Remove the item from the list + if (listConnection.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DBID.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 listConnection = _CacheByName[myKey]; // Get the list of items + listConnection.Remove(this); // Remove the item from the list + if (listConnection.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } } public static Connection New() { @@ -521,7 +542,11 @@ namespace VEPROMS.CSLA.Library { Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Connection tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -546,7 +571,11 @@ namespace VEPROMS.CSLA.Library { Connection tmp = Connection.New(name, title, connectionString, config); if (tmp.IsSavable) - tmp = tmp.Save(); + { + Connection tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } else { Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); @@ -564,13 +593,17 @@ namespace VEPROMS.CSLA.Library throw new System.Security.SecurityException("User not authorized to view a Connection"); try { - Connection tmp = GetExistingByPrimaryKey(dbid); + Connection tmp = GetCachedByPrimaryKey(dbid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(dbid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Connection + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -578,19 +611,23 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on Connection.Get", ex); } } - private static Connection GetByName(string name) + public static Connection GetByName(string name) { if (!CanGetObject()) throw new System.Security.SecurityException("User not authorized to view a Connection"); try { - Connection tmp = GetExistingByName(name); + Connection 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 Connection + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -632,7 +669,8 @@ namespace VEPROMS.CSLA.Library { BuildRefreshList(); Connection connection = base.Save(); - _AllList.Add(connection);//Refresh the item in AllList + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(connection);//Refresh the item in AllList ProcessRefreshList(); return connection; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs index e77d36a0..26988cde 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs @@ -179,7 +179,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); @@ -187,6 +187,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 { @@ -371,6 +391,8 @@ namespace VEPROMS.CSLA.Library //AuthorizationRules.AllowWrite(ShortName, ""); //AuthorizationRules.AllowRead(FormatID, ""); //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); //AuthorizationRules.AllowRead(Config, ""); //AuthorizationRules.AllowWrite(Config, ""); //AuthorizationRules.AllowRead(DTS, ""); @@ -455,6 +477,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"); @@ -472,7 +495,7 @@ namespace VEPROMS.CSLA.Library // if we're not dirty then don't update the database if (!this.IsDirty) return; SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _Config, _DTS, _UsrID); + _LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID); MarkOld(); } internal void Update(Connection myConnection) @@ -480,7 +503,7 @@ namespace VEPROMS.CSLA.Library // if we're not dirty then don't update the database if (!this.IsDirty) return; SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Folder.Update(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _Config, _DTS, _UsrID, ref _LastChanged); + _LastChanged = Folder.Update(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); MarkOld(); } internal void DeleteSelf(Connection myConnection) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs index a32c53e3..b4c793b5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.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(ConnectionInfo connectionInfo) + { + if (!_CacheList.Contains(connectionInfo)) _CacheList.Add(connectionInfo); // In AddToCache + } + protected static void RemoveFromCache(ConnectionInfo connectionInfo) + { + while (_CacheList.Contains(connectionInfo)) _CacheList.Remove(connectionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { List remove = new List(); - foreach (ConnectionInfo tmp in _AllList) + foreach (ConnectionInfo tmp in _CacheList) { - if (!_AllByPrimaryKey.ContainsKey(tmp.DBID.ToString())) + if (!_CacheByPrimaryKey.ContainsKey(tmp.DBID.ToString())) { - _AllByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey } - _AllByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list remove.Add(tmp); } foreach (ConnectionInfo tmp in remove) - _AllList.Remove(tmp); + RemoveFromCache(tmp); } internal static void AddList(ConnectionInfoList lst) { - foreach (ConnectionInfo item in lst) _AllList.Add(item); + foreach (ConnectionInfo item in lst) AddToCache(item); } - public static ConnectionInfo GetExistingByPrimaryKey(int dbid) + protected static ConnectionInfo GetCachedByPrimaryKey(int dbid) { ConvertListToDictionary(); string key = dbid.ToString(); - if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; return null; } #endregion @@ -194,11 +202,11 @@ namespace VEPROMS.CSLA.Library return _ConnectionFolders; } } - internal void RefreshConnectionFolders() + public void RefreshConnectionFolders() { ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(_DBID.ToString())) - foreach (ConnectionInfo tmp in _AllByPrimaryKey[_DBID.ToString()]) + if (_CacheByPrimaryKey.ContainsKey(_DBID.ToString())) + foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()]) tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried } // TODO: Replace base ConnectionInfo.ToString function as necessary @@ -222,24 +230,23 @@ namespace VEPROMS.CSLA.Library #endregion #region Factory Methods private static int _ConnectionInfoUnique = 0; - private int _MyConnectionInfoUnique; + private static int ConnectionInfoUnique + { get { return ++_ConnectionInfoUnique; } } + private int _MyConnectionInfoUnique = ConnectionInfoUnique; public int MyConnectionInfoUnique - { - get { return _MyConnectionInfoUnique; } - } - private ConnectionInfo() + { get { return _MyConnectionInfoUnique; } } + protected ConnectionInfo() {/* require use of factory methods */ - _MyConnectionInfoUnique = ++_ConnectionInfoUnique; - _AllList.Add(this); + AddToCache(this); } public void Dispose() { - _AllList.Remove(this); - if (!_AllByPrimaryKey.ContainsKey(DBID.ToString())) return; - List listConnectionInfo = _AllByPrimaryKey[DBID.ToString()]; // Get the list of items - listConnectionInfo.Remove(this); // Remove the item from the list + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DBID.ToString())) return; + List listConnectionInfo = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items + while (listConnectionInfo.Contains(this)) listConnectionInfo.Remove(this); // Remove the item from the list if (listConnectionInfo.Count == 0) // If there are no items left in the list - _AllByPrimaryKey.Remove(DBID.ToString()); // remove the list + _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list } public virtual Connection Get() { @@ -249,11 +256,11 @@ namespace VEPROMS.CSLA.Library { string key = tmp.DBID.ToString(); ConvertListToDictionary(); - if (_AllByPrimaryKey.ContainsKey(key)) - foreach (ConnectionInfo tmpInfo in _AllByPrimaryKey[key]) + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ConnectionInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - private void RefreshFields(Connection tmp) + protected virtual void RefreshFields(Connection tmp) { _Name = tmp.Name; _Title = tmp.Title; @@ -271,13 +278,17 @@ namespace VEPROMS.CSLA.Library // throw new System.Security.SecurityException("User not authorized to view a Connection"); try { - ConnectionInfo tmp = GetExistingByPrimaryKey(dbid); + ConnectionInfo tmp = GetCachedByPrimaryKey(dbid); if (tmp == null) { tmp = DataPortal.Fetch(new PKCriteria(dbid)); - if (!_AllList.Contains(tmp)) _AllList.Add(tmp); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ConnectionInfo + tmp = null; } - if (tmp.ErrorMessage == "No Record Found") tmp = null; return tmp; } catch (Exception ex) @@ -289,7 +300,6 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal internal ConnectionInfo(SafeDataReader dr) { - _MyConnectionInfoUnique = ++_ConnectionInfoUnique; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode()); try {