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<DocVersionInfo> _AllList = new List<DocVersionInfo>();
|
||||
private static Dictionary<string, List<DocVersionInfo>> _AllByPrimaryKey = new Dictionary<string, List<DocVersionInfo>>();
|
||||
private static List<DocVersionInfo> _CacheList = new List<DocVersionInfo>();
|
||||
protected static void AddToCache(DocVersionInfo docVersionInfo)
|
||||
{
|
||||
if (!_CacheList.Contains(docVersionInfo)) _CacheList.Add(docVersionInfo); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(DocVersionInfo docVersionInfo)
|
||||
{
|
||||
while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<DocVersionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DocVersionInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<DocVersionInfo> remove = new List<DocVersionInfo>();
|
||||
foreach (DocVersionInfo tmp in _AllList)
|
||||
foreach (DocVersionInfo tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.VersionID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.VersionID.ToString()] = new List<DocVersionInfo>(); // Add new list for PrimaryKey
|
||||
_CacheByPrimaryKey[tmp.VersionID.ToString()] = new List<DocVersionInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (DocVersionInfo tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
internal static void AddList(DocVersionInfoList lst)
|
||||
{
|
||||
foreach (DocVersionInfo item in lst) _AllList.Add(item);
|
||||
foreach (DocVersionInfo item in lst) AddToCache(item);
|
||||
}
|
||||
public static DocVersionInfo GetExistingByPrimaryKey(int versionID)
|
||||
protected static DocVersionInfo GetCachedByPrimaryKey(int versionID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = versionID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -243,24 +251,23 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _DocVersionInfoUnique = 0;
|
||||
private int _MyDocVersionInfoUnique;
|
||||
private static int DocVersionInfoUnique
|
||||
{ get { return ++_DocVersionInfoUnique; } }
|
||||
private int _MyDocVersionInfoUnique = DocVersionInfoUnique;
|
||||
public int MyDocVersionInfoUnique
|
||||
{
|
||||
get { return _MyDocVersionInfoUnique; }
|
||||
}
|
||||
private DocVersionInfo()
|
||||
{ get { return _MyDocVersionInfoUnique; } }
|
||||
protected DocVersionInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyDocVersionInfoUnique = ++_DocVersionInfoUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(VersionID.ToString())) return;
|
||||
List<DocVersionInfo> listDocVersionInfo = _AllByPrimaryKey[VersionID.ToString()]; // Get the list of items
|
||||
listDocVersionInfo.Remove(this); // Remove the item from the list
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return;
|
||||
List<DocVersionInfo> listDocVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items
|
||||
while (listDocVersionInfo.Contains(this)) listDocVersionInfo.Remove(this); // Remove the item from the list
|
||||
if (listDocVersionInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(VersionID.ToString()); // remove the list
|
||||
_CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list
|
||||
}
|
||||
public virtual DocVersion Get()
|
||||
{
|
||||
@@ -270,15 +277,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.VersionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(DocVersion tmp)
|
||||
protected virtual void RefreshFields(DocVersion tmp)
|
||||
{
|
||||
if (_FolderID != tmp.FolderID)
|
||||
{
|
||||
MyFolder.RefreshFolderDocVersions(); // Update List for old value
|
||||
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value
|
||||
_FolderID = tmp.FolderID; // Update the value
|
||||
}
|
||||
_MyFolder = null; // Reset list so that the next line gets a new list
|
||||
@@ -288,14 +295,14 @@ namespace VEPROMS.CSLA.Library
|
||||
_Title = tmp.Title;
|
||||
if (_ItemID != tmp.ItemID)
|
||||
{
|
||||
MyItem.RefreshItemDocVersions(); // Update List for old value
|
||||
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value
|
||||
_ItemID = tmp.ItemID; // Update the value
|
||||
}
|
||||
_MyItem = null; // Reset list so that the next line gets a new list
|
||||
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value
|
||||
if (_FormatID != tmp.FormatID)
|
||||
{
|
||||
MyFormat.RefreshFormatDocVersions(); // Update List for old value
|
||||
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value
|
||||
_FormatID = tmp.FormatID; // Update the value
|
||||
}
|
||||
_MyFormat = null; // Reset list so that the next line gets a new list
|
||||
@@ -313,25 +320,25 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.VersionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(FolderDocVersion tmp)
|
||||
protected virtual void RefreshFields(FolderDocVersion tmp)
|
||||
{
|
||||
_VersionType = tmp.VersionType;
|
||||
_Name = tmp.Name;
|
||||
_Title = tmp.Title;
|
||||
if (_ItemID != tmp.ItemID)
|
||||
{
|
||||
MyItem.RefreshItemDocVersions(); // Update List for old value
|
||||
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value
|
||||
_ItemID = tmp.ItemID; // Update the value
|
||||
}
|
||||
_MyItem = null; // Reset list so that the next line gets a new list
|
||||
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value
|
||||
if (_FormatID != tmp.FormatID)
|
||||
{
|
||||
MyFormat.RefreshFormatDocVersions(); // Update List for old value
|
||||
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value
|
||||
_FormatID = tmp.FormatID; // Update the value
|
||||
}
|
||||
_MyFormat = null; // Reset list so that the next line gets a new list
|
||||
@@ -349,15 +356,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.VersionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(FormatDocVersion tmp)
|
||||
protected virtual void RefreshFields(FormatDocVersion tmp)
|
||||
{
|
||||
if (_FolderID != tmp.FolderID)
|
||||
{
|
||||
MyFolder.RefreshFolderDocVersions(); // Update List for old value
|
||||
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value
|
||||
_FolderID = tmp.FolderID; // Update the value
|
||||
}
|
||||
_MyFolder = null; // Reset list so that the next line gets a new list
|
||||
@@ -367,7 +374,7 @@ namespace VEPROMS.CSLA.Library
|
||||
_Title = tmp.Title;
|
||||
if (_ItemID != tmp.ItemID)
|
||||
{
|
||||
MyItem.RefreshItemDocVersions(); // Update List for old value
|
||||
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value
|
||||
_ItemID = tmp.ItemID; // Update the value
|
||||
}
|
||||
_MyItem = null; // Reset list so that the next line gets a new list
|
||||
@@ -385,15 +392,15 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
string key = tmp.VersionID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(ItemDocVersion tmp)
|
||||
protected virtual void RefreshFields(ItemDocVersion tmp)
|
||||
{
|
||||
if (_FolderID != tmp.FolderID)
|
||||
{
|
||||
MyFolder.RefreshFolderDocVersions(); // Update List for old value
|
||||
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value
|
||||
_FolderID = tmp.FolderID; // Update the value
|
||||
}
|
||||
_MyFolder = null; // Reset list so that the next line gets a new list
|
||||
@@ -403,7 +410,7 @@ namespace VEPROMS.CSLA.Library
|
||||
_Title = tmp.Title;
|
||||
if (_FormatID != tmp.FormatID)
|
||||
{
|
||||
MyFormat.RefreshFormatDocVersions(); // Update List for old value
|
||||
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value
|
||||
_FormatID = tmp.FormatID; // Update the value
|
||||
}
|
||||
_MyFormat = null; // Reset list so that the next line gets a new list
|
||||
@@ -423,13 +430,17 @@ namespace VEPROMS.CSLA.Library
|
||||
// throw new System.Security.SecurityException("User not authorized to view a DocVersion");
|
||||
try
|
||||
{
|
||||
DocVersionInfo tmp = GetExistingByPrimaryKey(versionID);
|
||||
DocVersionInfo tmp = GetCachedByPrimaryKey(versionID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<DocVersionInfo>(new PKCriteria(versionID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up DocVersionInfo
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -441,7 +452,6 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal DocVersionInfo(SafeDataReader dr)
|
||||
{
|
||||
_MyDocVersionInfoUnique = ++_DocVersionInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user