This commit is contained in:
2008-08-12 11:25:17 +00:00
parent 25458190e6
commit 50e163dae0
8 changed files with 493 additions and 279 deletions

View File

@@ -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<FolderInfo> _AllList = new List<FolderInfo>();
private static Dictionary<string, List<FolderInfo>> _AllByPrimaryKey = new Dictionary<string, List<FolderInfo>>();
private static List<FolderInfo> _CacheList = new List<FolderInfo>();
protected static void AddToCache(FolderInfo folderInfo)
{
if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache
}
protected static void RemoveFromCache(FolderInfo folderInfo)
{
while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache
}
private static Dictionary<string, List<FolderInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FolderInfo>>();
private static void ConvertListToDictionary()
{
List<FolderInfo> remove = new List<FolderInfo>();
foreach (FolderInfo tmp in _AllList)
foreach (FolderInfo tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.FolderID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString()))
{
_AllByPrimaryKey[tmp.FolderID.ToString()] = new List<FolderInfo>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.FolderID.ToString()] = new List<FolderInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list
_CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (FolderInfo tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
internal static void AddList(FolderInfoList lst)
{
foreach (FolderInfo item in lst) _AllList.Add(item);
foreach (FolderInfo item in lst) AddToCache(item);
}
public static FolderInfo GetExistingByPrimaryKey(int folderID)
protected static FolderInfo GetCachedByPrimaryKey(int folderID)
{
ConvertListToDictionary();
string key = folderID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
@@ -189,6 +197,16 @@ namespace VEPROMS.CSLA.Library
return _MyFormat;
}
}
private double? _ManualOrder;
public double? ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ManualOrder", true);
return _ManualOrder;
}
}
private string _Config = string.Empty;
public string Config
{
@@ -247,11 +265,11 @@ namespace VEPROMS.CSLA.Library
return _FolderAssignments;
}
}
internal void RefreshFolderAssignments()
public void RefreshFolderAssignments()
{
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _AllByPrimaryKey[_FolderID.ToString()])
if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried
}
private int _FolderDocVersionCount = 0;
@@ -282,11 +300,11 @@ namespace VEPROMS.CSLA.Library
return _FolderDocVersions;
}
}
internal void RefreshFolderDocVersions()
public void RefreshFolderDocVersions()
{
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _AllByPrimaryKey[_FolderID.ToString()])
if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried
}
private int _ChildFolderCount = 0;
@@ -317,11 +335,11 @@ namespace VEPROMS.CSLA.Library
return _ChildFolders;
}
}
internal void RefreshChildFolders()
public void RefreshChildFolders()
{
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _AllByPrimaryKey[_FolderID.ToString()])
if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._ChildFolderCount = -1; // This will cause the data to be requeried
}
// TODO: Replace base FolderInfo.ToString function as necessary
@@ -345,24 +363,23 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Factory Methods
private static int _FolderInfoUnique = 0;
private int _MyFolderInfoUnique;
private static int FolderInfoUnique
{ get { return ++_FolderInfoUnique; } }
private int _MyFolderInfoUnique = FolderInfoUnique;
public int MyFolderInfoUnique
{
get { return _MyFolderInfoUnique; }
}
private FolderInfo()
{ get { return _MyFolderInfoUnique; } }
protected FolderInfo()
{/* require use of factory methods */
_MyFolderInfoUnique = ++_FolderInfoUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(FolderID.ToString())) return;
List<FolderInfo> listFolderInfo = _AllByPrimaryKey[FolderID.ToString()]; // Get the list of items
listFolderInfo.Remove(this); // Remove the item from the list
RemoveFromCache(this);
if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return;
List<FolderInfo> listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items
while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list
if (listFolderInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(FolderID.ToString()); // remove the list
_CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list
}
public virtual Folder Get()
{
@@ -372,22 +389,22 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.FolderID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Folder tmp)
protected virtual void RefreshFields(Folder tmp)
{
if (_ParentID != tmp.ParentID)
{
MyParent.RefreshChildFolders(); // Update List for old value
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
MyConnection.RefreshConnectionFolders(); // Update List for old value
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
@@ -397,11 +414,12 @@ namespace VEPROMS.CSLA.Library
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
MyFormat.RefreshFormatFolders(); // Update List for old value
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UsrID = tmp.UsrID;
@@ -415,15 +433,15 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.FolderID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ConnectionFolder tmp)
protected virtual void RefreshFields(ConnectionFolder tmp)
{
if (_ParentID != tmp.ParentID)
{
MyParent.RefreshChildFolders(); // Update List for old value
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
@@ -433,11 +451,12 @@ namespace VEPROMS.CSLA.Library
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
MyFormat.RefreshFormatFolders(); // Update List for old value
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UsrID = tmp.UsrID;
@@ -451,22 +470,22 @@ namespace VEPROMS.CSLA.Library
{
string key = tmp.FolderID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _AllByPrimaryKey[key])
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(FormatFolder tmp)
protected virtual void RefreshFields(FormatFolder tmp)
{
if (_ParentID != tmp.ParentID)
{
MyParent.RefreshChildFolders(); // Update List for old value
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
MyConnection.RefreshConnectionFolders(); // Update List for old value
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
@@ -474,6 +493,7 @@ namespace VEPROMS.CSLA.Library
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UsrID = tmp.UsrID;
@@ -489,13 +509,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
FolderInfo tmp = GetExistingByPrimaryKey(folderID);
FolderInfo tmp = GetCachedByPrimaryKey(folderID);
if (tmp == null)
{
tmp = DataPortal.Fetch<FolderInfo>(new PKCriteria(folderID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up FolderInfo
tmp = null;
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
}
catch (Exception ex)
@@ -507,7 +531,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal FolderInfo(SafeDataReader dr)
{
_MyFolderInfoUnique = ++_FolderInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode());
try
{
@@ -542,6 +565,7 @@ namespace VEPROMS.CSLA.Library
_Title = dr.GetString("Title");
_ShortName = dr.GetString("ShortName");
_FormatID = (int?)dr.GetValue("FormatID");
_ManualOrder = (double?)dr.GetValue("ManualOrder");
_Config = dr.GetString("Config");
_DTS = dr.GetDateTime("DTS");
_UsrID = dr.GetString("UsrID");