This commit is contained in:
@@ -51,28 +51,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<ZContent> _AllList = new List<ZContent>();
|
||||
private static Dictionary<string, List<ZContent>> _AllByPrimaryKey = new Dictionary<string, List<ZContent>>();
|
||||
private static List<ZContent> _CacheList = new 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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
foreach (ZContent tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static ZContent GetExistingByPrimaryKey(int contentID)
|
||||
protected static ZContent GetCachedByPrimaryKey(int contentID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = contentID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -254,24 +262,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _ZContentUnique = 0;
|
||||
private int _MyZContentUnique;
|
||||
protected static int ZContentUnique
|
||||
{ get { return ++_ZContentUnique; } }
|
||||
private int _MyZContentUnique = ZContentUnique;
|
||||
public int MyZContentUnique
|
||||
{
|
||||
get { return _MyZContentUnique; }
|
||||
}
|
||||
{ get { return _MyZContentUnique; } }
|
||||
protected ZContent()
|
||||
{/* require use of factory methods */
|
||||
_MyZContentUnique = ++_ZContentUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return;
|
||||
List<ZContent> listZContent = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items
|
||||
listZContent.Remove(this); // Remove the item from the list
|
||||
if (listZContent.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
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
|
||||
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static ZContent New()
|
||||
{
|
||||
@@ -297,7 +310,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
ZContent tmp = ZContent.New(myContent, oldStepSequence);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
ZContent tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
try
|
||||
{
|
||||
ZContent tmp = GetExistingByPrimaryKey(contentID);
|
||||
ZContent tmp = GetCachedByPrimaryKey(contentID);
|
||||
if (tmp == null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -371,7 +392,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
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();
|
||||
return zContent;
|
||||
}
|
||||
|
Reference in New Issue
Block a user