This commit is contained in:
@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<UserInfo> _AllList = new List<UserInfo>();
|
||||
private static Dictionary<string, UserInfo> _AllByPrimaryKey = new Dictionary<string, UserInfo>();
|
||||
private static Dictionary<string, List<UserInfo>> _AllByPrimaryKey = new Dictionary<string, List<UserInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<UserInfo> remove = new List<UserInfo>();
|
||||
foreach (UserInfo tmp in _AllList)
|
||||
{
|
||||
_AllByPrimaryKey[tmp.UID.ToString()]=tmp; // Primary Key
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.UID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.UID.ToString()] = new List<UserInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (UserInfo tmp in remove)
|
||||
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = uid.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("UID",true);
|
||||
CanReadProperty("UID", true);
|
||||
return _UID;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserID",true);
|
||||
CanReadProperty("UserID", true);
|
||||
return _UserID;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +109,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FirstName",true);
|
||||
CanReadProperty("FirstName", true);
|
||||
return _FirstName;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +119,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("MiddleName",true);
|
||||
CanReadProperty("MiddleName", true);
|
||||
return _MiddleName;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +129,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("LastName",true);
|
||||
CanReadProperty("LastName", true);
|
||||
return _LastName;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +139,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("Suffix",true);
|
||||
CanReadProperty("Suffix", true);
|
||||
return _Suffix;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +149,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("CourtesyTitle",true);
|
||||
CanReadProperty("CourtesyTitle", true);
|
||||
return _CourtesyTitle;
|
||||
}
|
||||
}
|
||||
@@ -155,7 +159,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("PhoneNumber",true);
|
||||
CanReadProperty("PhoneNumber", true);
|
||||
return _PhoneNumber;
|
||||
}
|
||||
}
|
||||
@@ -165,7 +169,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("CFGName",true);
|
||||
CanReadProperty("CFGName", true);
|
||||
return _CFGName;
|
||||
}
|
||||
}
|
||||
@@ -175,7 +179,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserLogin",true);
|
||||
CanReadProperty("UserLogin", true);
|
||||
return _UserLogin;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +189,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserName",true);
|
||||
CanReadProperty("UserName", true);
|
||||
return _UserName;
|
||||
}
|
||||
}
|
||||
@@ -195,7 +199,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("Config",true);
|
||||
CanReadProperty("Config", true);
|
||||
return _Config;
|
||||
}
|
||||
}
|
||||
@@ -205,7 +209,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DTS",true);
|
||||
CanReadProperty("DTS", true);
|
||||
return _DTS;
|
||||
}
|
||||
}
|
||||
@@ -215,7 +219,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UsrID",true);
|
||||
CanReadProperty("UsrID", true);
|
||||
return _UsrID;
|
||||
}
|
||||
}
|
||||
@@ -228,7 +232,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserMembershipCount",true);
|
||||
CanReadProperty("UserMembershipCount", true);
|
||||
return _UserMembershipCount;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +243,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserMemberships",true);
|
||||
CanReadProperty("UserMemberships", true);
|
||||
if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null))
|
||||
_UserMemberships = MembershipInfoList.GetByUID(_UID);
|
||||
if (_UserMembershipCount < 0)
|
||||
@@ -249,7 +253,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void RefreshUserMemberships()
|
||||
{
|
||||
_UserMembershipCount = -1; // This will cause the data to be requeried
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_UID.ToString()))
|
||||
foreach (UserInfo tmp in _AllByPrimaryKey[_UID.ToString()])
|
||||
tmp._UserMembershipCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base UserInfo.ToString function as necessary
|
||||
/// <summary>
|
||||
@@ -271,14 +278,25 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _UserInfoUnique = 0;
|
||||
private int _MyUserInfoUnique;
|
||||
public int MyUserInfoUnique
|
||||
{
|
||||
get { return _MyUserInfoUnique; }
|
||||
}
|
||||
private UserInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyUserInfoUnique = ++_UserInfoUnique;
|
||||
_AllList.Add(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
_AllByPrimaryKey.Remove(UID.ToString());
|
||||
if (!_AllByPrimaryKey.ContainsKey(UID.ToString())) return;
|
||||
List<UserInfo> listUserInfo = _AllByPrimaryKey[UID.ToString()]; // Get the list of items
|
||||
listUserInfo.Remove(this); // Remove the item from the list
|
||||
if (listUserInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(UID.ToString()); // remove the list
|
||||
}
|
||||
public virtual User Get()
|
||||
{
|
||||
@@ -286,9 +304,11 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static void Refresh(User tmp)
|
||||
{
|
||||
UserInfo tmpInfo = GetExistingByPrimaryKey(tmp.UID);
|
||||
if (tmpInfo == null) return;
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
string key = tmp.UID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (UserInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(User tmp)
|
||||
{
|
||||
@@ -318,7 +338,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<UserInfo>(new PKCriteria(uid));
|
||||
_AllList.Add(tmp);
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
@@ -332,14 +352,15 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal UserInfo(SafeDataReader dr)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode());
|
||||
_MyUserInfoUnique = ++_UserInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("UserInfo.Constructor", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.Constructor", ex);
|
||||
throw new DbCslaException("UserInfo.Constructor", ex);
|
||||
}
|
||||
}
|
||||
@@ -356,7 +377,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
private void ReadData(SafeDataReader dr)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] UserInfo.ReadData", GetHashCode());
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.ReadData", GetHashCode());
|
||||
try
|
||||
{
|
||||
_UID = dr.GetInt32("UID");
|
||||
@@ -377,14 +398,14 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("UserInfo.ReadData", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.ReadData", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("UserInfo.ReadData", ex);
|
||||
}
|
||||
}
|
||||
private void DataPortal_Fetch(PKCriteria criteria)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] UserInfo.DataPortal_Fetch", GetHashCode());
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.DataPortal_Fetch", GetHashCode());
|
||||
try
|
||||
{
|
||||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||||
@@ -412,7 +433,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("UserInfo.DataPortal_Fetch", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.DataPortal_Fetch", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("UserInfo.DataPortal_Fetch", ex);
|
||||
}
|
||||
@@ -422,7 +443,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#region extension
|
||||
UserInfoExtension _UserInfoExtension = new UserInfoExtension();
|
||||
[Serializable()]
|
||||
partial class UserInfoExtension : extensionBase {}
|
||||
partial class UserInfoExtension : extensionBase { }
|
||||
[Serializable()]
|
||||
class extensionBase
|
||||
{
|
||||
|
Reference in New Issue
Block a user