This commit is contained in:
Kathy Ruffing 2008-08-12 11:42:50 +00:00
parent dfafac5a3a
commit d81b4d8af0
19 changed files with 941 additions and 569 deletions

View File

@ -53,28 +53,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Membership> _AllList = new List<Membership>(); private static List<Membership> _CacheList = new List<Membership>();
private static Dictionary<string, List<Membership>> _AllByPrimaryKey = new Dictionary<string, List<Membership>>(); protected static void AddToCache(Membership membership)
{
if (!_CacheList.Contains(membership)) _CacheList.Add(membership); // In AddToCache
}
protected static void RemoveFromCache(Membership membership)
{
while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache
}
private static Dictionary<string, List<Membership>> _CacheByPrimaryKey = new Dictionary<string, List<Membership>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Membership> remove = new List<Membership>(); List<Membership> remove = new List<Membership>();
foreach (Membership tmp in _AllList) foreach (Membership tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.UGID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString()))
{ {
_AllByPrimaryKey[tmp.UGID.ToString()] = new List<Membership>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.UGID.ToString()] = new List<Membership>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Membership tmp in remove) foreach (Membership tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Membership GetExistingByPrimaryKey(int ugid) protected static Membership GetCachedByPrimaryKey(int ugid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = ugid.ToString(); string key = ugid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -484,24 +492,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _MembershipUnique = 0; private static int _MembershipUnique = 0;
private int _MyMembershipUnique; protected static int MembershipUnique
{ get { return ++_MembershipUnique; } }
private int _MyMembershipUnique = MembershipUnique;
public int MyMembershipUnique public int MyMembershipUnique
{ { get { return _MyMembershipUnique; } }
get { return _MyMembershipUnique; }
}
protected Membership() protected Membership()
{/* require use of factory methods */ {/* require use of factory methods */
_MyMembershipUnique = ++_MembershipUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(UGID.ToString())) return; }
List<Membership> listMembership = _AllByPrimaryKey[UGID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listMembership.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(UGID.ToString()))
{
List<Membership> listMembership = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items
while (listMembership.Contains(this)) listMembership.Remove(this); // Remove the item from the list
if (listMembership.Count == 0) //If there are no items left in the list if (listMembership.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(UGID.ToString()); // remove the list _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list
}
} }
public static Membership New() public static Membership New()
{ {
@ -539,7 +552,11 @@ namespace VEPROMS.CSLA.Library
{ {
Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID); Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Membership tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -564,7 +581,11 @@ namespace VEPROMS.CSLA.Library
{ {
Membership tmp = Membership.New(myUser, myGroup, endDate, config); Membership tmp = Membership.New(myUser, myGroup, endDate, config);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Membership tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -582,13 +603,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Membership"); throw new System.Security.SecurityException("User not authorized to view a Membership");
try try
{ {
Membership tmp = GetExistingByPrimaryKey(ugid); Membership tmp = GetCachedByPrimaryKey(ugid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Membership>(new PKCriteria(ugid)); tmp = DataPortal.Fetch<Membership>(new PKCriteria(ugid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Membership
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -630,7 +655,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Membership membership = base.Save(); Membership membership = base.Save();
_AllList.Add(membership);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(membership);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return membership; return membership;
} }

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<MembershipInfo> _AllList = new List<MembershipInfo>(); private static List<MembershipInfo> _CacheList = new List<MembershipInfo>();
private static Dictionary<string, List<MembershipInfo>> _AllByPrimaryKey = new Dictionary<string, List<MembershipInfo>>(); protected static void AddToCache(MembershipInfo membershipInfo)
{
if (!_CacheList.Contains(membershipInfo)) _CacheList.Add(membershipInfo); // In AddToCache
}
protected static void RemoveFromCache(MembershipInfo membershipInfo)
{
while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache
}
private static Dictionary<string, List<MembershipInfo>> _CacheByPrimaryKey = new Dictionary<string, List<MembershipInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<MembershipInfo> remove = new List<MembershipInfo>(); List<MembershipInfo> remove = new List<MembershipInfo>();
foreach (MembershipInfo tmp in _AllList) foreach (MembershipInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.UGID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString()))
{ {
_AllByPrimaryKey[tmp.UGID.ToString()] = new List<MembershipInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.UGID.ToString()] = new List<MembershipInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (MembershipInfo tmp in remove) foreach (MembershipInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(MembershipInfoList lst) internal static void AddList(MembershipInfoList lst)
{ {
foreach (MembershipInfo item in lst) _AllList.Add(item); foreach (MembershipInfo item in lst) AddToCache(item);
} }
public static MembershipInfo GetExistingByPrimaryKey(int ugid) protected static MembershipInfo GetCachedByPrimaryKey(int ugid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = ugid.ToString(); string key = ugid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -208,24 +216,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _MembershipInfoUnique = 0; private static int _MembershipInfoUnique = 0;
private int _MyMembershipInfoUnique; private static int MembershipInfoUnique
{ get { return ++_MembershipInfoUnique; } }
private int _MyMembershipInfoUnique = MembershipInfoUnique;
public int MyMembershipInfoUnique public int MyMembershipInfoUnique
{ { get { return _MyMembershipInfoUnique; } }
get { return _MyMembershipInfoUnique; } protected MembershipInfo()
}
private MembershipInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyMembershipInfoUnique = ++_MembershipInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(UGID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(UGID.ToString())) return;
List<MembershipInfo> listMembershipInfo = _AllByPrimaryKey[UGID.ToString()]; // Get the list of items List<MembershipInfo> listMembershipInfo = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items
listMembershipInfo.Remove(this); // Remove the item from the list while (listMembershipInfo.Contains(this)) listMembershipInfo.Remove(this); // Remove the item from the list
if (listMembershipInfo.Count == 0) // If there are no items left in the list if (listMembershipInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(UGID.ToString()); // remove the list _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list
} }
public virtual Membership Get() public virtual Membership Get()
{ {
@ -235,22 +242,22 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.UGID.ToString(); string key = tmp.UGID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (MembershipInfo tmpInfo in _AllByPrimaryKey[key]) foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Membership tmp) protected virtual void RefreshFields(Membership tmp)
{ {
if (_UID != tmp.UID) if (_UID != tmp.UID)
{ {
MyUser.RefreshUserMemberships(); // Update List for old value if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value
_UID = tmp.UID; // Update the value _UID = tmp.UID; // Update the value
} }
_MyUser = null; // Reset list so that the next line gets a new list _MyUser = null; // Reset list so that the next line gets a new list
if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value
if (_GID != tmp.GID) if (_GID != tmp.GID)
{ {
MyGroup.RefreshGroupMemberships(); // Update List for old value if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value
_GID = tmp.GID; // Update the value _GID = tmp.GID; // Update the value
} }
_MyGroup = null; // Reset list so that the next line gets a new list _MyGroup = null; // Reset list so that the next line gets a new list
@ -269,15 +276,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.UGID.ToString(); string key = tmp.UGID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (MembershipInfo tmpInfo in _AllByPrimaryKey[key]) foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(GroupMembership tmp) protected virtual void RefreshFields(GroupMembership tmp)
{ {
if (_UID != tmp.UID) if (_UID != tmp.UID)
{ {
MyUser.RefreshUserMemberships(); // Update List for old value if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value
_UID = tmp.UID; // Update the value _UID = tmp.UID; // Update the value
} }
_MyUser = null; // Reset list so that the next line gets a new list _MyUser = null; // Reset list so that the next line gets a new list
@ -296,15 +303,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.UGID.ToString(); string key = tmp.UGID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (MembershipInfo tmpInfo in _AllByPrimaryKey[key]) foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(UserMembership tmp) protected virtual void RefreshFields(UserMembership tmp)
{ {
if (_GID != tmp.GID) if (_GID != tmp.GID)
{ {
MyGroup.RefreshGroupMemberships(); // Update List for old value if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value
_GID = tmp.GID; // Update the value _GID = tmp.GID; // Update the value
} }
_MyGroup = null; // Reset list so that the next line gets a new list _MyGroup = null; // Reset list so that the next line gets a new list
@ -325,13 +332,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Membership"); // throw new System.Security.SecurityException("User not authorized to view a Membership");
try try
{ {
MembershipInfo tmp = GetExistingByPrimaryKey(ugid); MembershipInfo tmp = GetCachedByPrimaryKey(ugid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<MembershipInfo>(new PKCriteria(ugid)); tmp = DataPortal.Fetch<MembershipInfo>(new PKCriteria(ugid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up MembershipInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -343,7 +354,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal MembershipInfo(SafeDataReader dr) internal MembershipInfo(SafeDataReader dr)
{ {
_MyMembershipInfoUnique = ++_MembershipInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -53,28 +53,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Part> _AllList = new List<Part>(); private static List<Part> _CacheList = new List<Part>();
private static Dictionary<string, List<Part>> _AllByPrimaryKey = new Dictionary<string, List<Part>>(); protected static void AddToCache(Part part)
{
if (!_CacheList.Contains(part)) _CacheList.Add(part); // In AddToCache
}
protected static void RemoveFromCache(Part part)
{
while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache
}
private static Dictionary<string, List<Part>> _CacheByPrimaryKey = new Dictionary<string, List<Part>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Part> remove = new List<Part>(); List<Part> remove = new List<Part>();
foreach (Part tmp in _AllList) foreach (Part tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()))
{ {
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List<Part>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List<Part>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Part tmp in remove) foreach (Part tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Part GetExistingByPrimaryKey(int contentID, int fromType) protected static Part GetCachedByPrimaryKey(int contentID, int fromType)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = contentID.ToString() + "_" + fromType.ToString(); string key = contentID.ToString() + "_" + fromType.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -339,24 +347,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _PartUnique = 0; private static int _PartUnique = 0;
private int _MyPartUnique; protected static int PartUnique
{ get { return ++_PartUnique; } }
private int _MyPartUnique = PartUnique;
public int MyPartUnique public int MyPartUnique
{ { get { return _MyPartUnique; } }
get { return _MyPartUnique; }
}
protected Part() protected Part()
{/* require use of factory methods */ {/* require use of factory methods */
_MyPartUnique = ++_PartUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; }
List<Part> listPart = _AllByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listPart.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString()))
{
List<Part> listPart = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items
while (listPart.Contains(this)) listPart.Remove(this); // Remove the item from the list
if (listPart.Count == 0) //If there are no items left in the list if (listPart.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list
}
} }
public static Part New() public static Part New()
{ {
@ -379,6 +392,26 @@ namespace VEPROMS.CSLA.Library
tmp.MyItem = myItem; tmp.MyItem = myItem;
return tmp; return tmp;
} }
public static Part MakePart(Content myContent, int fromType, Item myItem)
{
Part tmp = Part.New(myContent, fromType, myItem);
if (tmp.IsSavable)
{
Part tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
tmp._ErrorMessage = "Failed Validation:";
foreach (Csla.Validation.BrokenRule br in brc)
{
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
}
}
return tmp;
}
public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID) public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID)
{ {
Part tmp = Part.New(); Part tmp = Part.New();
@ -393,7 +426,11 @@ namespace VEPROMS.CSLA.Library
{ {
Part tmp = Part.New(myContent, fromType, myItem, dts, userID); Part tmp = Part.New(myContent, fromType, myItem, dts, userID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Part tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -411,13 +448,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Part"); throw new System.Security.SecurityException("User not authorized to view a Part");
try try
{ {
Part tmp = GetExistingByPrimaryKey(contentID, fromType); Part tmp = GetCachedByPrimaryKey(contentID, fromType);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Part>(new PKCriteria(contentID, fromType)); tmp = DataPortal.Fetch<Part>(new PKCriteria(contentID, fromType));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Part
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -459,7 +500,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Part part = base.Save(); Part part = base.Save();
_AllList.Add(part);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(part);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return part; return part;
} }

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<PartInfo> _AllList = new List<PartInfo>(); private static List<PartInfo> _CacheList = new List<PartInfo>();
private static Dictionary<string, List<PartInfo>> _AllByPrimaryKey = new Dictionary<string, List<PartInfo>>(); protected static void AddToCache(PartInfo partInfo)
{
if (!_CacheList.Contains(partInfo)) _CacheList.Add(partInfo); // In AddToCache
}
protected static void RemoveFromCache(PartInfo partInfo)
{
while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache
}
private static Dictionary<string, List<PartInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PartInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<PartInfo> remove = new List<PartInfo>(); List<PartInfo> remove = new List<PartInfo>();
foreach (PartInfo tmp in _AllList) foreach (PartInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()))
{ {
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List<PartInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List<PartInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (PartInfo tmp in remove) foreach (PartInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(PartInfoList lst) internal static void AddList(PartInfoList lst)
{ {
foreach (PartInfo item in lst) _AllList.Add(item); foreach (PartInfo item in lst) AddToCache(item);
} }
public static PartInfo GetExistingByPrimaryKey(int contentID, int fromType) protected static PartInfo GetCachedByPrimaryKey(int contentID, int fromType)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = contentID.ToString() + "_" + fromType.ToString(); string key = contentID.ToString() + "_" + fromType.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -180,24 +188,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _PartInfoUnique = 0; private static int _PartInfoUnique = 0;
private int _MyPartInfoUnique; private static int PartInfoUnique
{ get { return ++_PartInfoUnique; } }
private int _MyPartInfoUnique = PartInfoUnique;
public int MyPartInfoUnique public int MyPartInfoUnique
{ { get { return _MyPartInfoUnique; } }
get { return _MyPartInfoUnique; } protected PartInfo()
}
private PartInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyPartInfoUnique = ++_PartInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return;
List<PartInfo> listPartInfo = _AllByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items List<PartInfo> listPartInfo = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items
listPartInfo.Remove(this); // Remove the item from the list while (listPartInfo.Contains(this)) listPartInfo.Remove(this); // Remove the item from the list
if (listPartInfo.Count == 0) // If there are no items left in the list if (listPartInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list
} }
public virtual Part Get() public virtual Part Get()
{ {
@ -207,15 +214,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PartInfo tmpInfo in _AllByPrimaryKey[key]) foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Part tmp) protected virtual void RefreshFields(Part tmp)
{ {
if (_ItemID != tmp.ItemID) if (_ItemID != tmp.ItemID)
{ {
MyItem.RefreshItemParts(); // Update List for old value if (MyItem != null) MyItem.RefreshItemParts(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value _ItemID = tmp.ItemID; // Update the value
} }
_MyItem = null; // Reset list so that the next line gets a new list _MyItem = null; // Reset list so that the next line gets a new list
@ -231,15 +238,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString(); string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PartInfo tmpInfo in _AllByPrimaryKey[key]) foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ContentPart tmp) protected virtual void RefreshFields(ContentPart tmp)
{ {
if (_ItemID != tmp.ItemID) if (_ItemID != tmp.ItemID)
{ {
MyItem.RefreshItemParts(); // Update List for old value if (MyItem != null) MyItem.RefreshItemParts(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value _ItemID = tmp.ItemID; // Update the value
} }
_MyItem = null; // Reset list so that the next line gets a new list _MyItem = null; // Reset list so that the next line gets a new list
@ -255,11 +262,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PartInfo tmpInfo in _AllByPrimaryKey[key]) foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ItemPart tmp) protected virtual void RefreshFields(ItemPart tmp)
{ {
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
@ -274,13 +281,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Part"); // throw new System.Security.SecurityException("User not authorized to view a Part");
try try
{ {
PartInfo tmp = GetExistingByPrimaryKey(contentID, fromType); PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<PartInfo>(new PKCriteria(contentID, fromType)); tmp = DataPortal.Fetch<PartInfo>(new PKCriteria(contentID, fromType));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up PartInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -292,7 +303,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal PartInfo(SafeDataReader dr) internal PartInfo(SafeDataReader dr)
{ {
_MyPartInfoUnique = ++_PartInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Permission> _AllList = new List<Permission>(); private static List<Permission> _CacheList = new List<Permission>();
private static Dictionary<string, List<Permission>> _AllByPrimaryKey = new Dictionary<string, List<Permission>>(); protected static void AddToCache(Permission permission)
{
if (!_CacheList.Contains(permission)) _CacheList.Add(permission); // In AddToCache
}
protected static void RemoveFromCache(Permission permission)
{
while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache
}
private static Dictionary<string, List<Permission>> _CacheByPrimaryKey = new Dictionary<string, List<Permission>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Permission> remove = new List<Permission>(); List<Permission> remove = new List<Permission>();
foreach (Permission tmp in _AllList) foreach (Permission tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString()))
{ {
_AllByPrimaryKey[tmp.PID.ToString()] = new List<Permission>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.PID.ToString()] = new List<Permission>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Permission tmp in remove) foreach (Permission tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Permission GetExistingByPrimaryKey(int pid) protected static Permission GetCachedByPrimaryKey(int pid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = pid.ToString(); string key = pid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -538,24 +546,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _PermissionUnique = 0; private static int _PermissionUnique = 0;
private int _MyPermissionUnique; protected static int PermissionUnique
{ get { return ++_PermissionUnique; } }
private int _MyPermissionUnique = PermissionUnique;
public int MyPermissionUnique public int MyPermissionUnique
{ { get { return _MyPermissionUnique; } }
get { return _MyPermissionUnique; }
}
protected Permission() protected Permission()
{/* require use of factory methods */ {/* require use of factory methods */
_MyPermissionUnique = ++_PermissionUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return; }
List<Permission> listPermission = _AllByPrimaryKey[PID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listPermission.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(PID.ToString()))
{
List<Permission> listPermission = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items
while (listPermission.Contains(this)) listPermission.Remove(this); // Remove the item from the list
if (listPermission.Count == 0) //If there are no items left in the list if (listPermission.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(PID.ToString()); // remove the list _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list
}
} }
public static Permission New() public static Permission New()
{ {
@ -598,7 +611,11 @@ namespace VEPROMS.CSLA.Library
{ {
Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID); Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Permission tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -625,7 +642,11 @@ namespace VEPROMS.CSLA.Library
{ {
Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config); Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Permission tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -643,13 +664,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Permission"); throw new System.Security.SecurityException("User not authorized to view a Permission");
try try
{ {
Permission tmp = GetExistingByPrimaryKey(pid); Permission tmp = GetCachedByPrimaryKey(pid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Permission>(new PKCriteria(pid)); tmp = DataPortal.Fetch<Permission>(new PKCriteria(pid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Permission
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -691,7 +716,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Permission permission = base.Save(); Permission permission = base.Save();
_AllList.Add(permission);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(permission);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return permission; return permission;
} }

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<PermissionInfo> _AllList = new List<PermissionInfo>(); private static List<PermissionInfo> _CacheList = new List<PermissionInfo>();
private static Dictionary<string, List<PermissionInfo>> _AllByPrimaryKey = new Dictionary<string, List<PermissionInfo>>(); protected static void AddToCache(PermissionInfo permissionInfo)
{
if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache
}
protected static void RemoveFromCache(PermissionInfo permissionInfo)
{
while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache
}
private static Dictionary<string, List<PermissionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PermissionInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<PermissionInfo> remove = new List<PermissionInfo>(); List<PermissionInfo> remove = new List<PermissionInfo>();
foreach (PermissionInfo tmp in _AllList) foreach (PermissionInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.PID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString()))
{ {
_AllByPrimaryKey[tmp.PID.ToString()] = new List<PermissionInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.PID.ToString()] = new List<PermissionInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (PermissionInfo tmp in remove) foreach (PermissionInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(PermissionInfoList lst) internal static void AddList(PermissionInfoList lst)
{ {
foreach (PermissionInfo item in lst) _AllList.Add(item); foreach (PermissionInfo item in lst) AddToCache(item);
} }
public static PermissionInfo GetExistingByPrimaryKey(int pid) protected static PermissionInfo GetCachedByPrimaryKey(int pid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = pid.ToString(); string key = pid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -238,24 +246,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _PermissionInfoUnique = 0; private static int _PermissionInfoUnique = 0;
private int _MyPermissionInfoUnique; private static int PermissionInfoUnique
{ get { return ++_PermissionInfoUnique; } }
private int _MyPermissionInfoUnique = PermissionInfoUnique;
public int MyPermissionInfoUnique public int MyPermissionInfoUnique
{ { get { return _MyPermissionInfoUnique; } }
get { return _MyPermissionInfoUnique; } protected PermissionInfo()
}
private PermissionInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyPermissionInfoUnique = ++_PermissionInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(PID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return;
List<PermissionInfo> listPermissionInfo = _AllByPrimaryKey[PID.ToString()]; // Get the list of items List<PermissionInfo> listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items
listPermissionInfo.Remove(this); // Remove the item from the list while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list
if (listPermissionInfo.Count == 0) // If there are no items left in the list if (listPermissionInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(PID.ToString()); // remove the list _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list
} }
public virtual Permission Get() public virtual Permission Get()
{ {
@ -265,15 +272,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.PID.ToString(); string key = tmp.PID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Permission tmp) protected virtual void RefreshFields(Permission tmp)
{ {
if (_RID != tmp.RID) if (_RID != tmp.RID)
{ {
MyRole.RefreshRolePermissions(); // Update List for old value if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value
_RID = tmp.RID; // Update the value _RID = tmp.RID; // Update the value
} }
_MyRole = null; // Reset list so that the next line gets a new list _MyRole = null; // Reset list so that the next line gets a new list
@ -295,11 +302,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.PID.ToString(); string key = tmp.PID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PermissionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(RolePermission tmp) protected virtual void RefreshFields(RolePermission tmp)
{ {
_PermLevel = tmp.PermLevel; _PermLevel = tmp.PermLevel;
_VersionType = tmp.VersionType; _VersionType = tmp.VersionType;
@ -320,13 +327,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Permission"); // throw new System.Security.SecurityException("User not authorized to view a Permission");
try try
{ {
PermissionInfo tmp = GetExistingByPrimaryKey(pid); PermissionInfo tmp = GetCachedByPrimaryKey(pid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<PermissionInfo>(new PKCriteria(pid)); tmp = DataPortal.Fetch<PermissionInfo>(new PKCriteria(pid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up PermissionInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -338,7 +349,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal PermissionInfo(SafeDataReader dr) internal PermissionInfo(SafeDataReader dr)
{ {
_MyPermissionInfoUnique = ++_PermissionInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<RoUsage> _AllList = new List<RoUsage>(); private static List<RoUsage> _CacheList = new List<RoUsage>();
private static Dictionary<string, List<RoUsage>> _AllByPrimaryKey = new Dictionary<string, List<RoUsage>>(); protected static void AddToCache(RoUsage roUsage)
{
if (!_CacheList.Contains(roUsage)) _CacheList.Add(roUsage); // In AddToCache
}
protected static void RemoveFromCache(RoUsage roUsage)
{
while (_CacheList.Contains(roUsage)) _CacheList.Remove(roUsage); // In RemoveFromCache
}
private static Dictionary<string, List<RoUsage>> _CacheByPrimaryKey = new Dictionary<string, List<RoUsage>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<RoUsage> remove = new List<RoUsage>(); List<RoUsage> remove = new List<RoUsage>();
foreach (RoUsage tmp in _AllList) foreach (RoUsage tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString()))
{ {
_AllByPrimaryKey[tmp.ROUsageID.ToString()] = new List<RoUsage>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List<RoUsage>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (RoUsage tmp in remove) foreach (RoUsage tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static RoUsage GetExistingByPrimaryKey(int rOUsageID) protected static RoUsage GetCachedByPrimaryKey(int rOUsageID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = rOUsageID.ToString(); string key = rOUsageID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -372,24 +380,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _RoUsageUnique = 0; private static int _RoUsageUnique = 0;
private int _MyRoUsageUnique; protected static int RoUsageUnique
{ get { return ++_RoUsageUnique; } }
private int _MyRoUsageUnique = RoUsageUnique;
public int MyRoUsageUnique public int MyRoUsageUnique
{ { get { return _MyRoUsageUnique; } }
get { return _MyRoUsageUnique; }
}
protected RoUsage() protected RoUsage()
{/* require use of factory methods */ {/* require use of factory methods */
_MyRoUsageUnique = ++_RoUsageUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; }
List<RoUsage> listRoUsage = _AllByPrimaryKey[ROUsageID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listRoUsage.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString()))
{
List<RoUsage> listRoUsage = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items
while (listRoUsage.Contains(this)) listRoUsage.Remove(this); // Remove the item from the list
if (listRoUsage.Count == 0) //If there are no items left in the list if (listRoUsage.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list
}
} }
public static RoUsage New() public static RoUsage New()
{ {
@ -424,7 +437,11 @@ namespace VEPROMS.CSLA.Library
{ {
RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID); RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
RoUsage tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -448,7 +465,11 @@ namespace VEPROMS.CSLA.Library
{ {
RoUsage tmp = RoUsage.New(myContent, roid, config); RoUsage tmp = RoUsage.New(myContent, roid, config);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
RoUsage tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -466,13 +487,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a RoUsage"); throw new System.Security.SecurityException("User not authorized to view a RoUsage");
try try
{ {
RoUsage tmp = GetExistingByPrimaryKey(rOUsageID); RoUsage tmp = GetCachedByPrimaryKey(rOUsageID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<RoUsage>(new PKCriteria(rOUsageID)); tmp = DataPortal.Fetch<RoUsage>(new PKCriteria(rOUsageID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up RoUsage
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -514,7 +539,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
RoUsage roUsage = base.Save(); RoUsage roUsage = base.Save();
_AllList.Add(roUsage);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(roUsage);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return roUsage; return roUsage;
} }

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<RoUsageInfo> _AllList = new List<RoUsageInfo>(); private static List<RoUsageInfo> _CacheList = new List<RoUsageInfo>();
private static Dictionary<string, List<RoUsageInfo>> _AllByPrimaryKey = new Dictionary<string, List<RoUsageInfo>>(); protected static void AddToCache(RoUsageInfo roUsageInfo)
{
if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache
}
protected static void RemoveFromCache(RoUsageInfo roUsageInfo)
{
while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache
}
private static Dictionary<string, List<RoUsageInfo>> _CacheByPrimaryKey = new Dictionary<string, List<RoUsageInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<RoUsageInfo> remove = new List<RoUsageInfo>(); List<RoUsageInfo> remove = new List<RoUsageInfo>();
foreach (RoUsageInfo tmp in _AllList) foreach (RoUsageInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString()))
{ {
_AllByPrimaryKey[tmp.ROUsageID.ToString()] = new List<RoUsageInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List<RoUsageInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (RoUsageInfo tmp in remove) foreach (RoUsageInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(RoUsageInfoList lst) internal static void AddList(RoUsageInfoList lst)
{ {
foreach (RoUsageInfo item in lst) _AllList.Add(item); foreach (RoUsageInfo item in lst) AddToCache(item);
} }
public static RoUsageInfo GetExistingByPrimaryKey(int rOUsageID) protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = rOUsageID.ToString(); string key = rOUsageID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -176,24 +184,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _RoUsageInfoUnique = 0; private static int _RoUsageInfoUnique = 0;
private int _MyRoUsageInfoUnique; private static int RoUsageInfoUnique
{ get { return ++_RoUsageInfoUnique; } }
private int _MyRoUsageInfoUnique = RoUsageInfoUnique;
public int MyRoUsageInfoUnique public int MyRoUsageInfoUnique
{ { get { return _MyRoUsageInfoUnique; } }
get { return _MyRoUsageInfoUnique; } protected RoUsageInfo()
}
private RoUsageInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyRoUsageInfoUnique = ++_RoUsageInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return;
List<RoUsageInfo> listRoUsageInfo = _AllByPrimaryKey[ROUsageID.ToString()]; // Get the list of items List<RoUsageInfo> listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items
listRoUsageInfo.Remove(this); // Remove the item from the list while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list
if (listRoUsageInfo.Count == 0) // If there are no items left in the list if (listRoUsageInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list
} }
public virtual RoUsage Get() public virtual RoUsage Get()
{ {
@ -203,15 +210,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ROUsageID.ToString(); string key = tmp.ROUsageID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (RoUsageInfo tmpInfo in _AllByPrimaryKey[key]) foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(RoUsage tmp) protected virtual void RefreshFields(RoUsage tmp)
{ {
if (_ContentID != tmp.ContentID) if (_ContentID != tmp.ContentID)
{ {
MyContent.RefreshContentRoUsages(); // Update List for old value if (MyContent != null) MyContent.RefreshContentRoUsages(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value _ContentID = tmp.ContentID; // Update the value
} }
_MyContent = null; // Reset list so that the next line gets a new list _MyContent = null; // Reset list so that the next line gets a new list
@ -228,11 +235,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ROUsageID.ToString(); string key = tmp.ROUsageID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (RoUsageInfo tmpInfo in _AllByPrimaryKey[key]) foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ContentRoUsage tmp) protected virtual void RefreshFields(ContentRoUsage tmp)
{ {
_ROID = tmp.ROID; _ROID = tmp.ROID;
_Config = tmp.Config; _Config = tmp.Config;
@ -248,13 +255,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a RoUsage"); // throw new System.Security.SecurityException("User not authorized to view a RoUsage");
try try
{ {
RoUsageInfo tmp = GetExistingByPrimaryKey(rOUsageID); RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<RoUsageInfo>(new PKCriteria(rOUsageID)); tmp = DataPortal.Fetch<RoUsageInfo>(new PKCriteria(rOUsageID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up RoUsageInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -266,7 +277,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal RoUsageInfo(SafeDataReader dr) internal RoUsageInfo(SafeDataReader dr)
{ {
_MyRoUsageInfoUnique = ++_RoUsageInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -77,38 +77,46 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Role> _AllList = new List<Role>(); private static List<Role> _CacheList = new List<Role>();
private static Dictionary<string, List<Role>> _AllByPrimaryKey = new Dictionary<string, List<Role>>(); protected static void AddToCache(Role role)
private static Dictionary<string, List<Role>> _AllByName = new Dictionary<string, List<Role>>(); {
if (!_CacheList.Contains(role)) _CacheList.Add(role); // In AddToCache
}
protected static void RemoveFromCache(Role role)
{
while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache
}
private static Dictionary<string, List<Role>> _CacheByPrimaryKey = new Dictionary<string, List<Role>>();
private static Dictionary<string, List<Role>> _CacheByName = new Dictionary<string, List<Role>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Role> remove = new List<Role>(); List<Role> remove = new List<Role>();
foreach (Role tmp in _AllList) foreach (Role tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.RID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString()))
{ {
_AllByPrimaryKey[tmp.RID.ToString()] = new List<Role>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.RID.ToString()] = new List<Role>(); // Add new list for PrimaryKey
_AllByName[tmp.Name.ToString()] = new List<Role>(); // Add new list for Name _CacheByName[tmp.Name.ToString()] = new List<Role>(); // Add new list for Name
} }
_AllByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list
_AllByName[tmp.Name.ToString()].Add(tmp); // Unique Index _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Role tmp in remove) foreach (Role tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Role GetExistingByPrimaryKey(int rid) protected static Role GetCachedByPrimaryKey(int rid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = rid.ToString(); string key = rid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
public static Role GetExistingByName(string name) protected static Role GetCachedByName(string name)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = name.ToString(); string key = name.ToString();
if (_AllByName.ContainsKey(key)) return _AllByName[key][0]; if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0];
return null; return null;
} }
#endregion #endregion
@ -442,28 +450,41 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _RoleUnique = 0; private static int _RoleUnique = 0;
private int _MyRoleUnique; protected static int RoleUnique
{ get { return ++_RoleUnique; } }
private int _MyRoleUnique = RoleUnique;
public int MyRoleUnique public int MyRoleUnique
{ { get { return _MyRoleUnique; } }
get { return _MyRoleUnique; }
}
protected Role() protected Role()
{/* require use of factory methods */ {/* require use of factory methods */
_MyRoleUnique = ++_RoleUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(RID.ToString())) return; }
List<Role> listRole = _AllByPrimaryKey[RID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
{
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(RID.ToString()))
{
List<Role> listRole = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items
while (listRole.Contains(this)) listRole.Remove(this); // Remove the item from the list
if (listRole.Count == 0) //If there are no items left in the list
_CacheByPrimaryKey.Remove(RID.ToString()); // remove the list
}
string myKey;
myKey = null;
foreach (string key in _CacheByName.Keys)
if (_CacheByName[key].Contains(this))
myKey = key;
if (myKey != null)
{
List<Role> listRole = _CacheByName[myKey]; // Get the list of items
listRole.Remove(this); // Remove the item from the list listRole.Remove(this); // Remove the item from the list
if (listRole.Count == 0) //If there are no items left in the list if (listRole.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(RID.ToString()); // remove the list _CacheByName.Remove(myKey); // remove the list
listRole = _AllByName[RID.ToString()]; // Get the list of items }
listRole.Remove(this); // Remove the item from the list
if (listRole.Count == 0) //If there are no items left in the list
_AllByName.Remove(RID.ToString()); // remove the list
} }
public static Role New() public static Role New()
{ {
@ -485,6 +506,26 @@ namespace VEPROMS.CSLA.Library
tmp.Title = title; tmp.Title = title;
return tmp; return tmp;
} }
public static Role MakeRole(string name, string title)
{
Role tmp = Role.New(name, title);
if (tmp.IsSavable)
{
Role tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
tmp._ErrorMessage = "Failed Validation:";
foreach (Csla.Validation.BrokenRule br in brc)
{
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
}
}
return tmp;
}
public static Role New(string name, string title, DateTime dts, string usrID) public static Role New(string name, string title, DateTime dts, string usrID)
{ {
Role tmp = Role.New(); Role tmp = Role.New();
@ -498,7 +539,11 @@ namespace VEPROMS.CSLA.Library
{ {
Role tmp = Role.New(name, title, dts, usrID); Role tmp = Role.New(name, title, dts, usrID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Role tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -516,13 +561,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Role"); throw new System.Security.SecurityException("User not authorized to view a Role");
try try
{ {
Role tmp = GetExistingByPrimaryKey(rid); Role tmp = GetCachedByPrimaryKey(rid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Role>(new PKCriteria(rid)); tmp = DataPortal.Fetch<Role>(new PKCriteria(rid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Role
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -530,19 +579,23 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on Role.Get", ex); throw new DbCslaException("Error on Role.Get", ex);
} }
} }
private static Role GetByName(string name) public static Role GetByName(string name)
{ {
if (!CanGetObject()) if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Role"); throw new System.Security.SecurityException("User not authorized to view a Role");
try try
{ {
Role tmp = GetExistingByName(name); Role tmp = GetCachedByName(name);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Role>(new NameCriteria(name)); tmp = DataPortal.Fetch<Role>(new NameCriteria(name));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Role
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -584,7 +637,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Role role = base.Save(); Role role = base.Save();
_AllList.Add(role);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(role);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return role; return role;
} }

View File

@ -285,6 +285,16 @@ namespace VEPROMS.CSLA.Library
return _Folder_FormatID; return _Folder_FormatID;
} }
} }
private double? _Folder_ManualOrder;
public double? Folder_ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Folder_ManualOrder", true);
return _Folder_ManualOrder;
}
}
private string _Folder_Config = string.Empty; private string _Folder_Config = string.Empty;
public string Folder_Config public string Folder_Config
{ {
@ -597,6 +607,7 @@ namespace VEPROMS.CSLA.Library
_Folder_Title = dr.GetString("Folder_Title"); _Folder_Title = dr.GetString("Folder_Title");
_Folder_ShortName = dr.GetString("Folder_ShortName"); _Folder_ShortName = dr.GetString("Folder_ShortName");
_Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID");
_Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder");
_Folder_Config = dr.GetString("Folder_Config"); _Folder_Config = dr.GetString("Folder_Config");
_Folder_DTS = dr.GetDateTime("Folder_DTS"); _Folder_DTS = dr.GetDateTime("Folder_DTS");
_Folder_UsrID = dr.GetString("Folder_UsrID"); _Folder_UsrID = dr.GetString("Folder_UsrID");

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<RoleInfo> _AllList = new List<RoleInfo>(); private static List<RoleInfo> _CacheList = new List<RoleInfo>();
private static Dictionary<string, List<RoleInfo>> _AllByPrimaryKey = new Dictionary<string, List<RoleInfo>>(); protected static void AddToCache(RoleInfo roleInfo)
{
if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache
}
protected static void RemoveFromCache(RoleInfo roleInfo)
{
while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache
}
private static Dictionary<string, List<RoleInfo>> _CacheByPrimaryKey = new Dictionary<string, List<RoleInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<RoleInfo> remove = new List<RoleInfo>(); List<RoleInfo> remove = new List<RoleInfo>();
foreach (RoleInfo tmp in _AllList) foreach (RoleInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.RID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString()))
{ {
_AllByPrimaryKey[tmp.RID.ToString()] = new List<RoleInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.RID.ToString()] = new List<RoleInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (RoleInfo tmp in remove) foreach (RoleInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(RoleInfoList lst) internal static void AddList(RoleInfoList lst)
{ {
foreach (RoleInfo item in lst) _AllList.Add(item); foreach (RoleInfo item in lst) AddToCache(item);
} }
public static RoleInfo GetExistingByPrimaryKey(int rid) protected static RoleInfo GetCachedByPrimaryKey(int rid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = rid.ToString(); string key = rid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -161,11 +169,11 @@ namespace VEPROMS.CSLA.Library
return _RoleAssignments; return _RoleAssignments;
} }
} }
internal void RefreshRoleAssignments() public void RefreshRoleAssignments()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_RID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_RID.ToString()))
foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()]) foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()])
tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried
} }
private int _RolePermissionCount = 0; private int _RolePermissionCount = 0;
@ -196,11 +204,11 @@ namespace VEPROMS.CSLA.Library
return _RolePermissions; return _RolePermissions;
} }
} }
internal void RefreshRolePermissions() public void RefreshRolePermissions()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_RID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_RID.ToString()))
foreach (RoleInfo tmp in _AllByPrimaryKey[_RID.ToString()]) foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()])
tmp._RolePermissionCount = -1; // This will cause the data to be requeried tmp._RolePermissionCount = -1; // This will cause the data to be requeried
} }
// TODO: Replace base RoleInfo.ToString function as necessary // TODO: Replace base RoleInfo.ToString function as necessary
@ -224,24 +232,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _RoleInfoUnique = 0; private static int _RoleInfoUnique = 0;
private int _MyRoleInfoUnique; private static int RoleInfoUnique
{ get { return ++_RoleInfoUnique; } }
private int _MyRoleInfoUnique = RoleInfoUnique;
public int MyRoleInfoUnique public int MyRoleInfoUnique
{ { get { return _MyRoleInfoUnique; } }
get { return _MyRoleInfoUnique; } protected RoleInfo()
}
private RoleInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyRoleInfoUnique = ++_RoleInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(RID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return;
List<RoleInfo> listRoleInfo = _AllByPrimaryKey[RID.ToString()]; // Get the list of items List<RoleInfo> listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items
listRoleInfo.Remove(this); // Remove the item from the list while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list
if (listRoleInfo.Count == 0) // If there are no items left in the list if (listRoleInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(RID.ToString()); // remove the list _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list
} }
public virtual Role Get() public virtual Role Get()
{ {
@ -251,11 +258,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.RID.ToString(); string key = tmp.RID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (RoleInfo tmpInfo in _AllByPrimaryKey[key]) foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Role tmp) protected virtual void RefreshFields(Role tmp)
{ {
_Name = tmp.Name; _Name = tmp.Name;
_Title = tmp.Title; _Title = tmp.Title;
@ -270,13 +277,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Role"); // throw new System.Security.SecurityException("User not authorized to view a Role");
try try
{ {
RoleInfo tmp = GetExistingByPrimaryKey(rid); RoleInfo tmp = GetCachedByPrimaryKey(rid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<RoleInfo>(new PKCriteria(rid)); tmp = DataPortal.Fetch<RoleInfo>(new PKCriteria(rid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up RoleInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -288,7 +299,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal RoleInfo(SafeDataReader dr) internal RoleInfo(SafeDataReader dr)
{ {
_MyRoleInfoUnique = ++_RoleInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -54,28 +54,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Transition> _AllList = new List<Transition>(); private static List<Transition> _CacheList = new List<Transition>();
private static Dictionary<string, List<Transition>> _AllByPrimaryKey = new Dictionary<string, List<Transition>>(); protected static void AddToCache(Transition transition)
{
if (!_CacheList.Contains(transition)) _CacheList.Add(transition); // In AddToCache
}
protected static void RemoveFromCache(Transition transition)
{
while (_CacheList.Contains(transition)) _CacheList.Remove(transition); // In RemoveFromCache
}
private static Dictionary<string, List<Transition>> _CacheByPrimaryKey = new Dictionary<string, List<Transition>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Transition> remove = new List<Transition>(); List<Transition> remove = new List<Transition>();
foreach (Transition tmp in _AllList) foreach (Transition tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{ {
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<Transition>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<Transition>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Transition tmp in remove) foreach (Transition tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Transition GetExistingByPrimaryKey(int transitionID) protected static Transition GetCachedByPrimaryKey(int transitionID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = transitionID.ToString(); string key = transitionID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -503,24 +511,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _TransitionUnique = 0; private static int _TransitionUnique = 0;
private int _MyTransitionUnique; protected static int TransitionUnique
{ get { return ++_TransitionUnique; } }
private int _MyTransitionUnique = TransitionUnique;
public int MyTransitionUnique public int MyTransitionUnique
{ { get { return _MyTransitionUnique; } }
get { return _MyTransitionUnique; }
}
protected Transition() protected Transition()
{/* require use of factory methods */ {/* require use of factory methods */
_MyTransitionUnique = ++_TransitionUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return; }
List<Transition> listTransition = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listTransition.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString()))
{
List<Transition> listTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
while (listTransition.Contains(this)) listTransition.Remove(this); // Remove the item from the list
if (listTransition.Count == 0) //If there are no items left in the list if (listTransition.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
}
} }
public static Transition New() public static Transition New()
{ {
@ -559,7 +572,11 @@ namespace VEPROMS.CSLA.Library
{ {
Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, tranType, config, dts, userID); Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, tranType, config, dts, userID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Transition tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -584,7 +601,11 @@ namespace VEPROMS.CSLA.Library
{ {
Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config); Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Transition tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -602,13 +623,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Transition"); throw new System.Security.SecurityException("User not authorized to view a Transition");
try try
{ {
Transition tmp = GetExistingByPrimaryKey(transitionID); Transition tmp = GetCachedByPrimaryKey(transitionID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Transition>(new PKCriteria(transitionID)); tmp = DataPortal.Fetch<Transition>(new PKCriteria(transitionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Transition
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -650,7 +675,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Transition transition = base.Save(); Transition transition = base.Save();
_AllList.Add(transition);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(transition);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return transition; return transition;
} }

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<TransitionInfo> _AllList = new List<TransitionInfo>(); private static List<TransitionInfo> _CacheList = new List<TransitionInfo>();
private static Dictionary<string, List<TransitionInfo>> _AllByPrimaryKey = new Dictionary<string, List<TransitionInfo>>(); protected static void AddToCache(TransitionInfo transitionInfo)
{
if (!_CacheList.Contains(transitionInfo)) _CacheList.Add(transitionInfo); // In AddToCache
}
protected static void RemoveFromCache(TransitionInfo transitionInfo)
{
while (_CacheList.Contains(transitionInfo)) _CacheList.Remove(transitionInfo); // In RemoveFromCache
}
private static Dictionary<string, List<TransitionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<TransitionInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<TransitionInfo> remove = new List<TransitionInfo>(); List<TransitionInfo> remove = new List<TransitionInfo>();
foreach (TransitionInfo tmp in _AllList) foreach (TransitionInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{ {
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<TransitionInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<TransitionInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (TransitionInfo tmp in remove) foreach (TransitionInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(TransitionInfoList lst) internal static void AddList(TransitionInfoList lst)
{ {
foreach (TransitionInfo item in lst) _AllList.Add(item); foreach (TransitionInfo item in lst) AddToCache(item);
} }
public static TransitionInfo GetExistingByPrimaryKey(int transitionID) protected static TransitionInfo GetCachedByPrimaryKey(int transitionID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = transitionID.ToString(); string key = transitionID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -223,8 +231,11 @@ namespace VEPROMS.CSLA.Library
get get
{ {
CanReadProperty("MyZTransition", true); CanReadProperty("MyZTransition", true);
if (_TransitionZTransitionCount > 0 && _MyZTransition == null) if (_TransitionZTransitionCount != 0 && _MyZTransition == null)
{
_MyZTransition = ZTransitionInfo.Get(_TransitionID); _MyZTransition = ZTransitionInfo.Get(_TransitionID);
_TransitionZTransitionCount = _MyZTransition == null ? 0 : 1;
}
return _MyZTransition; return _MyZTransition;
} }
} }
@ -249,24 +260,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _TransitionInfoUnique = 0; private static int _TransitionInfoUnique = 0;
private int _MyTransitionInfoUnique; private static int TransitionInfoUnique
{ get { return ++_TransitionInfoUnique; } }
private int _MyTransitionInfoUnique = TransitionInfoUnique;
public int MyTransitionInfoUnique public int MyTransitionInfoUnique
{ { get { return _MyTransitionInfoUnique; } }
get { return _MyTransitionInfoUnique; } protected TransitionInfo()
}
private TransitionInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyTransitionInfoUnique = ++_TransitionInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
List<TransitionInfo> listTransitionInfo = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items List<TransitionInfo> listTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
listTransitionInfo.Remove(this); // Remove the item from the list while (listTransitionInfo.Contains(this)) listTransitionInfo.Remove(this); // Remove the item from the list
if (listTransitionInfo.Count == 0) // If there are no items left in the list if (listTransitionInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
} }
public virtual Transition Get() public virtual Transition Get()
{ {
@ -276,29 +286,29 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.TransitionID.ToString(); string key = tmp.TransitionID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Transition tmp) protected virtual void RefreshFields(Transition tmp)
{ {
if (_FromID != tmp.FromID) if (_FromID != tmp.FromID)
{ {
MyContent.RefreshContentTransitions(); // Update List for old value if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value
_FromID = tmp.FromID; // Update the value _FromID = tmp.FromID; // Update the value
} }
_MyContent = null; // Reset list so that the next line gets a new list _MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value
if (_ToID != tmp.ToID) if (_ToID != tmp.ToID)
{ {
MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
_ToID = tmp.ToID; // Update the value _ToID = tmp.ToID; // Update the value
} }
_MyItemToID = null; // Reset list so that the next line gets a new list _MyItemToID = null; // Reset list so that the next line gets a new list
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value
if (_RangeID != tmp.RangeID) if (_RangeID != tmp.RangeID)
{ {
MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
_RangeID = tmp.RangeID; // Update the value _RangeID = tmp.RangeID; // Update the value
} }
_MyItemRangeID = null; // Reset list so that the next line gets a new list _MyItemRangeID = null; // Reset list so that the next line gets a new list
@ -311,29 +321,30 @@ namespace VEPROMS.CSLA.Library
_MyContent = null; _MyContent = null;
_MyItemToID = null; _MyItemToID = null;
_MyItemRangeID = null; _MyItemRangeID = null;
_MyZTransition = null;// _MyZTransition = null;// Reset related value
_TransitionZTransitionCount = -1;// Reset Count
OnChange();// raise an event OnChange();// raise an event
} }
public static void Refresh(ContentTransition tmp) public static void Refresh(ContentTransition tmp)
{ {
string key = tmp.TransitionID.ToString(); string key = tmp.TransitionID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ContentTransition tmp) protected virtual void RefreshFields(ContentTransition tmp)
{ {
if (_ToID != tmp.ToID) if (_ToID != tmp.ToID)
{ {
MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
_ToID = tmp.ToID; // Update the value _ToID = tmp.ToID; // Update the value
} }
_MyItemToID = null; // Reset list so that the next line gets a new list _MyItemToID = null; // Reset list so that the next line gets a new list
if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value
if (_RangeID != tmp.RangeID) if (_RangeID != tmp.RangeID)
{ {
MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
_RangeID = tmp.RangeID; // Update the value _RangeID = tmp.RangeID; // Update the value
} }
_MyItemRangeID = null; // Reset list so that the next line gets a new list _MyItemRangeID = null; // Reset list so that the next line gets a new list
@ -346,29 +357,30 @@ namespace VEPROMS.CSLA.Library
_MyContent = null; _MyContent = null;
_MyItemToID = null; _MyItemToID = null;
_MyItemRangeID = null; _MyItemRangeID = null;
_MyZTransition = null;// _MyZTransition = null;// Reset related value
_TransitionZTransitionCount = -1;// Reset Count
OnChange();// raise an event OnChange();// raise an event
} }
public static void Refresh(ItemTransition_RangeID tmp) public static void Refresh(ItemTransition_RangeID tmp)
{ {
string key = tmp.TransitionID.ToString(); string key = tmp.TransitionID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ItemTransition_RangeID tmp) protected virtual void RefreshFields(ItemTransition_RangeID tmp)
{ {
if (_FromID != tmp.FromID) if (_FromID != tmp.FromID)
{ {
MyContent.RefreshContentTransitions(); // Update List for old value if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value
_FromID = tmp.FromID; // Update the value _FromID = tmp.FromID; // Update the value
} }
_MyContent = null; // Reset list so that the next line gets a new list _MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value
if (_ToID != tmp.ToID) if (_ToID != tmp.ToID)
{ {
MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value
_ToID = tmp.ToID; // Update the value _ToID = tmp.ToID; // Update the value
} }
_MyItemToID = null; // Reset list so that the next line gets a new list _MyItemToID = null; // Reset list so that the next line gets a new list
@ -381,29 +393,30 @@ namespace VEPROMS.CSLA.Library
_MyContent = null; _MyContent = null;
_MyItemToID = null; _MyItemToID = null;
_MyItemRangeID = null; _MyItemRangeID = null;
_MyZTransition = null;// _MyZTransition = null;// Reset related value
_TransitionZTransitionCount = -1;// Reset Count
OnChange();// raise an event OnChange();// raise an event
} }
public static void Refresh(ItemTransition_ToID tmp) public static void Refresh(ItemTransition_ToID tmp)
{ {
string key = tmp.TransitionID.ToString(); string key = tmp.TransitionID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (TransitionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ItemTransition_ToID tmp) protected virtual void RefreshFields(ItemTransition_ToID tmp)
{ {
if (_FromID != tmp.FromID) if (_FromID != tmp.FromID)
{ {
MyContent.RefreshContentTransitions(); // Update List for old value if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value
_FromID = tmp.FromID; // Update the value _FromID = tmp.FromID; // Update the value
} }
_MyContent = null; // Reset list so that the next line gets a new list _MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value
if (_RangeID != tmp.RangeID) if (_RangeID != tmp.RangeID)
{ {
MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value
_RangeID = tmp.RangeID; // Update the value _RangeID = tmp.RangeID; // Update the value
} }
_MyItemRangeID = null; // Reset list so that the next line gets a new list _MyItemRangeID = null; // Reset list so that the next line gets a new list
@ -416,7 +429,8 @@ namespace VEPROMS.CSLA.Library
_MyContent = null; _MyContent = null;
_MyItemToID = null; _MyItemToID = null;
_MyItemRangeID = null; _MyItemRangeID = null;
_MyZTransition = null;// _MyZTransition = null;// Reset related value
_TransitionZTransitionCount = -1;// Reset Count
OnChange();// raise an event OnChange();// raise an event
} }
public static TransitionInfo Get(int transitionID) public static TransitionInfo Get(int transitionID)
@ -425,13 +439,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Transition"); // throw new System.Security.SecurityException("User not authorized to view a Transition");
try try
{ {
TransitionInfo tmp = GetExistingByPrimaryKey(transitionID); TransitionInfo tmp = GetCachedByPrimaryKey(transitionID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<TransitionInfo>(new PKCriteria(transitionID)); tmp = DataPortal.Fetch<TransitionInfo>(new PKCriteria(transitionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up TransitionInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -443,7 +461,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal TransitionInfo(SafeDataReader dr) internal TransitionInfo(SafeDataReader dr)
{ {
_MyTransitionInfoUnique = ++_TransitionInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -64,28 +64,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<User> _AllList = new List<User>(); private static List<User> _CacheList = new List<User>();
private static Dictionary<string, List<User>> _AllByPrimaryKey = new Dictionary<string, List<User>>(); protected static void AddToCache(User user)
{
if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache
}
protected static void RemoveFromCache(User user)
{
while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache
}
private static Dictionary<string, List<User>> _CacheByPrimaryKey = new Dictionary<string, List<User>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<User> remove = new List<User>(); List<User> remove = new List<User>();
foreach (User tmp in _AllList) foreach (User tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.UID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString()))
{ {
_AllByPrimaryKey[tmp.UID.ToString()] = new List<User>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.UID.ToString()] = new List<User>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (User tmp in remove) foreach (User tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static User GetExistingByPrimaryKey(int uid) protected static User GetCachedByPrimaryKey(int uid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = uid.ToString(); string key = uid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -618,24 +626,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _UserUnique = 0; private static int _UserUnique = 0;
private int _MyUserUnique; protected static int UserUnique
{ get { return ++_UserUnique; } }
private int _MyUserUnique = UserUnique;
public int MyUserUnique public int MyUserUnique
{ { get { return _MyUserUnique; } }
get { return _MyUserUnique; }
}
protected User() protected User()
{/* require use of factory methods */ {/* require use of factory methods */
_MyUserUnique = ++_UserUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(UID.ToString())) return; }
List<User> listUser = _AllByPrimaryKey[UID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listUser.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(UID.ToString()))
{
List<User> listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items
while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list
if (listUser.Count == 0) //If there are no items left in the list if (listUser.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(UID.ToString()); // remove the list _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list
}
} }
public static User New() public static User New()
{ {
@ -672,7 +685,11 @@ namespace VEPROMS.CSLA.Library
{ {
User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID); User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
User tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -703,7 +720,11 @@ namespace VEPROMS.CSLA.Library
{ {
User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config); User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
User tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -721,13 +742,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a User"); throw new System.Security.SecurityException("User not authorized to view a User");
try try
{ {
User tmp = GetExistingByPrimaryKey(uid); User tmp = GetCachedByPrimaryKey(uid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<User>(new PKCriteria(uid)); tmp = DataPortal.Fetch<User>(new PKCriteria(uid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up User
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -769,7 +794,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
User user = base.Save(); User user = base.Save();
_AllList.Add(user);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(user);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return user; return user;
} }

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<UserInfo> _AllList = new List<UserInfo>(); private static List<UserInfo> _CacheList = new List<UserInfo>();
private static Dictionary<string, List<UserInfo>> _AllByPrimaryKey = new Dictionary<string, List<UserInfo>>(); protected static void AddToCache(UserInfo userInfo)
{
if (!_CacheList.Contains(userInfo)) _CacheList.Add(userInfo); // In AddToCache
}
protected static void RemoveFromCache(UserInfo userInfo)
{
while (_CacheList.Contains(userInfo)) _CacheList.Remove(userInfo); // In RemoveFromCache
}
private static Dictionary<string, List<UserInfo>> _CacheByPrimaryKey = new Dictionary<string, List<UserInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<UserInfo> remove = new List<UserInfo>(); List<UserInfo> remove = new List<UserInfo>();
foreach (UserInfo tmp in _AllList) foreach (UserInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.UID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString()))
{ {
_AllByPrimaryKey[tmp.UID.ToString()] = new List<UserInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.UID.ToString()] = new List<UserInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (UserInfo tmp in remove) foreach (UserInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(UserInfoList lst) internal static void AddList(UserInfoList lst)
{ {
foreach (UserInfo item in lst) _AllList.Add(item); foreach (UserInfo item in lst) AddToCache(item);
} }
public static UserInfo GetExistingByPrimaryKey(int uid) protected static UserInfo GetCachedByPrimaryKey(int uid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = uid.ToString(); string key = uid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -251,11 +259,11 @@ namespace VEPROMS.CSLA.Library
return _UserMemberships; return _UserMemberships;
} }
} }
internal void RefreshUserMemberships() public void RefreshUserMemberships()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_UID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_UID.ToString()))
foreach (UserInfo tmp in _AllByPrimaryKey[_UID.ToString()]) foreach (UserInfo tmp in _CacheByPrimaryKey[_UID.ToString()])
tmp._UserMembershipCount = -1; // This will cause the data to be requeried tmp._UserMembershipCount = -1; // This will cause the data to be requeried
} }
// TODO: Replace base UserInfo.ToString function as necessary // TODO: Replace base UserInfo.ToString function as necessary
@ -279,24 +287,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _UserInfoUnique = 0; private static int _UserInfoUnique = 0;
private int _MyUserInfoUnique; private static int UserInfoUnique
{ get { return ++_UserInfoUnique; } }
private int _MyUserInfoUnique = UserInfoUnique;
public int MyUserInfoUnique public int MyUserInfoUnique
{ { get { return _MyUserInfoUnique; } }
get { return _MyUserInfoUnique; } protected UserInfo()
}
private UserInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyUserInfoUnique = ++_UserInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(UID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(UID.ToString())) return;
List<UserInfo> listUserInfo = _AllByPrimaryKey[UID.ToString()]; // Get the list of items List<UserInfo> listUserInfo = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items
listUserInfo.Remove(this); // Remove the item from the list while (listUserInfo.Contains(this)) listUserInfo.Remove(this); // Remove the item from the list
if (listUserInfo.Count == 0) // If there are no items left in the list if (listUserInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(UID.ToString()); // remove the list _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list
} }
public virtual User Get() public virtual User Get()
{ {
@ -306,11 +313,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.UID.ToString(); string key = tmp.UID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (UserInfo tmpInfo in _AllByPrimaryKey[key]) foreach (UserInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(User tmp) protected virtual void RefreshFields(User tmp)
{ {
_UserID = tmp.UserID; _UserID = tmp.UserID;
_FirstName = tmp.FirstName; _FirstName = tmp.FirstName;
@ -334,13 +341,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a User"); // throw new System.Security.SecurityException("User not authorized to view a User");
try try
{ {
UserInfo tmp = GetExistingByPrimaryKey(uid); UserInfo tmp = GetCachedByPrimaryKey(uid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<UserInfo>(new PKCriteria(uid)); tmp = DataPortal.Fetch<UserInfo>(new PKCriteria(uid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up UserInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -352,7 +363,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal UserInfo(SafeDataReader dr) internal UserInfo(SafeDataReader dr)
{ {
_MyUserInfoUnique = ++_UserInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -51,28 +51,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<ZContent> _AllList = new List<ZContent>(); private static List<ZContent> _CacheList = new List<ZContent>();
private static Dictionary<string, List<ZContent>> _AllByPrimaryKey = new Dictionary<string, List<ZContent>>(); protected static void AddToCache(ZContent zContent)
{
if (!_CacheList.Contains(zContent)) _CacheList.Add(zContent); // In AddToCache
}
protected static void RemoveFromCache(ZContent zContent)
{
while (_CacheList.Contains(zContent)) _CacheList.Remove(zContent); // In RemoveFromCache
}
private static Dictionary<string, List<ZContent>> _CacheByPrimaryKey = new Dictionary<string, List<ZContent>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<ZContent> remove = new List<ZContent>(); List<ZContent> remove = new List<ZContent>();
foreach (ZContent tmp in _AllList) foreach (ZContent tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
{ {
_AllByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContent>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContent>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (ZContent tmp in remove) foreach (ZContent tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static ZContent GetExistingByPrimaryKey(int contentID) protected static ZContent GetCachedByPrimaryKey(int contentID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = contentID.ToString(); string key = contentID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -254,24 +262,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _ZContentUnique = 0; private static int _ZContentUnique = 0;
private int _MyZContentUnique; protected static int ZContentUnique
{ get { return ++_ZContentUnique; } }
private int _MyZContentUnique = ZContentUnique;
public int MyZContentUnique public int MyZContentUnique
{ { get { return _MyZContentUnique; } }
get { return _MyZContentUnique; }
}
protected ZContent() protected ZContent()
{/* require use of factory methods */ {/* require use of factory methods */
_MyZContentUnique = ++_ZContentUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; }
List<ZContent> listZContent = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listZContent.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString()))
{
List<ZContent> listZContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items
while (listZContent.Contains(this)) listZContent.Remove(this); // Remove the item from the list
if (listZContent.Count == 0) //If there are no items left in the list if (listZContent.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
} }
public static ZContent New() public static ZContent New()
{ {
@ -297,7 +310,11 @@ namespace VEPROMS.CSLA.Library
{ {
ZContent tmp = ZContent.New(myContent, oldStepSequence); ZContent tmp = ZContent.New(myContent, oldStepSequence);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
ZContent tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -323,13 +340,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a ZContent"); throw new System.Security.SecurityException("User not authorized to view a ZContent");
try try
{ {
ZContent tmp = GetExistingByPrimaryKey(contentID); ZContent tmp = GetCachedByPrimaryKey(contentID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<ZContent>(new PKCriteria(contentID)); tmp = DataPortal.Fetch<ZContent>(new PKCriteria(contentID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up ZContent
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -371,7 +392,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
ZContent zContent = base.Save(); ZContent zContent = base.Save();
_AllList.Add(zContent);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(zContent);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return zContent; return zContent;
} }

View File

@ -36,28 +36,36 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<ZContentInfo> _AllList = new List<ZContentInfo>(); private static List<ZContentInfo> _CacheList = new List<ZContentInfo>();
private static Dictionary<string, List<ZContentInfo>> _AllByPrimaryKey = new Dictionary<string, List<ZContentInfo>>(); protected static void AddToCache(ZContentInfo zContentInfo)
{
if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache
}
protected static void RemoveFromCache(ZContentInfo zContentInfo)
{
while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache
}
private static Dictionary<string, List<ZContentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ZContentInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<ZContentInfo> remove = new List<ZContentInfo>(); List<ZContentInfo> remove = new List<ZContentInfo>();
foreach (ZContentInfo tmp in _AllList) foreach (ZContentInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
{ {
_AllByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContentInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContentInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (ZContentInfo tmp in remove) foreach (ZContentInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static ZContentInfo GetExistingByPrimaryKey(int contentID) protected static ZContentInfo GetCachedByPrimaryKey(int contentID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = contentID.ToString(); string key = contentID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -133,24 +141,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ZContentInfoUnique = 0; private static int _ZContentInfoUnique = 0;
private int _MyZContentInfoUnique; private static int ZContentInfoUnique
{ get { return ++_ZContentInfoUnique; } }
private int _MyZContentInfoUnique = ZContentInfoUnique;
public int MyZContentInfoUnique public int MyZContentInfoUnique
{ { get { return _MyZContentInfoUnique; } }
get { return _MyZContentInfoUnique; } protected ZContentInfo()
}
private ZContentInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyZContentInfoUnique = ++_ZContentInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return;
List<ZContentInfo> listZContentInfo = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items List<ZContentInfo> listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items
listZContentInfo.Remove(this); // Remove the item from the list while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list
if (listZContentInfo.Count == 0) // If there are no items left in the list if (listZContentInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
} }
public virtual ZContent Get() public virtual ZContent Get()
{ {
@ -160,11 +167,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ContentID.ToString(); string key = tmp.ContentID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ZContentInfo tmpInfo in _AllByPrimaryKey[key]) foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ZContent tmp) protected virtual void RefreshFields(ZContent tmp)
{ {
_OldStepSequence = tmp.OldStepSequence; _OldStepSequence = tmp.OldStepSequence;
_ZContentInfoExtension.Refresh(this); _ZContentInfoExtension.Refresh(this);
@ -177,15 +184,16 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a ZContent"); // throw new System.Security.SecurityException("User not authorized to view a ZContent");
try try
{ {
ZContentInfo tmp = GetExistingByPrimaryKey(contentID); ZContentInfo tmp = GetCachedByPrimaryKey(contentID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<ZContentInfo>(new PKCriteria(contentID)); tmp = DataPortal.Fetch<ZContentInfo>(new PKCriteria(contentID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
} }
if (tmp.ErrorMessage == "No Record Found") if (tmp.ErrorMessage == "No Record Found")
{ {
tmp._ContentID = contentID; tmp.Dispose(); // Clean-up ZContentInfo
tmp = null;
} }
return tmp; return tmp;
} }
@ -198,7 +206,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal ZContentInfo(SafeDataReader dr) internal ZContentInfo(SafeDataReader dr)
{ {
_MyZContentInfoUnique = ++_ZContentInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -51,28 +51,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<ZTransition> _AllList = new List<ZTransition>(); private static List<ZTransition> _CacheList = new List<ZTransition>();
private static Dictionary<string, List<ZTransition>> _AllByPrimaryKey = new Dictionary<string, List<ZTransition>>(); protected static void AddToCache(ZTransition zTransition)
{
if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache
}
protected static void RemoveFromCache(ZTransition zTransition)
{
while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache
}
private static Dictionary<string, List<ZTransition>> _CacheByPrimaryKey = new Dictionary<string, List<ZTransition>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<ZTransition> remove = new List<ZTransition>(); List<ZTransition> remove = new List<ZTransition>();
foreach (ZTransition tmp in _AllList) foreach (ZTransition tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{ {
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransition>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransition>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (ZTransition tmp in remove) foreach (ZTransition tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static ZTransition GetExistingByPrimaryKey(int transitionID) protected static ZTransition GetCachedByPrimaryKey(int transitionID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = transitionID.ToString(); string key = transitionID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -254,24 +262,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _ZTransitionUnique = 0; private static int _ZTransitionUnique = 0;
private int _MyZTransitionUnique; protected static int ZTransitionUnique
{ get { return ++_ZTransitionUnique; } }
private int _MyZTransitionUnique = ZTransitionUnique;
public int MyZTransitionUnique public int MyZTransitionUnique
{ { get { return _MyZTransitionUnique; } }
get { return _MyZTransitionUnique; }
}
protected ZTransition() protected ZTransition()
{/* require use of factory methods */ {/* require use of factory methods */
_MyZTransitionUnique = ++_ZTransitionUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return; }
List<ZTransition> listZTransition = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listZTransition.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString()))
{
List<ZTransition> listZTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
while (listZTransition.Contains(this)) listZTransition.Remove(this); // Remove the item from the list
if (listZTransition.Count == 0) //If there are no items left in the list if (listZTransition.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
}
} }
public static ZTransition New() public static ZTransition New()
{ {
@ -297,7 +310,11 @@ namespace VEPROMS.CSLA.Library
{ {
ZTransition tmp = ZTransition.New(myTransition, oldto); ZTransition tmp = ZTransition.New(myTransition, oldto);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
ZTransition tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -323,13 +340,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a ZTransition"); throw new System.Security.SecurityException("User not authorized to view a ZTransition");
try try
{ {
ZTransition tmp = GetExistingByPrimaryKey(transitionID); ZTransition tmp = GetCachedByPrimaryKey(transitionID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<ZTransition>(new PKCriteria(transitionID)); tmp = DataPortal.Fetch<ZTransition>(new PKCriteria(transitionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up ZTransition
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -371,7 +392,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
ZTransition zTransition = base.Save(); ZTransition zTransition = base.Save();
_AllList.Add(zTransition);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(zTransition);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return zTransition; return zTransition;
} }

View File

@ -36,28 +36,36 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<ZTransitionInfo> _AllList = new List<ZTransitionInfo>(); private static List<ZTransitionInfo> _CacheList = new List<ZTransitionInfo>();
private static Dictionary<string, List<ZTransitionInfo>> _AllByPrimaryKey = new Dictionary<string, List<ZTransitionInfo>>(); protected static void AddToCache(ZTransitionInfo zTransitionInfo)
{
if (!_CacheList.Contains(zTransitionInfo)) _CacheList.Add(zTransitionInfo); // In AddToCache
}
protected static void RemoveFromCache(ZTransitionInfo zTransitionInfo)
{
while (_CacheList.Contains(zTransitionInfo)) _CacheList.Remove(zTransitionInfo); // In RemoveFromCache
}
private static Dictionary<string, List<ZTransitionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ZTransitionInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<ZTransitionInfo> remove = new List<ZTransitionInfo>(); List<ZTransitionInfo> remove = new List<ZTransitionInfo>();
foreach (ZTransitionInfo tmp in _AllList) foreach (ZTransitionInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{ {
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransitionInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransitionInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (ZTransitionInfo tmp in remove) foreach (ZTransitionInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static ZTransitionInfo GetExistingByPrimaryKey(int transitionID) protected static ZTransitionInfo GetCachedByPrimaryKey(int transitionID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = transitionID.ToString(); string key = transitionID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -133,24 +141,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ZTransitionInfoUnique = 0; private static int _ZTransitionInfoUnique = 0;
private int _MyZTransitionInfoUnique; private static int ZTransitionInfoUnique
{ get { return ++_ZTransitionInfoUnique; } }
private int _MyZTransitionInfoUnique = ZTransitionInfoUnique;
public int MyZTransitionInfoUnique public int MyZTransitionInfoUnique
{ { get { return _MyZTransitionInfoUnique; } }
get { return _MyZTransitionInfoUnique; } protected ZTransitionInfo()
}
private ZTransitionInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyZTransitionInfoUnique = ++_ZTransitionInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
List<ZTransitionInfo> listZTransitionInfo = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items List<ZTransitionInfo> listZTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items
listZTransitionInfo.Remove(this); // Remove the item from the list while (listZTransitionInfo.Contains(this)) listZTransitionInfo.Remove(this); // Remove the item from the list
if (listZTransitionInfo.Count == 0) // If there are no items left in the list if (listZTransitionInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
} }
public virtual ZTransition Get() public virtual ZTransition Get()
{ {
@ -160,11 +167,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.TransitionID.ToString(); string key = tmp.TransitionID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ZTransitionInfo tmpInfo in _AllByPrimaryKey[key]) foreach (ZTransitionInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ZTransition tmp) protected virtual void RefreshFields(ZTransition tmp)
{ {
_Oldto = tmp.Oldto; _Oldto = tmp.Oldto;
_ZTransitionInfoExtension.Refresh(this); _ZTransitionInfoExtension.Refresh(this);
@ -177,15 +184,16 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a ZTransition"); // throw new System.Security.SecurityException("User not authorized to view a ZTransition");
try try
{ {
ZTransitionInfo tmp = GetExistingByPrimaryKey(transitionID); ZTransitionInfo tmp = GetCachedByPrimaryKey(transitionID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<ZTransitionInfo>(new PKCriteria(transitionID)); tmp = DataPortal.Fetch<ZTransitionInfo>(new PKCriteria(transitionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
} }
if (tmp.ErrorMessage == "No Record Found") if (tmp.ErrorMessage == "No Record Found")
{ {
tmp._TransitionID = transitionID; tmp.Dispose(); // Clean-up ZTransitionInfo
tmp = null;
} }
return tmp; return tmp;
} }
@ -198,7 +206,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal ZTransitionInfo(SafeDataReader dr) internal ZTransitionInfo(SafeDataReader dr)
{ {
_MyZTransitionInfoUnique = ++_ZTransitionInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode());
try try
{ {