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<DocumentInfo> _AllList = new List<DocumentInfo>();
|
||||
private static Dictionary<string, List<DocumentInfo>> _AllByPrimaryKey = new Dictionary<string, List<DocumentInfo>>();
|
||||
private static List<DocumentInfo> _CacheList = new List<DocumentInfo>();
|
||||
protected static void AddToCache(DocumentInfo documentInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(documentInfo)) _CacheList.Add(documentInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(DocumentInfo documentInfo)
|
||||
{
|
||||
while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<DocumentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DocumentInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<DocumentInfo> remove = new List<DocumentInfo>();
|
||||
foreach (DocumentInfo tmp in _AllList)
|
||||
foreach (DocumentInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DocID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.DocID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DocID.ToString()] = new List<DocumentInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.DocID.ToString()] = new List<DocumentInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (DocumentInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(DocumentInfoList lst)
|
||||
{
|
||||
foreach (DocumentInfo item in lst) _AllList.Add(item);
|
||||
foreach (DocumentInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static DocumentInfo GetExistingByPrimaryKey(int docID)
|
||||
protected static DocumentInfo GetCachedByPrimaryKey(int docID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = docID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -187,11 +195,11 @@ namespace VEPROMS.CSLA.Library
|
||||
return _DocumentEntries;
|
||||
}
|
||||
}
|
||||
internal void RefreshDocumentEntries()
|
||||
public void RefreshDocumentEntries()
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_DocID.ToString()))
|
||||
foreach (DocumentInfo tmp in _AllByPrimaryKey[_DocID.ToString()])
|
||||
if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString()))
|
||||
foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()])
|
||||
tmp._DocumentEntryCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base DocumentInfo.ToString function as necessary
|
||||
@@ -215,24 +223,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _DocumentInfoUnique = 0;
|
||||
private int _MyDocumentInfoUnique;
|
||||
private static int DocumentInfoUnique
|
||||
{ get { return ++_DocumentInfoUnique; } }
|
||||
private int _MyDocumentInfoUnique = DocumentInfoUnique;
|
||||
public int MyDocumentInfoUnique
|
||||
{
|
||||
get { return _MyDocumentInfoUnique; }
|
||||
}
|
||||
private DocumentInfo()
|
||||
{ get { return _MyDocumentInfoUnique; } }
|
||||
protected DocumentInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyDocumentInfoUnique = ++_DocumentInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(DocID.ToString())) return;
|
||||
List<DocumentInfo> listDocumentInfo = _AllByPrimaryKey[DocID.ToString()]; // Get the list of items
|
||||
listDocumentInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString())) return;
|
||||
List<DocumentInfo> listDocumentInfo = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items
|
||||
while (listDocumentInfo.Contains(this)) listDocumentInfo.Remove(this); // Remove the item from the list
|
||||
if (listDocumentInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DocID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Document Get()
|
||||
{
|
||||
@@ -242,11 +249,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.DocID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocumentInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocumentInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Document tmp)
|
||||
protected virtual void RefreshFields(Document tmp)
|
||||
{
|
||||
_LibTitle = tmp.LibTitle;
|
||||
_DocContent = tmp.DocContent;
|
||||
@@ -263,13 +270,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Document");
|
||||
try
|
||||
{
|
||||
DocumentInfo tmp = GetExistingByPrimaryKey(docID);
|
||||
DocumentInfo tmp = GetCachedByPrimaryKey(docID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<DocumentInfo>(new PKCriteria(docID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up DocumentInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -281,7 +292,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal DocumentInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyDocumentInfoUnique = ++_DocumentInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user