This commit is contained in:
@@ -97,38 +97,46 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Format> _AllList = new List<Format>();
|
||||
private static Dictionary<string, List<Format>> _AllByPrimaryKey = new Dictionary<string, List<Format>>();
|
||||
private static Dictionary<string, List<Format>> _AllByParentID_Name = new Dictionary<string, List<Format>>();
|
||||
private static List<Format> _CacheList = new List<Format>();
|
||||
protected static void AddToCache(Format format)
|
||||
{
|
||||
if (!_CacheList.Contains(format)) _CacheList.Add(format); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Format format)
|
||||
{
|
||||
while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Format>> _CacheByPrimaryKey = new Dictionary<string, List<Format>>();
|
||||
private static Dictionary<string, List<Format>> _CacheByParentID_Name = new Dictionary<string, List<Format>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Format> remove = new List<Format>();
|
||||
foreach (Format tmp in _AllList)
|
||||
foreach (Format tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.FormatID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()] = new List<Format>(); // Add new list for PrimaryKey
|
||||
_AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List<Format>(); // Add new list for ParentID_Name
|
||||
_CacheByPrimaryKey[tmp.FormatID.ToString()] = new List<Format>(); // Add new list for PrimaryKey
|
||||
_CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List<Format>(); // Add new list for ParentID_Name
|
||||
}
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||
_CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (Format tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Format GetExistingByPrimaryKey(int formatID)
|
||||
protected static Format GetCachedByPrimaryKey(int formatID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = formatID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
public static Format GetExistingByParentID_Name(int parentID, string name)
|
||||
protected static Format GetCachedByParentID_Name(int parentID, string name)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = parentID.ToString() + "_" + name.ToString();
|
||||
if (_AllByParentID_Name.ContainsKey(key)) return _AllByParentID_Name[key][0];
|
||||
if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -614,28 +622,41 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _FormatUnique = 0;
|
||||
private int _MyFormatUnique;
|
||||
protected static int FormatUnique
|
||||
{ get { return ++_FormatUnique; } }
|
||||
private int _MyFormatUnique = FormatUnique;
|
||||
public int MyFormatUnique
|
||||
{
|
||||
get { return _MyFormatUnique; }
|
||||
}
|
||||
{ get { return _MyFormatUnique; } }
|
||||
protected Format()
|
||||
{/* require use of factory methods */
|
||||
_MyFormatUnique = ++_FormatUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(FormatID.ToString())) return;
|
||||
List<Format> listFormat = _AllByPrimaryKey[FormatID.ToString()]; // Get the list of items
|
||||
listFormat.Remove(this); // Remove the item from the list
|
||||
if (listFormat.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(FormatID.ToString()); // remove the list
|
||||
listFormat = _AllByParentID_Name[FormatID.ToString()]; // Get the list of items
|
||||
listFormat.Remove(this); // Remove the item from the list
|
||||
if (listFormat.Count == 0) //If there are no items left in the list
|
||||
_AllByParentID_Name.Remove(FormatID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(FormatID.ToString()))
|
||||
{
|
||||
List<Format> listFormat = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items
|
||||
while (listFormat.Contains(this)) listFormat.Remove(this); // Remove the item from the list
|
||||
if (listFormat.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list
|
||||
}
|
||||
string myKey;
|
||||
myKey = null;
|
||||
foreach (string key in _CacheByParentID_Name.Keys)
|
||||
if (_CacheByParentID_Name[key].Contains(this))
|
||||
myKey = key;
|
||||
if (myKey != null)
|
||||
{
|
||||
List<Format> listFormat = _CacheByParentID_Name[myKey]; // Get the list of items
|
||||
listFormat.Remove(this); // Remove the item from the list
|
||||
if (listFormat.Count == 0) //If there are no items left in the list
|
||||
_CacheByParentID_Name.Remove(myKey); // remove the list
|
||||
}
|
||||
}
|
||||
public static Format New()
|
||||
{
|
||||
@@ -674,7 +695,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Format tmp = Format.New(myParent, name, description, data, genMac, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Format tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -700,7 +725,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Format tmp = Format.New(myParent, name, description, data, genMac);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Format tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -718,13 +747,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Format");
|
||||
try
|
||||
{
|
||||
Format tmp = GetExistingByPrimaryKey(formatID);
|
||||
Format tmp = GetCachedByPrimaryKey(formatID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Format>(new PKCriteria(formatID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Format
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -732,19 +765,23 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on Format.Get", ex);
|
||||
}
|
||||
}
|
||||
private static Format GetByParentID_Name(int parentID, string name)
|
||||
public static Format GetByParentID_Name(int parentID, string name)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Format");
|
||||
try
|
||||
{
|
||||
Format tmp = GetExistingByParentID_Name(parentID, name);
|
||||
Format tmp = GetCachedByParentID_Name(parentID, name);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Format>(new ParentID_NameCriteria(parentID, name));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Format
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -796,7 +833,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Format format = base.Save();
|
||||
_AllList.Add(format);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(format);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return format;
|
||||
}
|
||||
|
Reference in New Issue
Block a user