This commit is contained in:
@@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<FormatInfo> _AllList = new List<FormatInfo>();
|
||||
private static Dictionary<string, List<FormatInfo>> _AllByPrimaryKey = new Dictionary<string, List<FormatInfo>>();
|
||||
private static List<FormatInfo> _CacheList = new List<FormatInfo>();
|
||||
protected static void AddToCache(FormatInfo formatInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(formatInfo)) _CacheList.Add(formatInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(FormatInfo formatInfo)
|
||||
{
|
||||
while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<FormatInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FormatInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<FormatInfo> remove = new List<FormatInfo>();
|
||||
foreach (FormatInfo tmp in _AllList)
|
||||
foreach (FormatInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.FormatID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()] = new List<FormatInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.FormatID.ToString()] = new List<FormatInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (FormatInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(FormatInfoList lst)
|
||||
{
|
||||
foreach (FormatInfo item in lst) _AllList.Add(item);
|
||||
foreach (FormatInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static FormatInfo GetExistingByPrimaryKey(int formatID)
|
||||
protected static FormatInfo 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;
|
||||
}
|
||||
#endregion
|
||||
@@ -203,11 +211,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _FormatContents;
|
||||
}
|
||||
}
|
||||
internal void RefreshFormatContents()
|
||||
public void RefreshFormatContents()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._FormatContentCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _FormatDocVersionCount = 0;
|
||||
@@ -238,11 +246,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _FormatDocVersions;
|
||||
}
|
||||
}
|
||||
internal void RefreshFormatDocVersions()
|
||||
public void RefreshFormatDocVersions()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._FormatDocVersionCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _FormatFolderCount = 0;
|
||||
@@ -273,11 +281,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _FormatFolders;
|
||||
}
|
||||
}
|
||||
internal void RefreshFormatFolders()
|
||||
public void RefreshFormatFolders()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._FormatFolderCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _ChildFormatCount = 0;
|
||||
@@ -308,11 +316,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ChildFormats;
|
||||
}
|
||||
}
|
||||
internal void RefreshChildFormats()
|
||||
public void RefreshChildFormats()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._ChildFormatCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base FormatInfo.ToString function as necessary
|
||||
@@ -336,24 +344,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _FormatInfoUnique = 0;
|
||||
private int _MyFormatInfoUnique;
|
||||
private static int FormatInfoUnique
|
||||
{ get { return ++_FormatInfoUnique; } }
|
||||
private int _MyFormatInfoUnique = FormatInfoUnique;
|
||||
public int MyFormatInfoUnique
|
||||
{
|
||||
get { return _MyFormatInfoUnique; }
|
||||
}
|
||||
private FormatInfo()
|
||||
{ get { return _MyFormatInfoUnique; } }
|
||||
protected FormatInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyFormatInfoUnique = ++_FormatInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(FormatID.ToString())) return;
|
||||
List<FormatInfo> listFormatInfo = _AllByPrimaryKey[FormatID.ToString()]; // Get the list of items
|
||||
listFormatInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) return;
|
||||
List<FormatInfo> listFormatInfo = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items
|
||||
while (listFormatInfo.Contains(this)) listFormatInfo.Remove(this); // Remove the item from the list
|
||||
if (listFormatInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(FormatID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Format Get()
|
||||
{
|
||||
@@ -363,15 +370,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.FormatID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (FormatInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (FormatInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Format tmp)
|
||||
protected virtual void RefreshFields(Format tmp)
|
||||
{
|
||||
if (_ParentID != tmp.ParentID)
|
||||
{
|
||||
MyParent.RefreshChildFormats(); // Update List for old value
|
||||
if (MyParent != null) MyParent.RefreshChildFormats(); // Update List for old value
|
||||
_ParentID = tmp.ParentID; // Update the value
|
||||
}
|
||||
_MyParent = null; // Reset list so that the next line gets a new list
|
||||
@@ -392,13 +399,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Format");
|
||||
try
|
||||
{
|
||||
FormatInfo tmp = GetExistingByPrimaryKey(formatID);
|
||||
FormatInfo tmp = GetCachedByPrimaryKey(formatID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<FormatInfo>(new PKCriteria(formatID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up FormatInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -410,7 +421,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal FormatInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyFormatInfoUnique = ++_FormatInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user