This commit is contained in:
parent
d0dba2aad4
commit
0c505e9455
@ -64,38 +64,46 @@ namespace VEPROMS.CSLA.Library
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region Collection
|
#region Collection
|
||||||
protected static List<Connection> _AllList = new List<Connection>();
|
private static List<Connection> _CacheList = new List<Connection>();
|
||||||
private static Dictionary<string, List<Connection>> _AllByPrimaryKey = new Dictionary<string, List<Connection>>();
|
protected static void AddToCache(Connection connection)
|
||||||
private static Dictionary<string, List<Connection>> _AllByName = new Dictionary<string, List<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<string, List<Connection>> _CacheByPrimaryKey = new Dictionary<string, List<Connection>>();
|
||||||
|
private static Dictionary<string, List<Connection>> _CacheByName = new Dictionary<string, List<Connection>>();
|
||||||
private static void ConvertListToDictionary()
|
private static void ConvertListToDictionary()
|
||||||
{
|
{
|
||||||
List<Connection> remove = new List<Connection>();
|
List<Connection> remove = new List<Connection>();
|
||||||
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<Connection>(); // Add new list for PrimaryKey
|
_CacheByPrimaryKey[tmp.DBID.ToString()] = new List<Connection>(); // Add new list for PrimaryKey
|
||||||
_AllByName[tmp.Name.ToString()] = new List<Connection>(); // Add new list for Name
|
_CacheByName[tmp.Name.ToString()] = new List<Connection>(); // Add new list for Name
|
||||||
}
|
}
|
||||||
_AllByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list
|
_CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list
|
||||||
_AllByName[tmp.Name.ToString()].Add(tmp); // Unique Index
|
_CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||||
remove.Add(tmp);
|
remove.Add(tmp);
|
||||||
}
|
}
|
||||||
foreach (Connection tmp in remove)
|
foreach (Connection tmp in remove)
|
||||||
_AllList.Remove(tmp);
|
RemoveFromCache(tmp);
|
||||||
}
|
}
|
||||||
public static Connection GetExistingByPrimaryKey(int dbid)
|
protected static Connection GetCachedByPrimaryKey(int dbid)
|
||||||
{
|
{
|
||||||
ConvertListToDictionary();
|
ConvertListToDictionary();
|
||||||
string key = dbid.ToString();
|
string key = dbid.ToString();
|
||||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public static Connection GetExistingByName(string name)
|
protected static Connection GetCachedByName(string name)
|
||||||
{
|
{
|
||||||
ConvertListToDictionary();
|
ConvertListToDictionary();
|
||||||
string key = name.ToString();
|
string key = name.ToString();
|
||||||
if (_AllByName.ContainsKey(key)) return _AllByName[key][0];
|
if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -469,28 +477,41 @@ namespace VEPROMS.CSLA.Library
|
|||||||
public int CurrentEditLevel
|
public int CurrentEditLevel
|
||||||
{ get { return EditLevel; } }
|
{ get { return EditLevel; } }
|
||||||
private static int _ConnectionUnique = 0;
|
private static int _ConnectionUnique = 0;
|
||||||
private int _MyConnectionUnique;
|
protected static int ConnectionUnique
|
||||||
|
{ get { return ++_ConnectionUnique; } }
|
||||||
|
private int _MyConnectionUnique = ConnectionUnique;
|
||||||
public int MyConnectionUnique
|
public int MyConnectionUnique
|
||||||
{
|
{ get { return _MyConnectionUnique; } }
|
||||||
get { return _MyConnectionUnique; }
|
|
||||||
}
|
|
||||||
protected Connection()
|
protected Connection()
|
||||||
{/* require use of factory methods */
|
{/* require use of factory methods */
|
||||||
_MyConnectionUnique = ++_ConnectionUnique;
|
AddToCache(this);
|
||||||
_AllList.Add(this);
|
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_AllList.Remove(this);
|
RemoveFromDictionaries();
|
||||||
if (!_AllByPrimaryKey.ContainsKey(DBID.ToString())) return;
|
}
|
||||||
List<Connection> listConnection = _AllByPrimaryKey[DBID.ToString()]; // Get the list of items
|
private void RemoveFromDictionaries()
|
||||||
|
{
|
||||||
|
RemoveFromCache(this);
|
||||||
|
if (_CacheByPrimaryKey.ContainsKey(DBID.ToString()))
|
||||||
|
{
|
||||||
|
List<Connection> 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<Connection> listConnection = _CacheByName[myKey]; // Get the list of items
|
||||||
listConnection.Remove(this); // Remove the item from the list
|
listConnection.Remove(this); // Remove the item from the list
|
||||||
if (listConnection.Count == 0) //If there are no items left in the list
|
if (listConnection.Count == 0) //If there are no items left in the list
|
||||||
_AllByPrimaryKey.Remove(DBID.ToString()); // remove the list
|
_CacheByName.Remove(myKey); // 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
|
|
||||||
}
|
}
|
||||||
public static Connection New()
|
public static Connection New()
|
||||||
{
|
{
|
||||||
@ -521,7 +542,11 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID);
|
Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID);
|
||||||
if (tmp.IsSavable)
|
if (tmp.IsSavable)
|
||||||
tmp = tmp.Save();
|
{
|
||||||
|
Connection tmp2 = tmp;
|
||||||
|
tmp = tmp2.Save();
|
||||||
|
tmp2.Dispose();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||||
@ -546,7 +571,11 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
Connection tmp = Connection.New(name, title, connectionString, config);
|
Connection tmp = Connection.New(name, title, connectionString, config);
|
||||||
if (tmp.IsSavable)
|
if (tmp.IsSavable)
|
||||||
tmp = tmp.Save();
|
{
|
||||||
|
Connection tmp2 = tmp;
|
||||||
|
tmp = tmp2.Save();
|
||||||
|
tmp2.Dispose();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
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");
|
throw new System.Security.SecurityException("User not authorized to view a Connection");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Connection tmp = GetExistingByPrimaryKey(dbid);
|
Connection tmp = GetCachedByPrimaryKey(dbid);
|
||||||
if (tmp == null)
|
if (tmp == null)
|
||||||
{
|
{
|
||||||
tmp = DataPortal.Fetch<Connection>(new PKCriteria(dbid));
|
tmp = DataPortal.Fetch<Connection>(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;
|
return tmp;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -578,19 +611,23 @@ namespace VEPROMS.CSLA.Library
|
|||||||
throw new DbCslaException("Error on Connection.Get", ex);
|
throw new DbCslaException("Error on Connection.Get", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static Connection GetByName(string name)
|
public static Connection GetByName(string name)
|
||||||
{
|
{
|
||||||
if (!CanGetObject())
|
if (!CanGetObject())
|
||||||
throw new System.Security.SecurityException("User not authorized to view a Connection");
|
throw new System.Security.SecurityException("User not authorized to view a Connection");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Connection tmp = GetExistingByName(name);
|
Connection tmp = GetCachedByName(name);
|
||||||
if (tmp == null)
|
if (tmp == null)
|
||||||
{
|
{
|
||||||
tmp = DataPortal.Fetch<Connection>(new NameCriteria(name));
|
tmp = DataPortal.Fetch<Connection>(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;
|
return tmp;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -632,7 +669,8 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
BuildRefreshList();
|
BuildRefreshList();
|
||||||
Connection connection = base.Save();
|
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();
|
ProcessRefreshList();
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ namespace VEPROMS.CSLA.Library
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
CanWriteProperty("MyFormat", true);
|
CanWriteProperty("MyFormat", true);
|
||||||
if (_MyFormat != value)
|
if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID))
|
||||||
{
|
{
|
||||||
_MyFormat = value;
|
_MyFormat = value;
|
||||||
_FormatID = (value == null ? null : (int?)value.FormatID);
|
_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;
|
private string _Config = string.Empty;
|
||||||
public string Config
|
public string Config
|
||||||
{
|
{
|
||||||
@ -371,6 +391,8 @@ namespace VEPROMS.CSLA.Library
|
|||||||
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
|
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
|
||||||
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
|
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
|
||||||
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
|
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
|
||||||
|
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
|
||||||
|
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
|
||||||
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
||||||
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
||||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||||
@ -455,6 +477,7 @@ namespace VEPROMS.CSLA.Library
|
|||||||
_Title = dr.GetString("Title");
|
_Title = dr.GetString("Title");
|
||||||
_ShortName = dr.GetString("ShortName");
|
_ShortName = dr.GetString("ShortName");
|
||||||
_FormatID = (int?)dr.GetValue("FormatID");
|
_FormatID = (int?)dr.GetValue("FormatID");
|
||||||
|
_ManualOrder = (double?)dr.GetValue("ManualOrder");
|
||||||
_Config = dr.GetString("Config");
|
_Config = dr.GetString("Config");
|
||||||
_DTS = dr.GetDateTime("DTS");
|
_DTS = dr.GetDateTime("DTS");
|
||||||
_UsrID = dr.GetString("UsrID");
|
_UsrID = dr.GetString("UsrID");
|
||||||
@ -472,7 +495,7 @@ namespace VEPROMS.CSLA.Library
|
|||||||
// if we're not dirty then don't update the database
|
// if we're not dirty then don't update the database
|
||||||
if (!this.IsDirty) return;
|
if (!this.IsDirty) return;
|
||||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
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();
|
MarkOld();
|
||||||
}
|
}
|
||||||
internal void Update(Connection myConnection)
|
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 we're not dirty then don't update the database
|
||||||
if (!this.IsDirty) return;
|
if (!this.IsDirty) return;
|
||||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
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();
|
MarkOld();
|
||||||
}
|
}
|
||||||
internal void DeleteSelf(Connection myConnection)
|
internal void DeleteSelf(Connection myConnection)
|
||||||
|
@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
|
|||||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
#endregion
|
#endregion
|
||||||
#region Collection
|
#region Collection
|
||||||
protected static List<ConnectionInfo> _AllList = new List<ConnectionInfo>();
|
private static List<ConnectionInfo> _CacheList = new List<ConnectionInfo>();
|
||||||
private static Dictionary<string, List<ConnectionInfo>> _AllByPrimaryKey = new Dictionary<string, List<ConnectionInfo>>();
|
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<string, List<ConnectionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ConnectionInfo>>();
|
||||||
private static void ConvertListToDictionary()
|
private static void ConvertListToDictionary()
|
||||||
{
|
{
|
||||||
List<ConnectionInfo> remove = new List<ConnectionInfo>();
|
List<ConnectionInfo> remove = new List<ConnectionInfo>();
|
||||||
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<ConnectionInfo>(); // Add new list for PrimaryKey
|
_CacheByPrimaryKey[tmp.DBID.ToString()] = new List<ConnectionInfo>(); // 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);
|
remove.Add(tmp);
|
||||||
}
|
}
|
||||||
foreach (ConnectionInfo tmp in remove)
|
foreach (ConnectionInfo tmp in remove)
|
||||||
_AllList.Remove(tmp);
|
RemoveFromCache(tmp);
|
||||||
}
|
}
|
||||||
internal static void AddList(ConnectionInfoList lst)
|
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();
|
ConvertListToDictionary();
|
||||||
string key = dbid.ToString();
|
string key = dbid.ToString();
|
||||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -194,11 +202,11 @@ namespace VEPROMS.CSLA.Library
|
|||||||
return _ConnectionFolders;
|
return _ConnectionFolders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal void RefreshConnectionFolders()
|
public void RefreshConnectionFolders()
|
||||||
{
|
{
|
||||||
ConvertListToDictionary();
|
ConvertListToDictionary();
|
||||||
if (_AllByPrimaryKey.ContainsKey(_DBID.ToString()))
|
if (_CacheByPrimaryKey.ContainsKey(_DBID.ToString()))
|
||||||
foreach (ConnectionInfo tmp in _AllByPrimaryKey[_DBID.ToString()])
|
foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()])
|
||||||
tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried
|
tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried
|
||||||
}
|
}
|
||||||
// TODO: Replace base ConnectionInfo.ToString function as necessary
|
// TODO: Replace base ConnectionInfo.ToString function as necessary
|
||||||
@ -222,24 +230,23 @@ namespace VEPROMS.CSLA.Library
|
|||||||
#endregion
|
#endregion
|
||||||
#region Factory Methods
|
#region Factory Methods
|
||||||
private static int _ConnectionInfoUnique = 0;
|
private static int _ConnectionInfoUnique = 0;
|
||||||
private int _MyConnectionInfoUnique;
|
private static int ConnectionInfoUnique
|
||||||
|
{ get { return ++_ConnectionInfoUnique; } }
|
||||||
|
private int _MyConnectionInfoUnique = ConnectionInfoUnique;
|
||||||
public int MyConnectionInfoUnique
|
public int MyConnectionInfoUnique
|
||||||
{
|
{ get { return _MyConnectionInfoUnique; } }
|
||||||
get { return _MyConnectionInfoUnique; }
|
protected ConnectionInfo()
|
||||||
}
|
|
||||||
private ConnectionInfo()
|
|
||||||
{/* require use of factory methods */
|
{/* require use of factory methods */
|
||||||
_MyConnectionInfoUnique = ++_ConnectionInfoUnique;
|
AddToCache(this);
|
||||||
_AllList.Add(this);
|
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_AllList.Remove(this);
|
RemoveFromCache(this);
|
||||||
if (!_AllByPrimaryKey.ContainsKey(DBID.ToString())) return;
|
if (!_CacheByPrimaryKey.ContainsKey(DBID.ToString())) return;
|
||||||
List<ConnectionInfo> listConnectionInfo = _AllByPrimaryKey[DBID.ToString()]; // Get the list of items
|
List<ConnectionInfo> listConnectionInfo = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items
|
||||||
listConnectionInfo.Remove(this); // Remove the item from the list
|
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
|
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()
|
public virtual Connection Get()
|
||||||
{
|
{
|
||||||
@ -249,11 +256,11 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
string key = tmp.DBID.ToString();
|
string key = tmp.DBID.ToString();
|
||||||
ConvertListToDictionary();
|
ConvertListToDictionary();
|
||||||
if (_AllByPrimaryKey.ContainsKey(key))
|
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||||
foreach (ConnectionInfo tmpInfo in _AllByPrimaryKey[key])
|
foreach (ConnectionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||||
tmpInfo.RefreshFields(tmp);
|
tmpInfo.RefreshFields(tmp);
|
||||||
}
|
}
|
||||||
private void RefreshFields(Connection tmp)
|
protected virtual void RefreshFields(Connection tmp)
|
||||||
{
|
{
|
||||||
_Name = tmp.Name;
|
_Name = tmp.Name;
|
||||||
_Title = tmp.Title;
|
_Title = tmp.Title;
|
||||||
@ -271,13 +278,17 @@ namespace VEPROMS.CSLA.Library
|
|||||||
// throw new System.Security.SecurityException("User not authorized to view a Connection");
|
// throw new System.Security.SecurityException("User not authorized to view a Connection");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ConnectionInfo tmp = GetExistingByPrimaryKey(dbid);
|
ConnectionInfo tmp = GetCachedByPrimaryKey(dbid);
|
||||||
if (tmp == null)
|
if (tmp == null)
|
||||||
{
|
{
|
||||||
tmp = DataPortal.Fetch<ConnectionInfo>(new PKCriteria(dbid));
|
tmp = DataPortal.Fetch<ConnectionInfo>(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;
|
return tmp;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -289,7 +300,6 @@ namespace VEPROMS.CSLA.Library
|
|||||||
#region Data Access Portal
|
#region Data Access Portal
|
||||||
internal ConnectionInfo(SafeDataReader dr)
|
internal ConnectionInfo(SafeDataReader dr)
|
||||||
{
|
{
|
||||||
_MyConnectionInfoUnique = ++_ConnectionInfoUnique;
|
|
||||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode());
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user