This commit is contained in:
@@ -117,28 +117,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Content> _AllList = new List<Content>();
|
||||
private static Dictionary<string, List<Content>> _AllByPrimaryKey = new Dictionary<string, List<Content>>();
|
||||
private static List<Content> _CacheList = new List<Content>();
|
||||
protected static void AddToCache(Content content)
|
||||
{
|
||||
if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Content content)
|
||||
{
|
||||
while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Content>> _CacheByPrimaryKey = new Dictionary<string, List<Content>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Content> remove = new List<Content>();
|
||||
foreach (Content tmp in _AllList)
|
||||
foreach (Content tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.ContentID.ToString()] = new List<Content>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.ContentID.ToString()] = new List<Content>(); // 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 (Content tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Content GetExistingByPrimaryKey(int contentID)
|
||||
protected static Content 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,7 +262,7 @@ namespace VEPROMS.CSLA.Library
|
||||
set
|
||||
{
|
||||
CanWriteProperty("MyFormat", true);
|
||||
if (_MyFormat != value)
|
||||
if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID))
|
||||
{
|
||||
_MyFormat = value;
|
||||
_FormatID = (value == null ? null : (int?)value.FormatID);
|
||||
@@ -714,24 +722,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _ContentUnique = 0;
|
||||
private int _MyContentUnique;
|
||||
protected static int ContentUnique
|
||||
{ get { return ++_ContentUnique; } }
|
||||
private int _MyContentUnique = ContentUnique;
|
||||
public int MyContentUnique
|
||||
{
|
||||
get { return _MyContentUnique; }
|
||||
}
|
||||
{ get { return _MyContentUnique; } }
|
||||
protected Content()
|
||||
{/* require use of factory methods */
|
||||
_MyContentUnique = ++_ContentUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return;
|
||||
List<Content> listContent = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items
|
||||
listContent.Remove(this); // Remove the item from the list
|
||||
if (listContent.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<Content> listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items
|
||||
while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list
|
||||
if (listContent.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Content New()
|
||||
{
|
||||
@@ -762,7 +775,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Content tmp = Content.New(number, text, type, myFormat, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Content tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -788,7 +805,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Content tmp = Content.New(number, text, type, myFormat, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Content tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -806,13 +827,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Content");
|
||||
try
|
||||
{
|
||||
Content tmp = GetExistingByPrimaryKey(contentID);
|
||||
Content tmp = GetCachedByPrimaryKey(contentID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Content>(new PKCriteria(contentID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Content
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -854,7 +879,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Content content = base.Save();
|
||||
_AllList.Add(content);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(content);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return content;
|
||||
}
|
||||
|
Reference in New Issue
Block a user