This commit is contained in:
@@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Detail> _AllList = new List<Detail>();
|
||||
private static Dictionary<string, List<Detail>> _AllByPrimaryKey = new Dictionary<string, List<Detail>>();
|
||||
private static List<Detail> _CacheList = new List<Detail>();
|
||||
protected static void AddToCache(Detail detail)
|
||||
{
|
||||
if (!_CacheList.Contains(detail)) _CacheList.Add(detail); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Detail detail)
|
||||
{
|
||||
while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Detail>> _CacheByPrimaryKey = new Dictionary<string, List<Detail>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Detail> remove = new List<Detail>();
|
||||
foreach (Detail tmp in _AllList)
|
||||
foreach (Detail tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()] = new List<Detail>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()] = new List<Detail>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (Detail tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Detail GetExistingByPrimaryKey(int detailID)
|
||||
protected static Detail GetCachedByPrimaryKey(int detailID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = detailID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -394,24 +402,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _DetailUnique = 0;
|
||||
private int _MyDetailUnique;
|
||||
protected static int DetailUnique
|
||||
{ get { return ++_DetailUnique; } }
|
||||
private int _MyDetailUnique = DetailUnique;
|
||||
public int MyDetailUnique
|
||||
{
|
||||
get { return _MyDetailUnique; }
|
||||
}
|
||||
{ get { return _MyDetailUnique; } }
|
||||
protected Detail()
|
||||
{/* require use of factory methods */
|
||||
_MyDetailUnique = ++_DetailUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(DetailID.ToString())) return;
|
||||
List<Detail> listDetail = _AllByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
listDetail.Remove(this); // Remove the item from the list
|
||||
if (listDetail.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(DetailID.ToString()))
|
||||
{
|
||||
List<Detail> listDetail = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
while (listDetail.Contains(this)) listDetail.Remove(this); // Remove the item from the list
|
||||
if (listDetail.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Detail New()
|
||||
{
|
||||
@@ -449,7 +462,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Detail tmp = Detail.New(myContent, itemType, text, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Detail tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -474,7 +491,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Detail tmp = Detail.New(myContent, itemType, text, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Detail tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -492,13 +513,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Detail");
|
||||
try
|
||||
{
|
||||
Detail tmp = GetExistingByPrimaryKey(detailID);
|
||||
Detail tmp = GetCachedByPrimaryKey(detailID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Detail>(new PKCriteria(detailID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Detail
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -540,7 +565,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Detail detail = base.Save();
|
||||
_AllList.Add(detail);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(detail);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return detail;
|
||||
}
|
||||
|
Reference in New Issue
Block a user