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<PermissionInfo> _AllList = new List<PermissionInfo>();
private static Dictionary<string, PermissionInfo> _AllByPrimaryKey = new Dictionary<string, PermissionInfo>();
private static Dictionary<string, List<PermissionInfo>> _AllByPrimaryKey = new Dictionary<string, List<PermissionInfo>>();
private static void ConvertListToDictionary()
{
List<PermissionInfo> remove = new List<PermissionInfo>();
foreach (PermissionInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.PID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString()))
{
_AllByPrimaryKey[tmp.PID.ToString()] = new List<PermissionInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (PermissionInfo tmp in remove)
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = pid.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("PID",true);
CanReadProperty("PID", true);
return _PID;
}
}
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RID",true);
CanReadProperty("RID", true);
if (_MyRole != null) _RID = _MyRole.RID;
return _RID;
}
@@ -106,7 +110,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyRole",true);
CanReadProperty("MyRole", true);
if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID);
return _MyRole;
}
@@ -120,7 +124,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PermLevel",true);
CanReadProperty("PermLevel", true);
return _PermLevel;
}
}
@@ -133,7 +137,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("VersionType",true);
CanReadProperty("VersionType", true);
return _VersionType;
}
}
@@ -146,7 +150,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PermValue",true);
CanReadProperty("PermValue", true);
return _PermValue;
}
}
@@ -159,7 +163,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PermAD",true);
CanReadProperty("PermAD", true);
return _PermAD;
}
}
@@ -169,7 +173,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("StartDate",true);
CanReadProperty("StartDate", true);
return _StartDate;
}
}
@@ -179,7 +183,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("EndDate",true);
CanReadProperty("EndDate", true);
return _EndDate;
}
}
@@ -189,7 +193,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
}
@@ -199,7 +203,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -209,7 +213,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
}
@@ -233,14 +237,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _PermissionInfoUnique = 0;
private int _MyPermissionInfoUnique;
public int MyPermissionInfoUnique
{
get { return _MyPermissionInfoUnique; }
}
private PermissionInfo()
{/* require use of factory methods */
_MyPermissionInfoUnique = ++_PermissionInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(PID.ToString());
if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return;
List<PermissionInfo> listPermissionInfo = _AllByPrimaryKey[PID.ToString()]; // Get the list of items
listPermissionInfo.Remove(this); // Remove the item from the list
if (listPermissionInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(PID.ToString()); // remove the list
}
public virtual Permission Get()
{
@@ -248,9 +263,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Permission tmp)
{
PermissionInfo tmpInfo = GetExistingByPrimaryKey(tmp.PID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.PID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Permission tmp)
{
@@ -258,9 +275,9 @@ namespace VEPROMS.CSLA.Library
{
MyRole.RefreshRolePermissions(); // Update List for old value
_RID = tmp.RID; // Update the value
_MyRole = null; // Reset list so that the next line gets a new list
MyRole.RefreshRolePermissions(); // Update List for new value
}
_MyRole = null; // Reset list so that the next line gets a new list
if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for new value
_PermLevel = tmp.PermLevel;
_VersionType = tmp.VersionType;
_PermValue = tmp.PermValue;
@@ -276,9 +293,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(RolePermission tmp)
{
PermissionInfo tmpInfo = GetExistingByPrimaryKey(tmp.PID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.PID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(RolePermission tmp)
{
@@ -305,7 +324,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<PermissionInfo>(new PKCriteria(pid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -319,14 +338,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal PermissionInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode());
_MyPermissionInfoUnique = ++_PermissionInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("PermissionInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.Constructor", ex);
throw new DbCslaException("PermissionInfo.Constructor", ex);
}
}
@@ -343,7 +363,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PermissionInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.ReadData", GetHashCode());
try
{
_PID = dr.GetInt32("PID");
@@ -360,14 +380,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("PermissionInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("PermissionInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PermissionInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -395,7 +415,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("PermissionInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("PermissionInfo.DataPortal_Fetch", ex);
}
@@ -405,7 +425,7 @@ namespace VEPROMS.CSLA.Library
#region extension
PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension();
[Serializable()]
partial class PermissionInfoExtension : extensionBase {}
partial class PermissionInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{