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<RoleInfo> _AllList = new List<RoleInfo>();
private static Dictionary<string, RoleInfo> _AllByPrimaryKey = new Dictionary<string, RoleInfo>();
private static Dictionary<string, List<RoleInfo>> _AllByPrimaryKey = new Dictionary<string, List<RoleInfo>>();
private static void ConvertListToDictionary()
{
List<RoleInfo> remove = new List<RoleInfo>();
foreach (RoleInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.RID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.RID.ToString()))
{
_AllByPrimaryKey[tmp.RID.ToString()] = new List<RoleInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (RoleInfo tmp in remove)
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = rid.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("RID",true);
CanReadProperty("RID", true);
return _RID;
}
}
@@ -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("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -125,7 +129,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
}
@@ -138,7 +142,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RoleAssignmentCount",true);
CanReadProperty("RoleAssignmentCount", true);
return _RoleAssignmentCount;
}
}
@@ -149,7 +153,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RoleAssignments",true);
CanReadProperty("RoleAssignments", true);
if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null))
_RoleAssignments = AssignmentInfoList.GetByRID(_RID);
if (_RoleAssignmentCount < 0)
@@ -159,7 +163,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshRoleAssignments()
{
_RoleAssignmentCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_RID.ToString()))
foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()])
tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried
}
private int _RolePermissionCount = 0;
/// <summary>
@@ -170,7 +177,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RolePermissionCount",true);
CanReadProperty("RolePermissionCount", true);
return _RolePermissionCount;
}
}
@@ -181,7 +188,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RolePermissions",true);
CanReadProperty("RolePermissions", true);
if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null))
_RolePermissions = PermissionInfoList.GetByRID(_RID);
if (_RolePermissionCount < 0)
@@ -191,7 +198,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshRolePermissions()
{
_RolePermissionCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_RID.ToString()))
foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()])
tmp._RolePermissionCount = -1; // This will cause the data to be requeried
}
// TODO: Replace base RoleInfo.ToString function as necessary
/// <summary>
@@ -213,14 +223,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _RoleInfoUnique = 0;
private int _MyRoleInfoUnique;
public int MyRoleInfoUnique
{
get { return _MyRoleInfoUnique; }
}
private RoleInfo()
{/* require use of factory methods */
_MyRoleInfoUnique = ++_RoleInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(RID.ToString());
if (!_AllByPrimaryKey.ContainsKey(RID.ToString())) return;
List<RoleInfo> listRoleInfo = _AllByPrimaryKey[RID.ToString()]; // Get the list of items
listRoleInfo.Remove(this); // Remove the item from the list
if (listRoleInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(RID.ToString()); // remove the list
}
public virtual Role Get()
{
@@ -228,9 +249,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Role tmp)
{
RoleInfo tmpInfo = GetExistingByPrimaryKey(tmp.RID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.RID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (RoleInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Role tmp)
{
@@ -251,7 +274,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<RoleInfo>(new PKCriteria(rid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -265,14 +288,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal RoleInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode());
_MyRoleInfoUnique = ++_RoleInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("RoleInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.Constructor", ex);
throw new DbCslaException("RoleInfo.Constructor", ex);
}
}
@@ -289,7 +313,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RoleInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.ReadData", GetHashCode());
try
{
_RID = dr.GetInt32("RID");
@@ -302,14 +326,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("RoleInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("RoleInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] RoleInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -337,7 +361,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("RoleInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("RoleInfo.DataPortal_Fetch", ex);
}
@@ -347,7 +371,7 @@ namespace VEPROMS.CSLA.Library
#region extension
RoleInfoExtension _RoleInfoExtension = new RoleInfoExtension();
[Serializable()]
partial class RoleInfoExtension : extensionBase {}
partial class RoleInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{