This commit is contained in:
@@ -53,28 +53,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Membership> _AllList = new List<Membership>();
|
||||
private static Dictionary<string, List<Membership>> _AllByPrimaryKey = new Dictionary<string, List<Membership>>();
|
||||
private static List<Membership> _CacheList = new 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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
foreach (Membership tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Membership GetExistingByPrimaryKey(int ugid)
|
||||
protected static Membership GetCachedByPrimaryKey(int ugid)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = ugid.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -484,24 +492,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _MembershipUnique = 0;
|
||||
private int _MyMembershipUnique;
|
||||
protected static int MembershipUnique
|
||||
{ get { return ++_MembershipUnique; } }
|
||||
private int _MyMembershipUnique = MembershipUnique;
|
||||
public int MyMembershipUnique
|
||||
{
|
||||
get { return _MyMembershipUnique; }
|
||||
}
|
||||
{ get { return _MyMembershipUnique; } }
|
||||
protected Membership()
|
||||
{/* require use of factory methods */
|
||||
_MyMembershipUnique = ++_MembershipUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(UGID.ToString())) return;
|
||||
List<Membership> listMembership = _AllByPrimaryKey[UGID.ToString()]; // Get the list of items
|
||||
listMembership.Remove(this); // Remove the item from the list
|
||||
if (listMembership.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(UGID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
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
|
||||
_CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Membership New()
|
||||
{
|
||||
@@ -539,7 +552,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Membership tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -564,7 +581,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Membership tmp = Membership.New(myUser, myGroup, endDate, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Membership tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
try
|
||||
{
|
||||
Membership tmp = GetExistingByPrimaryKey(ugid);
|
||||
Membership tmp = GetCachedByPrimaryKey(ugid);
|
||||
if (tmp == null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -630,7 +655,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
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();
|
||||
return membership;
|
||||
}
|
||||
|
Reference in New Issue
Block a user