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

@@ -47,19 +47,23 @@ namespace VEPROMS.CSLA.Library
foreach (Permission tmp in _RefreshPermissions)
{
PermissionInfo.Refresh(tmp);
if(tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole);
if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole);
}
}
#endregion
#region Collection
protected static List<Permission> _AllList = new List<Permission>();
private static Dictionary<string, Permission> _AllByPrimaryKey = new Dictionary<string, Permission>();
private static Dictionary<string, List<Permission>> _AllByPrimaryKey = new Dictionary<string, List<Permission>>();
private static void ConvertListToDictionary()
{
List<Permission> remove = new List<Permission>();
foreach (Permission tmp in _AllList)
{
_AllByPrimaryKey[tmp.PID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString()))
{
_AllByPrimaryKey[tmp.PID.ToString()] = new List<Permission>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (Permission tmp in remove)
@@ -69,7 +73,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
@@ -91,7 +95,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PID",true);
CanReadProperty("PID", true);
return _PID;
}
}
@@ -101,7 +105,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;
}
@@ -112,14 +116,14 @@ 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 = Role.Get(_RID);
return _MyRole;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyRole",true);
CanWriteProperty("MyRole", true);
if (_MyRole != value)
{
_MyRole = value;
@@ -136,13 +140,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PermLevel",true);
CanReadProperty("PermLevel", true);
return _PermLevel;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("PermLevel",true);
CanWriteProperty("PermLevel", true);
if (_PermLevel != value)
{
_PermLevel = value;
@@ -159,13 +163,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("VersionType",true);
CanReadProperty("VersionType", true);
return _VersionType;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("VersionType",true);
CanWriteProperty("VersionType", true);
if (_VersionType != value)
{
_VersionType = value;
@@ -182,13 +186,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PermValue",true);
CanReadProperty("PermValue", true);
return _PermValue;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("PermValue",true);
CanWriteProperty("PermValue", true);
if (_PermValue != value)
{
_PermValue = value;
@@ -205,13 +209,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PermAD",true);
CanReadProperty("PermAD", true);
return _PermAD;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("PermAD",true);
CanWriteProperty("PermAD", true);
if (_PermAD != value)
{
_PermAD = value;
@@ -225,13 +229,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("StartDate",true);
CanReadProperty("StartDate", true);
return _StartDate;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("StartDate",true);
CanWriteProperty("StartDate", true);
if (value == null) value = string.Empty;
_StartDate = value;
try
@@ -255,13 +259,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("EndDate",true);
CanReadProperty("EndDate", true);
return _EndDate;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("EndDate",true);
CanWriteProperty("EndDate", true);
if (value == null) value = string.Empty;
_EndDate = value;
try
@@ -285,13 +289,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("Config",true);
CanWriteProperty("Config", true);
if (value == null) value = string.Empty;
if (_Config != value)
{
@@ -306,13 +310,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DTS",true);
CanWriteProperty("DTS", true);
if (_DTS != value)
{
_DTS = value;
@@ -326,13 +330,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("UsrID",true);
CanWriteProperty("UsrID", true);
if (value == null) value = string.Empty;
if (_UsrID != value)
{
@@ -344,11 +348,11 @@ namespace VEPROMS.CSLA.Library
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty || (_MyRole == null? false : _MyRole.IsDirty); }
get { return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRole == null? true : _MyRole.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); }
}
// TODO: Replace base Permission.ToString function as necessary
/// <summary>
@@ -371,22 +375,23 @@ namespace VEPROMS.CSLA.Library
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules=false;
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
get {
if(_CheckingBrokenRules)return null;
get
{
if (_CheckingBrokenRules) return null;
if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
try
{
_CheckingBrokenRules=true;
_CheckingBrokenRules = true;
IVEHasBrokenRules hasBrokenRules = null;
if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules;
if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -532,14 +537,25 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _PermissionUnique = 0;
private int _MyPermissionUnique;
public int MyPermissionUnique
{
get { return _MyPermissionUnique; }
}
protected Permission()
{/* require use of factory methods */
_MyPermissionUnique = ++_PermissionUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(PID.ToString());
if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return;
List<Permission> listPermission = _AllByPrimaryKey[PID.ToString()]; // Get the list of items
listPermission.Remove(this); // Remove the item from the list
if (listPermission.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(PID.ToString()); // remove the list
}
public static Permission New()
{
@@ -631,7 +647,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<Permission>(new PKCriteria(pid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -712,7 +728,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.ReadData", GetHashCode());
try
{
_PID = dr.GetInt32("PID");
@@ -731,14 +747,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Permission.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -766,7 +782,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Permission.DataPortal_Fetch", ex);
}
@@ -787,13 +803,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Permission.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -802,7 +818,7 @@ namespace VEPROMS.CSLA.Library
if (!this.IsDirty) return;
try
{
if(_MyRole != null) _MyRole.Update();
if (_MyRole != null) _MyRole.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
@@ -834,11 +850,11 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// update child objects
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Permission.SQLInsert", ex);
}
@@ -846,7 +862,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -880,7 +896,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Add", ex);
throw new DbCslaException("Permission.Add", ex);
}
}
@@ -888,7 +904,7 @@ namespace VEPROMS.CSLA.Library
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -902,7 +918,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -911,10 +927,10 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLUpdate", GetHashCode());
try
{
if(_MyRole != null) _MyRole.Update();
if (_MyRole != null) _MyRole.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
@@ -950,7 +966,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -971,7 +987,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -1003,7 +1019,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Update", ex);
throw new DbCslaException("Permission.Update", ex);
}
}
@@ -1015,7 +1031,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -1031,7 +1047,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Permission.DataPortal_Delete", ex);
}
@@ -1039,7 +1055,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int pid)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -1054,7 +1070,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Remove", ex);
throw new DbCslaException("Permission.Remove", ex);
}
}
@@ -1088,7 +1104,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -1106,7 +1122,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Permission.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Execute", ex);
throw new DbCslaException("Permission.DataPortal_Execute", ex);
}
}