This commit is contained in:
Kathy Ruffing 2008-08-12 11:27:04 +00:00
parent 50e163dae0
commit dfafac5a3a
9 changed files with 352 additions and 202 deletions

View File

@ -181,7 +181,7 @@ namespace VEPROMS.CSLA.Library
set set
{ {
CanWriteProperty("MyItem", true); CanWriteProperty("MyItem", true);
if (_MyItem != value) if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID))
{ {
_MyItem = value; _MyItem = value;
_ItemID = (value == null ? null : (int?)value.ItemID); _ItemID = (value == null ? null : (int?)value.ItemID);
@ -312,6 +312,16 @@ namespace VEPROMS.CSLA.Library
return _Folder_FormatID; return _Folder_FormatID;
} }
} }
private double? _Folder_ManualOrder;
public double? Folder_ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Folder_ManualOrder", true);
return _Folder_ManualOrder;
}
}
private string _Folder_Config = string.Empty; private string _Folder_Config = string.Empty;
public string Folder_Config public string Folder_Config
{ {
@ -551,6 +561,7 @@ namespace VEPROMS.CSLA.Library
_Folder_Title = dr.GetString("Folder_Title"); _Folder_Title = dr.GetString("Folder_Title");
_Folder_ShortName = dr.GetString("Folder_ShortName"); _Folder_ShortName = dr.GetString("Folder_ShortName");
_Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID");
_Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder");
_Folder_Config = dr.GetString("Folder_Config"); _Folder_Config = dr.GetString("Folder_Config");
_Folder_DTS = dr.GetDateTime("Folder_DTS"); _Folder_DTS = dr.GetDateTime("Folder_DTS");
_Folder_UsrID = dr.GetString("Folder_UsrID"); _Folder_UsrID = dr.GetString("Folder_UsrID");

View File

@ -186,6 +186,26 @@ namespace VEPROMS.CSLA.Library
} }
} }
} }
private double? _ManualOrder;
public double? ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ManualOrder", true);
return _ManualOrder;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("ManualOrder", true);
if (_ManualOrder != value)
{
_ManualOrder = value;
PropertyHasChanged();
}
}
}
private string _Config = string.Empty; private string _Config = string.Empty;
public string Config public string Config
{ {
@ -453,6 +473,8 @@ namespace VEPROMS.CSLA.Library
//AuthorizationRules.AllowWrite(Title, "<Role(s)>"); //AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>"); //AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>"); //AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>"); //AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>"); //AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>"); //AuthorizationRules.AllowRead(DTS, "<Role(s)>");
@ -539,6 +561,7 @@ namespace VEPROMS.CSLA.Library
_Name = dr.GetString("Name"); _Name = dr.GetString("Name");
_Title = dr.GetString("Title"); _Title = dr.GetString("Title");
_ShortName = dr.GetString("ShortName"); _ShortName = dr.GetString("ShortName");
_ManualOrder = (double?)dr.GetValue("ManualOrder");
_Config = dr.GetString("Config"); _Config = dr.GetString("Config");
_DTS = dr.GetDateTime("DTS"); _DTS = dr.GetDateTime("DTS");
_UsrID = dr.GetString("UsrID"); _UsrID = dr.GetString("UsrID");
@ -563,7 +586,7 @@ namespace VEPROMS.CSLA.Library
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _Config, _DTS, _UsrID); _LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID);
MarkOld(); MarkOld();
} }
internal void Update(Format myFormat) internal void Update(Format myFormat)
@ -571,7 +594,7 @@ namespace VEPROMS.CSLA.Library
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Update(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _Config, _DTS, _UsrID, ref _LastChanged); _LastChanged = Folder.Update(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
MarkOld(); MarkOld();
} }
internal void DeleteSelf(Format myFormat) internal void DeleteSelf(Format myFormat)

View File

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

View File

@ -77,38 +77,46 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Group> _AllList = new List<Group>(); private static List<Group> _CacheList = new List<Group>();
private static Dictionary<string, List<Group>> _AllByPrimaryKey = new Dictionary<string, List<Group>>(); protected static void AddToCache(Group group)
private static Dictionary<string, List<Group>> _AllByGroupName = new Dictionary<string, List<Group>>(); {
if (!_CacheList.Contains(group)) _CacheList.Add(group); // In AddToCache
}
protected static void RemoveFromCache(Group group)
{
while (_CacheList.Contains(group)) _CacheList.Remove(group); // In RemoveFromCache
}
private static Dictionary<string, List<Group>> _CacheByPrimaryKey = new Dictionary<string, List<Group>>();
private static Dictionary<string, List<Group>> _CacheByGroupName = new Dictionary<string, List<Group>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Group> remove = new List<Group>(); List<Group> remove = new List<Group>();
foreach (Group tmp in _AllList) foreach (Group tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.GID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.GID.ToString()))
{ {
_AllByPrimaryKey[tmp.GID.ToString()] = new List<Group>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.GID.ToString()] = new List<Group>(); // Add new list for PrimaryKey
_AllByGroupName[tmp.GroupName.ToString()] = new List<Group>(); // Add new list for GroupName _CacheByGroupName[tmp.GroupName.ToString()] = new List<Group>(); // Add new list for GroupName
} }
_AllByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list
_AllByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index _CacheByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Group tmp in remove) foreach (Group tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Group GetExistingByPrimaryKey(int gid) protected static Group GetCachedByPrimaryKey(int gid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = gid.ToString(); string key = gid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
public static Group GetExistingByGroupName(string groupName) protected static Group GetCachedByGroupName(string groupName)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = groupName.ToString(); string key = groupName.ToString();
if (_AllByGroupName.ContainsKey(key)) return _AllByGroupName[key][0]; if (_CacheByGroupName.ContainsKey(key)) return _CacheByGroupName[key][0];
return null; return null;
} }
#endregion #endregion
@ -462,28 +470,41 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _GroupUnique = 0; private static int _GroupUnique = 0;
private int _MyGroupUnique; protected static int GroupUnique
{ get { return ++_GroupUnique; } }
private int _MyGroupUnique = GroupUnique;
public int MyGroupUnique public int MyGroupUnique
{ { get { return _MyGroupUnique; } }
get { return _MyGroupUnique; }
}
protected Group() protected Group()
{/* require use of factory methods */ {/* require use of factory methods */
_MyGroupUnique = ++_GroupUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(GID.ToString())) return; }
List<Group> listGroup = _AllByPrimaryKey[GID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
{
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(GID.ToString()))
{
List<Group> listGroup = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items
while (listGroup.Contains(this)) listGroup.Remove(this); // Remove the item from the list
if (listGroup.Count == 0) //If there are no items left in the list
_CacheByPrimaryKey.Remove(GID.ToString()); // remove the list
}
string myKey;
myKey = null;
foreach (string key in _CacheByGroupName.Keys)
if (_CacheByGroupName[key].Contains(this))
myKey = key;
if (myKey != null)
{
List<Group> listGroup = _CacheByGroupName[myKey]; // Get the list of items
listGroup.Remove(this); // Remove the item from the list listGroup.Remove(this); // Remove the item from the list
if (listGroup.Count == 0) //If there are no items left in the list if (listGroup.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(GID.ToString()); // remove the list _CacheByGroupName.Remove(myKey); // remove the list
listGroup = _AllByGroupName[GID.ToString()]; // Get the list of items }
listGroup.Remove(this); // Remove the item from the list
if (listGroup.Count == 0) //If there are no items left in the list
_AllByGroupName.Remove(GID.ToString()); // remove the list
} }
public static Group New() public static Group New()
{ {
@ -518,7 +539,11 @@ namespace VEPROMS.CSLA.Library
{ {
Group tmp = Group.New(groupName, groupType, config, dts, usrID); Group tmp = Group.New(groupName, groupType, config, dts, usrID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Group tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -542,7 +567,11 @@ namespace VEPROMS.CSLA.Library
{ {
Group tmp = Group.New(groupName, groupType, config); Group tmp = Group.New(groupName, groupType, config);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Group tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -560,13 +589,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Group"); throw new System.Security.SecurityException("User not authorized to view a Group");
try try
{ {
Group tmp = GetExistingByPrimaryKey(gid); Group tmp = GetCachedByPrimaryKey(gid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Group>(new PKCriteria(gid)); tmp = DataPortal.Fetch<Group>(new PKCriteria(gid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Group
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -574,19 +607,23 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on Group.Get", ex); throw new DbCslaException("Error on Group.Get", ex);
} }
} }
private static Group GetByGroupName(string groupName) public static Group GetByGroupName(string groupName)
{ {
if (!CanGetObject()) if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Group"); throw new System.Security.SecurityException("User not authorized to view a Group");
try try
{ {
Group tmp = GetExistingByGroupName(groupName); Group tmp = GetCachedByGroupName(groupName);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Group>(new GroupNameCriteria(groupName)); tmp = DataPortal.Fetch<Group>(new GroupNameCriteria(groupName));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Group
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -628,7 +665,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Group group = base.Save(); Group group = base.Save();
_AllList.Add(group);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(group);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return group; return group;
} }

View File

@ -285,6 +285,16 @@ namespace VEPROMS.CSLA.Library
return _Folder_FormatID; return _Folder_FormatID;
} }
} }
private double? _Folder_ManualOrder;
public double? Folder_ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Folder_ManualOrder", true);
return _Folder_ManualOrder;
}
}
private string _Folder_Config = string.Empty; private string _Folder_Config = string.Empty;
public string Folder_Config public string Folder_Config
{ {
@ -587,6 +597,7 @@ namespace VEPROMS.CSLA.Library
_Folder_Title = dr.GetString("Folder_Title"); _Folder_Title = dr.GetString("Folder_Title");
_Folder_ShortName = dr.GetString("Folder_ShortName"); _Folder_ShortName = dr.GetString("Folder_ShortName");
_Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID");
_Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder");
_Folder_Config = dr.GetString("Folder_Config"); _Folder_Config = dr.GetString("Folder_Config");
_Folder_DTS = dr.GetDateTime("Folder_DTS"); _Folder_DTS = dr.GetDateTime("Folder_DTS");
_Folder_UsrID = dr.GetString("Folder_UsrID"); _Folder_UsrID = dr.GetString("Folder_UsrID");

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<GroupInfo> _AllList = new List<GroupInfo>(); private static List<GroupInfo> _CacheList = new List<GroupInfo>();
private static Dictionary<string, List<GroupInfo>> _AllByPrimaryKey = new Dictionary<string, List<GroupInfo>>(); protected static void AddToCache(GroupInfo groupInfo)
{
if (!_CacheList.Contains(groupInfo)) _CacheList.Add(groupInfo); // In AddToCache
}
protected static void RemoveFromCache(GroupInfo groupInfo)
{
while (_CacheList.Contains(groupInfo)) _CacheList.Remove(groupInfo); // In RemoveFromCache
}
private static Dictionary<string, List<GroupInfo>> _CacheByPrimaryKey = new Dictionary<string, List<GroupInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<GroupInfo> remove = new List<GroupInfo>(); List<GroupInfo> remove = new List<GroupInfo>();
foreach (GroupInfo tmp in _AllList) foreach (GroupInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.GID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.GID.ToString()))
{ {
_AllByPrimaryKey[tmp.GID.ToString()] = new List<GroupInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.GID.ToString()] = new List<GroupInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (GroupInfo tmp in remove) foreach (GroupInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(GroupInfoList lst) internal static void AddList(GroupInfoList lst)
{ {
foreach (GroupInfo item in lst) _AllList.Add(item); foreach (GroupInfo item in lst) AddToCache(item);
} }
public static GroupInfo GetExistingByPrimaryKey(int gid) protected static GroupInfo GetCachedByPrimaryKey(int gid)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = gid.ToString(); string key = gid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -171,11 +179,11 @@ namespace VEPROMS.CSLA.Library
return _GroupAssignments; return _GroupAssignments;
} }
} }
internal void RefreshGroupAssignments() public void RefreshGroupAssignments()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_GID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_GID.ToString()))
foreach (GroupInfo tmp in _AllByPrimaryKey[_GID.ToString()]) foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()])
tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried
} }
private int _GroupMembershipCount = 0; private int _GroupMembershipCount = 0;
@ -206,11 +214,11 @@ namespace VEPROMS.CSLA.Library
return _GroupMemberships; return _GroupMemberships;
} }
} }
internal void RefreshGroupMemberships() public void RefreshGroupMemberships()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_GID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_GID.ToString()))
foreach (GroupInfo tmp in _AllByPrimaryKey[_GID.ToString()]) foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()])
tmp._GroupMembershipCount = -1; // This will cause the data to be requeried tmp._GroupMembershipCount = -1; // This will cause the data to be requeried
} }
// TODO: Replace base GroupInfo.ToString function as necessary // TODO: Replace base GroupInfo.ToString function as necessary
@ -234,24 +242,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _GroupInfoUnique = 0; private static int _GroupInfoUnique = 0;
private int _MyGroupInfoUnique; private static int GroupInfoUnique
{ get { return ++_GroupInfoUnique; } }
private int _MyGroupInfoUnique = GroupInfoUnique;
public int MyGroupInfoUnique public int MyGroupInfoUnique
{ { get { return _MyGroupInfoUnique; } }
get { return _MyGroupInfoUnique; } protected GroupInfo()
}
private GroupInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyGroupInfoUnique = ++_GroupInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(GID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(GID.ToString())) return;
List<GroupInfo> listGroupInfo = _AllByPrimaryKey[GID.ToString()]; // Get the list of items List<GroupInfo> listGroupInfo = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items
listGroupInfo.Remove(this); // Remove the item from the list while (listGroupInfo.Contains(this)) listGroupInfo.Remove(this); // Remove the item from the list
if (listGroupInfo.Count == 0) // If there are no items left in the list if (listGroupInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(GID.ToString()); // remove the list _CacheByPrimaryKey.Remove(GID.ToString()); // remove the list
} }
public virtual Group Get() public virtual Group Get()
{ {
@ -261,11 +268,11 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.GID.ToString(); string key = tmp.GID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (GroupInfo tmpInfo in _AllByPrimaryKey[key]) foreach (GroupInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Group tmp) protected virtual void RefreshFields(Group tmp)
{ {
_GroupName = tmp.GroupName; _GroupName = tmp.GroupName;
_GroupType = tmp.GroupType; _GroupType = tmp.GroupType;
@ -281,13 +288,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Group"); // throw new System.Security.SecurityException("User not authorized to view a Group");
try try
{ {
GroupInfo tmp = GetExistingByPrimaryKey(gid); GroupInfo tmp = GetCachedByPrimaryKey(gid);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<GroupInfo>(new PKCriteria(gid)); tmp = DataPortal.Fetch<GroupInfo>(new PKCriteria(gid));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up GroupInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -299,7 +310,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal GroupInfo(SafeDataReader dr) internal GroupInfo(SafeDataReader dr)
{ {
_MyGroupInfoUnique = ++_GroupInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode());
try try
{ {

View File

@ -124,28 +124,36 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
protected static List<Item> _AllList = new List<Item>(); private static List<Item> _CacheList = new List<Item>();
private static Dictionary<string, List<Item>> _AllByPrimaryKey = new Dictionary<string, List<Item>>(); protected static void AddToCache(Item item)
{
if (!_CacheList.Contains(item)) _CacheList.Add(item); // In AddToCache
}
protected static void RemoveFromCache(Item item)
{
while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache
}
private static Dictionary<string, List<Item>> _CacheByPrimaryKey = new Dictionary<string, List<Item>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<Item> remove = new List<Item>(); List<Item> remove = new List<Item>();
foreach (Item tmp in _AllList) foreach (Item tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ItemID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ItemID.ToString()))
{ {
_AllByPrimaryKey[tmp.ItemID.ToString()] = new List<Item>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ItemID.ToString()] = new List<Item>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (Item tmp in remove) foreach (Item tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
public static Item GetExistingByPrimaryKey(int itemID) protected static Item GetCachedByPrimaryKey(int itemID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = itemID.ToString(); string key = itemID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -196,7 +204,7 @@ namespace VEPROMS.CSLA.Library
set set
{ {
CanWriteProperty("MyPrevious", true); CanWriteProperty("MyPrevious", true);
if (_MyPrevious != value) if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID))
{ {
_MyPrevious = value; _MyPrevious = value;
_PreviousID = (value == null ? null : (int?)value.ItemID); _PreviousID = (value == null ? null : (int?)value.ItemID);
@ -635,24 +643,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel public int CurrentEditLevel
{ get { return EditLevel; } } { get { return EditLevel; } }
private static int _ItemUnique = 0; private static int _ItemUnique = 0;
private int _MyItemUnique; protected static int ItemUnique
{ get { return ++_ItemUnique; } }
private int _MyItemUnique = ItemUnique;
public int MyItemUnique public int MyItemUnique
{ { get { return _MyItemUnique; } }
get { return _MyItemUnique; }
}
protected Item() protected Item()
{/* require use of factory methods */ {/* require use of factory methods */
_MyItemUnique = ++_ItemUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromDictionaries();
if (!_AllByPrimaryKey.ContainsKey(ItemID.ToString())) return; }
List<Item> listItem = _AllByPrimaryKey[ItemID.ToString()]; // Get the list of items private void RemoveFromDictionaries()
listItem.Remove(this); // Remove the item from the list {
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString()))
{
List<Item> listItem = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items
while (listItem.Contains(this)) listItem.Remove(this); // Remove the item from the list
if (listItem.Count == 0) //If there are no items left in the list if (listItem.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(ItemID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list
}
} }
public static Item New() public static Item New()
{ {
@ -686,7 +699,11 @@ namespace VEPROMS.CSLA.Library
{ {
Item tmp = Item.New(myPrevious, myContent, dts, userID); Item tmp = Item.New(myPrevious, myContent, dts, userID);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Item tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -709,7 +726,11 @@ namespace VEPROMS.CSLA.Library
{ {
Item tmp = Item.New(myPrevious, myContent); Item tmp = Item.New(myPrevious, myContent);
if (tmp.IsSavable) if (tmp.IsSavable)
tmp = tmp.Save(); {
Item tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else else
{ {
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@ -727,13 +748,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a Item"); throw new System.Security.SecurityException("User not authorized to view a Item");
try try
{ {
Item tmp = GetExistingByPrimaryKey(itemID); Item tmp = GetCachedByPrimaryKey(itemID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<Item>(new PKCriteria(itemID)); tmp = DataPortal.Fetch<Item>(new PKCriteria(itemID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Item
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -785,7 +810,8 @@ namespace VEPROMS.CSLA.Library
{ {
BuildRefreshList(); BuildRefreshList();
Item item = base.Save(); Item item = base.Save();
_AllList.Add(item);//Refresh the item in AllList RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(item);//Refresh the item in AllList
ProcessRefreshList(); ProcessRefreshList();
return item; return item;
} }

View File

@ -181,7 +181,7 @@ namespace VEPROMS.CSLA.Library
set set
{ {
CanWriteProperty("MyFormat", true); CanWriteProperty("MyFormat", true);
if (_MyFormat != value) if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID))
{ {
_MyFormat = value; _MyFormat = value;
_FormatID = (value == null ? null : (int?)value.FormatID); _FormatID = (value == null ? null : (int?)value.FormatID);
@ -312,6 +312,16 @@ namespace VEPROMS.CSLA.Library
return _Folder_FormatID; return _Folder_FormatID;
} }
} }
private double? _Folder_ManualOrder;
public double? Folder_ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Folder_ManualOrder", true);
return _Folder_ManualOrder;
}
}
private string _Folder_Config = string.Empty; private string _Folder_Config = string.Empty;
public string Folder_Config public string Folder_Config
{ {
@ -551,6 +561,7 @@ namespace VEPROMS.CSLA.Library
_Folder_Title = dr.GetString("Folder_Title"); _Folder_Title = dr.GetString("Folder_Title");
_Folder_ShortName = dr.GetString("Folder_ShortName"); _Folder_ShortName = dr.GetString("Folder_ShortName");
_Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID");
_Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder");
_Folder_Config = dr.GetString("Folder_Config"); _Folder_Config = dr.GetString("Folder_Config");
_Folder_DTS = dr.GetDateTime("Folder_DTS"); _Folder_DTS = dr.GetDateTime("Folder_DTS");
_Folder_UsrID = dr.GetString("Folder_UsrID"); _Folder_UsrID = dr.GetString("Folder_UsrID");

View File

@ -36,32 +36,40 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
protected static List<ItemInfo> _AllList = new List<ItemInfo>(); private static List<ItemInfo> _CacheList = new List<ItemInfo>();
private static Dictionary<string, List<ItemInfo>> _AllByPrimaryKey = new Dictionary<string, List<ItemInfo>>(); protected static void AddToCache(ItemInfo itemInfo)
{
if (!_CacheList.Contains(itemInfo)) _CacheList.Add(itemInfo); // In AddToCache
}
protected static void RemoveFromCache(ItemInfo itemInfo)
{
while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache
}
private static Dictionary<string, List<ItemInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ItemInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
List<ItemInfo> remove = new List<ItemInfo>(); List<ItemInfo> remove = new List<ItemInfo>();
foreach (ItemInfo tmp in _AllList) foreach (ItemInfo tmp in _CacheList)
{ {
if (!_AllByPrimaryKey.ContainsKey(tmp.ItemID.ToString())) if (!_CacheByPrimaryKey.ContainsKey(tmp.ItemID.ToString()))
{ {
_AllByPrimaryKey[tmp.ItemID.ToString()] = new List<ItemInfo>(); // Add new list for PrimaryKey _CacheByPrimaryKey[tmp.ItemID.ToString()] = new List<ItemInfo>(); // Add new list for PrimaryKey
} }
_AllByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list _CacheByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp); remove.Add(tmp);
} }
foreach (ItemInfo tmp in remove) foreach (ItemInfo tmp in remove)
_AllList.Remove(tmp); RemoveFromCache(tmp);
} }
internal static void AddList(ItemInfoList lst) internal static void AddList(ItemInfoList lst)
{ {
foreach (ItemInfo item in lst) _AllList.Add(item); foreach (ItemInfo item in lst) AddToCache(item);
} }
public static ItemInfo GetExistingByPrimaryKey(int itemID) protected static ItemInfo GetCachedByPrimaryKey(int itemID)
{ {
ConvertListToDictionary(); ConvertListToDictionary();
string key = itemID.ToString(); string key = itemID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0]; if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null; return null;
} }
#endregion #endregion
@ -185,11 +193,11 @@ namespace VEPROMS.CSLA.Library
return _ItemAnnotations; return _ItemAnnotations;
} }
} }
internal void RefreshItemAnnotations() public void RefreshItemAnnotations()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried
} }
private int _ItemDocVersionCount = 0; private int _ItemDocVersionCount = 0;
@ -220,11 +228,11 @@ namespace VEPROMS.CSLA.Library
return _ItemDocVersions; return _ItemDocVersions;
} }
} }
internal void RefreshItemDocVersions() public void RefreshItemDocVersions()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried
} }
private int _NextItemCount = 0; private int _NextItemCount = 0;
@ -255,11 +263,11 @@ namespace VEPROMS.CSLA.Library
return _NextItems; return _NextItems;
} }
} }
internal void RefreshNextItems() public void RefreshNextItems()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._NextItemCount = -1; // This will cause the data to be requeried tmp._NextItemCount = -1; // This will cause the data to be requeried
} }
private int _ItemPartCount = 0; private int _ItemPartCount = 0;
@ -290,11 +298,11 @@ namespace VEPROMS.CSLA.Library
return _ItemParts; return _ItemParts;
} }
} }
internal void RefreshItemParts() public void RefreshItemParts()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._ItemPartCount = -1; // This will cause the data to be requeried tmp._ItemPartCount = -1; // This will cause the data to be requeried
} }
private int _ItemTransition_RangeIDCount = 0; private int _ItemTransition_RangeIDCount = 0;
@ -325,11 +333,11 @@ namespace VEPROMS.CSLA.Library
return _ItemTransitions_RangeID; return _ItemTransitions_RangeID;
} }
} }
internal void RefreshItemTransitions_RangeID() public void RefreshItemTransitions_RangeID()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried
} }
private int _ItemTransition_ToIDCount = 0; private int _ItemTransition_ToIDCount = 0;
@ -360,11 +368,11 @@ namespace VEPROMS.CSLA.Library
return _ItemTransitions_ToID; return _ItemTransitions_ToID;
} }
} }
internal void RefreshItemTransitions_ToID() public void RefreshItemTransitions_ToID()
{ {
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString())) if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried
} }
// TODO: Replace base ItemInfo.ToString function as necessary // TODO: Replace base ItemInfo.ToString function as necessary
@ -388,24 +396,23 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ItemInfoUnique = 0; private static int _ItemInfoUnique = 0;
private int _MyItemInfoUnique; private static int ItemInfoUnique
{ get { return ++_ItemInfoUnique; } }
private int _MyItemInfoUnique = ItemInfoUnique;
public int MyItemInfoUnique public int MyItemInfoUnique
{ { get { return _MyItemInfoUnique; } }
get { return _MyItemInfoUnique; } protected ItemInfo()
}
private ItemInfo()
{/* require use of factory methods */ {/* require use of factory methods */
_MyItemInfoUnique = ++_ItemInfoUnique; AddToCache(this);
_AllList.Add(this);
} }
public void Dispose() public void Dispose()
{ {
_AllList.Remove(this); RemoveFromCache(this);
if (!_AllByPrimaryKey.ContainsKey(ItemID.ToString())) return; if (!_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) return;
List<ItemInfo> listItemInfo = _AllByPrimaryKey[ItemID.ToString()]; // Get the list of items List<ItemInfo> listItemInfo = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items
listItemInfo.Remove(this); // Remove the item from the list while (listItemInfo.Contains(this)) listItemInfo.Remove(this); // Remove the item from the list
if (listItemInfo.Count == 0) // If there are no items left in the list if (listItemInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ItemID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list
} }
public virtual Item Get() public virtual Item Get()
{ {
@ -415,22 +422,22 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ItemID.ToString(); string key = tmp.ItemID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ItemInfo tmpInfo in _AllByPrimaryKey[key]) foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(Item tmp) protected virtual void RefreshFields(Item tmp)
{ {
if (_PreviousID != tmp.PreviousID) if (_PreviousID != tmp.PreviousID)
{ {
MyPrevious.RefreshNextItems(); // Update List for old value if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value _PreviousID = tmp.PreviousID; // Update the value
} }
_MyPrevious = null; // Reset list so that the next line gets a new list _MyPrevious = null; // Reset list so that the next line gets a new list
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value
if (_ContentID != tmp.ContentID) if (_ContentID != tmp.ContentID)
{ {
MyContent.RefreshContentItems(); // Update List for old value if (MyContent != null) MyContent.RefreshContentItems(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value _ContentID = tmp.ContentID; // Update the value
} }
_MyContent = null; // Reset list so that the next line gets a new list _MyContent = null; // Reset list so that the next line gets a new list
@ -446,15 +453,15 @@ namespace VEPROMS.CSLA.Library
{ {
string key = tmp.ItemID.ToString(); string key = tmp.ItemID.ToString();
ConvertListToDictionary(); ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key)) if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ItemInfo tmpInfo in _AllByPrimaryKey[key]) foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp); tmpInfo.RefreshFields(tmp);
} }
private void RefreshFields(ContentItem tmp) protected virtual void RefreshFields(ContentItem tmp)
{ {
if (_PreviousID != tmp.PreviousID) if (_PreviousID != tmp.PreviousID)
{ {
MyPrevious.RefreshNextItems(); // Update List for old value if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value _PreviousID = tmp.PreviousID; // Update the value
} }
_MyPrevious = null; // Reset list so that the next line gets a new list _MyPrevious = null; // Reset list so that the next line gets a new list
@ -472,13 +479,17 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Item"); // throw new System.Security.SecurityException("User not authorized to view a Item");
try try
{ {
ItemInfo tmp = GetExistingByPrimaryKey(itemID); ItemInfo tmp = GetCachedByPrimaryKey(itemID);
if (tmp == null) if (tmp == null)
{ {
tmp = DataPortal.Fetch<ItemInfo>(new PKCriteria(itemID)); tmp = DataPortal.Fetch<ItemInfo>(new PKCriteria(itemID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp); AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up ItemInfo
tmp = null;
} }
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception ex)
@ -490,7 +501,6 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
internal ItemInfo(SafeDataReader dr) internal ItemInfo(SafeDataReader dr)
{ {
_MyItemInfoUnique = ++_ItemInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode());
try try
{ {