This commit is contained in:
@@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<RoUsage> _AllList = new List<RoUsage>();
|
||||
private static Dictionary<string, List<RoUsage>> _AllByPrimaryKey = new Dictionary<string, List<RoUsage>>();
|
||||
private static List<RoUsage> _CacheList = new 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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
foreach (RoUsage tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static RoUsage GetExistingByPrimaryKey(int rOUsageID)
|
||||
protected static RoUsage GetCachedByPrimaryKey(int rOUsageID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = rOUsageID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -372,24 +380,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _RoUsageUnique = 0;
|
||||
private int _MyRoUsageUnique;
|
||||
protected static int RoUsageUnique
|
||||
{ get { return ++_RoUsageUnique; } }
|
||||
private int _MyRoUsageUnique = RoUsageUnique;
|
||||
public int MyRoUsageUnique
|
||||
{
|
||||
get { return _MyRoUsageUnique; }
|
||||
}
|
||||
{ get { return _MyRoUsageUnique; } }
|
||||
protected RoUsage()
|
||||
{/* require use of factory methods */
|
||||
_MyRoUsageUnique = ++_RoUsageUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(ROUsageID.ToString())) return;
|
||||
List<RoUsage> listRoUsage = _AllByPrimaryKey[ROUsageID.ToString()]; // Get the list of items
|
||||
listRoUsage.Remove(this); // Remove the item from the list
|
||||
if (listRoUsage.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
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
|
||||
_CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static RoUsage New()
|
||||
{
|
||||
@@ -424,7 +437,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
RoUsage tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -448,7 +465,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
RoUsage tmp = RoUsage.New(myContent, roid, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
RoUsage tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
try
|
||||
{
|
||||
RoUsage tmp = GetExistingByPrimaryKey(rOUsageID);
|
||||
RoUsage tmp = GetCachedByPrimaryKey(rOUsageID);
|
||||
if (tmp == null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -514,7 +539,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
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();
|
||||
return roUsage;
|
||||
}
|
||||
|
Reference in New Issue
Block a user