This commit is contained in:
Jsj
2008-05-16 18:07:47 +00:00
parent 9d0b3cd543
commit cda0291dbd
116 changed files with 4257 additions and 3382 deletions

View File

@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<ConnectionInfo> _AllList = new List<ConnectionInfo>();
private static Dictionary<string, ConnectionInfo> _AllByPrimaryKey = new Dictionary<string, ConnectionInfo>();
private static Dictionary<string, List<ConnectionInfo>> _AllByPrimaryKey = new Dictionary<string, List<ConnectionInfo>>();
private static void ConvertListToDictionary()
{
List<ConnectionInfo> remove = new List<ConnectionInfo>();
foreach (ConnectionInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.DBID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.DBID.ToString()))
{
_AllByPrimaryKey[tmp.DBID.ToString()] = new List<ConnectionInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (ConnectionInfo tmp in remove)
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = dbid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
return null;
}
#endregion
@@ -85,7 +89,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DBID",true);
CanReadProperty("DBID", true);
return _DBID;
}
}
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Name",true);
CanReadProperty("Name", true);
return _Name;
}
}
@@ -105,7 +109,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Title",true);
CanReadProperty("Title", true);
return _Title;
}
}
@@ -115,7 +119,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ConnectionString",true);
CanReadProperty("ConnectionString", true);
return _ConnectionString;
}
}
@@ -128,7 +132,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ServerType",true);
CanReadProperty("ServerType", true);
return _ServerType;
}
}
@@ -138,7 +142,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
}
@@ -148,7 +152,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -158,7 +162,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
}
@@ -171,7 +175,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ConnectionFolderCount",true);
CanReadProperty("ConnectionFolderCount", true);
return _ConnectionFolderCount;
}
}
@@ -182,7 +186,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ConnectionFolders",true);
CanReadProperty("ConnectionFolders", true);
if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null))
_ConnectionFolders = FolderInfoList.GetByDBID(_DBID);
if (_ConnectionFolderCount < 0)
@@ -192,7 +196,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshConnectionFolders()
{
_ConnectionFolderCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_DBID.ToString()))
foreach (ConnectionInfo tmp in _AllByPrimaryKey[_DBID.ToString()])
tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried
}
// TODO: Replace base ConnectionInfo.ToString function as necessary
/// <summary>
@@ -214,14 +221,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _ConnectionInfoUnique = 0;
private int _MyConnectionInfoUnique;
public int MyConnectionInfoUnique
{
get { return _MyConnectionInfoUnique; }
}
private ConnectionInfo()
{/* require use of factory methods */
_MyConnectionInfoUnique = ++_ConnectionInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(DBID.ToString());
if (!_AllByPrimaryKey.ContainsKey(DBID.ToString())) return;
List<ConnectionInfo> listConnectionInfo = _AllByPrimaryKey[DBID.ToString()]; // Get the list of items
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
}
public virtual Connection Get()
{
@@ -229,9 +247,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Connection tmp)
{
ConnectionInfo tmpInfo = GetExistingByPrimaryKey(tmp.DBID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.DBID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (ConnectionInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Connection tmp)
{
@@ -255,7 +275,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<ConnectionInfo>(new PKCriteria(dbid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -269,14 +289,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal ConnectionInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode());
_MyConnectionInfoUnique = ++_ConnectionInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ConnectionInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.Constructor", ex);
throw new DbCslaException("ConnectionInfo.Constructor", ex);
}
}
@@ -293,7 +314,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ConnectionInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.ReadData", GetHashCode());
try
{
_DBID = dr.GetInt32("DBID");
@@ -308,14 +329,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ConnectionInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ConnectionInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ConnectionInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -343,7 +364,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ConnectionInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ConnectionInfo.DataPortal_Fetch", ex);
}
@@ -353,7 +374,7 @@ namespace VEPROMS.CSLA.Library
#region extension
ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension();
[Serializable()]
partial class ConnectionInfoExtension : extensionBase {}
partial class ConnectionInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{