This commit is contained in:
parent
f42f176ae9
commit
25458190e6
@ -52,28 +52,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Detail> _AllList = new List<Detail>();
|
||||
private static Dictionary<string, List<Detail>> _AllByPrimaryKey = new Dictionary<string, List<Detail>>();
|
||||
private static List<Detail> _CacheList = new List<Detail>();
|
||||
protected static void AddToCache(Detail detail)
|
||||
{
|
||||
if (!_CacheList.Contains(detail)) _CacheList.Add(detail); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Detail detail)
|
||||
{
|
||||
while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Detail>> _CacheByPrimaryKey = new Dictionary<string, List<Detail>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Detail> remove = new List<Detail>();
|
||||
foreach (Detail tmp in _AllList)
|
||||
foreach (Detail tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()] = new List<Detail>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()] = new List<Detail>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (Detail tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Detail GetExistingByPrimaryKey(int detailID)
|
||||
protected static Detail GetCachedByPrimaryKey(int detailID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = detailID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@ -394,24 +402,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _DetailUnique = 0;
|
||||
private int _MyDetailUnique;
|
||||
protected static int DetailUnique
|
||||
{ get { return ++_DetailUnique; } }
|
||||
private int _MyDetailUnique = DetailUnique;
|
||||
public int MyDetailUnique
|
||||
{
|
||||
get { return _MyDetailUnique; }
|
||||
}
|
||||
{ get { return _MyDetailUnique; } }
|
||||
protected Detail()
|
||||
{/* require use of factory methods */
|
||||
_MyDetailUnique = ++_DetailUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(DetailID.ToString())) return;
|
||||
List<Detail> listDetail = _AllByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
listDetail.Remove(this); // Remove the item from the list
|
||||
if (listDetail.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(DetailID.ToString()))
|
||||
{
|
||||
List<Detail> listDetail = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
while (listDetail.Contains(this)) listDetail.Remove(this); // Remove the item from the list
|
||||
if (listDetail.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Detail New()
|
||||
{
|
||||
@ -449,7 +462,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Detail tmp = Detail.New(myContent, itemType, text, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Detail tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@ -474,7 +491,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Detail tmp = Detail.New(myContent, itemType, text, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Detail tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@ -492,13 +513,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Detail");
|
||||
try
|
||||
{
|
||||
Detail tmp = GetExistingByPrimaryKey(detailID);
|
||||
Detail tmp = GetCachedByPrimaryKey(detailID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Detail>(new PKCriteria(detailID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Detail
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -540,7 +565,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Detail detail = base.Save();
|
||||
_AllList.Add(detail);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(detail);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return detail;
|
||||
}
|
||||
|
@ -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<DetailInfo> _AllList = new List<DetailInfo>();
|
||||
private static Dictionary<string, List<DetailInfo>> _AllByPrimaryKey = new Dictionary<string, List<DetailInfo>>();
|
||||
private static List<DetailInfo> _CacheList = new List<DetailInfo>();
|
||||
protected static void AddToCache(DetailInfo detailInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(detailInfo)) _CacheList.Add(detailInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(DetailInfo detailInfo)
|
||||
{
|
||||
while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<DetailInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DetailInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<DetailInfo> remove = new List<DetailInfo>();
|
||||
foreach (DetailInfo tmp in _AllList)
|
||||
foreach (DetailInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()] = new List<DetailInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()] = new List<DetailInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (DetailInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(DetailInfoList lst)
|
||||
{
|
||||
foreach (DetailInfo item in lst) _AllList.Add(item);
|
||||
foreach (DetailInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static DetailInfo GetExistingByPrimaryKey(int detailID)
|
||||
protected static DetailInfo GetCachedByPrimaryKey(int detailID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = detailID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@ -186,24 +194,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _DetailInfoUnique = 0;
|
||||
private int _MyDetailInfoUnique;
|
||||
private static int DetailInfoUnique
|
||||
{ get { return ++_DetailInfoUnique; } }
|
||||
private int _MyDetailInfoUnique = DetailInfoUnique;
|
||||
public int MyDetailInfoUnique
|
||||
{
|
||||
get { return _MyDetailInfoUnique; }
|
||||
}
|
||||
private DetailInfo()
|
||||
{ get { return _MyDetailInfoUnique; } }
|
||||
protected DetailInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyDetailInfoUnique = ++_DetailInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(DetailID.ToString())) return;
|
||||
List<DetailInfo> listDetailInfo = _AllByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
listDetailInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) return;
|
||||
List<DetailInfo> listDetailInfo = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items
|
||||
while (listDetailInfo.Contains(this)) listDetailInfo.Remove(this); // Remove the item from the list
|
||||
if (listDetailInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Detail Get()
|
||||
{
|
||||
@ -213,15 +220,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.DetailID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Detail tmp)
|
||||
protected virtual void RefreshFields(Detail tmp)
|
||||
{
|
||||
if (_ContentID != tmp.ContentID)
|
||||
{
|
||||
MyContent.RefreshContentDetails(); // Update List for old value
|
||||
if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for old value
|
||||
_ContentID = tmp.ContentID; // Update the value
|
||||
}
|
||||
_MyContent = null; // Reset list so that the next line gets a new list
|
||||
@ -239,11 +246,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.DetailID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ContentDetail tmp)
|
||||
protected virtual void RefreshFields(ContentDetail tmp)
|
||||
{
|
||||
_ItemType = tmp.ItemType;
|
||||
_Text = tmp.Text;
|
||||
@ -260,13 +267,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Detail");
|
||||
try
|
||||
{
|
||||
DetailInfo tmp = GetExistingByPrimaryKey(detailID);
|
||||
DetailInfo tmp = GetCachedByPrimaryKey(detailID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<DetailInfo>(new PKCriteria(detailID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up DetailInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -278,7 +289,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal DetailInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyDetailInfoUnique = ++_DetailInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
@ -64,28 +64,36 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Document> _AllList = new List<Document>();
|
||||
private static Dictionary<string, List<Document>> _AllByPrimaryKey = new Dictionary<string, List<Document>>();
|
||||
private static List<Document> _CacheList = new List<Document>();
|
||||
protected static void AddToCache(Document document)
|
||||
{
|
||||
if (!_CacheList.Contains(document)) _CacheList.Add(document); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Document document)
|
||||
{
|
||||
while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Document>> _CacheByPrimaryKey = new Dictionary<string, List<Document>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Document> remove = new List<Document>();
|
||||
foreach (Document tmp in _AllList)
|
||||
foreach (Document tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DocID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.DocID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DocID.ToString()] = new List<Document>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.DocID.ToString()] = new List<Document>(); // 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 (Document tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Document GetExistingByPrimaryKey(int docID)
|
||||
protected static Document 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
|
||||
@ -436,24 +444,29 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _DocumentUnique = 0;
|
||||
private int _MyDocumentUnique;
|
||||
protected static int DocumentUnique
|
||||
{ get { return ++_DocumentUnique; } }
|
||||
private int _MyDocumentUnique = DocumentUnique;
|
||||
public int MyDocumentUnique
|
||||
{
|
||||
get { return _MyDocumentUnique; }
|
||||
}
|
||||
{ get { return _MyDocumentUnique; } }
|
||||
protected Document()
|
||||
{/* require use of factory methods */
|
||||
_MyDocumentUnique = ++_DocumentUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(DocID.ToString())) return;
|
||||
List<Document> listDocument = _AllByPrimaryKey[DocID.ToString()]; // Get the list of items
|
||||
listDocument.Remove(this); // Remove the item from the list
|
||||
if (listDocument.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DocID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(DocID.ToString()))
|
||||
{
|
||||
List<Document> listDocument = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items
|
||||
while (listDocument.Contains(this)) listDocument.Remove(this); // Remove the item from the list
|
||||
if (listDocument.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list
|
||||
}
|
||||
}
|
||||
public static Document New()
|
||||
{
|
||||
@ -483,7 +496,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Document tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@ -508,7 +525,11 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Document tmp = Document.New(libTitle, docContent, docAscii, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Document tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@ -526,13 +547,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Document");
|
||||
try
|
||||
{
|
||||
Document tmp = GetExistingByPrimaryKey(docID);
|
||||
Document tmp = GetCachedByPrimaryKey(docID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Document>(new PKCriteria(docID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Document
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -574,7 +599,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Document document = base.Save();
|
||||
_AllList.Add(document);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(document);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return document;
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user