This commit is contained in:
Jsj
2008-05-16 18:07:47 +00:00
parent 9d0b3cd543
commit cda0291dbd
116 changed files with 4257 additions and 3382 deletions

View File

@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<ItemInfo> _AllList = new List<ItemInfo>();
private static Dictionary<string, ItemInfo> _AllByPrimaryKey = new Dictionary<string, ItemInfo>();
private static Dictionary<string, List<ItemInfo>> _AllByPrimaryKey = new Dictionary<string, List<ItemInfo>>();
private static void ConvertListToDictionary()
{
List<ItemInfo> remove = new List<ItemInfo>();
foreach (ItemInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.ItemID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.ItemID.ToString()))
{
_AllByPrimaryKey[tmp.ItemID.ToString()] = new List<ItemInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (ItemInfo tmp in remove)
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = itemID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
return null;
}
#endregion
@@ -85,7 +89,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemID",true);
CanReadProperty("ItemID", true);
return _ItemID;
}
}
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("PreviousID",true);
CanReadProperty("PreviousID", true);
if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID;
return _PreviousID;
}
@@ -106,7 +110,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyPrevious",true);
CanReadProperty("MyPrevious", true);
if (_MyPrevious == null && _PreviousID != null) _MyPrevious = ItemInfo.Get((int)_PreviousID);
return _MyPrevious;
}
@@ -117,7 +121,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ContentID",true);
CanReadProperty("ContentID", true);
if (_MyContent != null) _ContentID = _MyContent.ContentID;
return _ContentID;
}
@@ -128,7 +132,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyContent",true);
CanReadProperty("MyContent", true);
if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID);
return _MyContent;
}
@@ -139,7 +143,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -149,7 +153,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UserID",true);
CanReadProperty("UserID", true);
return _UserID;
}
}
@@ -162,7 +166,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemAnnotationCount",true);
CanReadProperty("ItemAnnotationCount", true);
return _ItemAnnotationCount;
}
}
@@ -173,7 +177,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemAnnotations",true);
CanReadProperty("ItemAnnotations", true);
if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null))
_ItemAnnotations = AnnotationInfoList.GetByItemID(_ItemID);
if (_ItemAnnotationCount < 0)
@@ -183,7 +187,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshItemAnnotations()
{
_ItemAnnotationCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()])
tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried
}
private int _ItemDocVersionCount = 0;
/// <summary>
@@ -194,7 +201,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemDocVersionCount",true);
CanReadProperty("ItemDocVersionCount", true);
return _ItemDocVersionCount;
}
}
@@ -205,7 +212,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemDocVersions",true);
CanReadProperty("ItemDocVersions", true);
if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null))
_ItemDocVersions = DocVersionInfoList.GetByItemID(_ItemID);
if (_ItemDocVersionCount < 0)
@@ -215,7 +222,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshItemDocVersions()
{
_ItemDocVersionCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()])
tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried
}
private int _NextItemCount = 0;
/// <summary>
@@ -226,7 +236,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("NextItemCount",true);
CanReadProperty("NextItemCount", true);
return _NextItemCount;
}
}
@@ -237,7 +247,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("NextItems",true);
CanReadProperty("NextItems", true);
if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null))
_NextItems = ItemInfoList.GetNext(_ItemID);
if (_NextItemCount < 0)
@@ -247,7 +257,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshNextItems()
{
_NextItemCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()])
tmp._NextItemCount = -1; // This will cause the data to be requeried
}
private int _ItemPartCount = 0;
/// <summary>
@@ -258,7 +271,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemPartCount",true);
CanReadProperty("ItemPartCount", true);
return _ItemPartCount;
}
}
@@ -269,7 +282,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemParts",true);
CanReadProperty("ItemParts", true);
if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null))
_ItemParts = PartInfoList.GetByItemID(_ItemID);
if (_ItemPartCount < 0)
@@ -279,7 +292,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshItemParts()
{
_ItemPartCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()])
tmp._ItemPartCount = -1; // This will cause the data to be requeried
}
private int _ItemTransition_RangeIDCount = 0;
/// <summary>
@@ -290,7 +306,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemTransition_RangeIDCount",true);
CanReadProperty("ItemTransition_RangeIDCount", true);
return _ItemTransition_RangeIDCount;
}
}
@@ -301,7 +317,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemTransitions_RangeID",true);
CanReadProperty("ItemTransitions_RangeID", true);
if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null))
_ItemTransitions_RangeID = TransitionInfoList.GetByRangeID(_ItemID);
if (_ItemTransition_RangeIDCount < 0)
@@ -311,7 +327,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshItemTransitions_RangeID()
{
_ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()])
tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried
}
private int _ItemTransition_ToIDCount = 0;
/// <summary>
@@ -322,7 +341,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemTransition_ToIDCount",true);
CanReadProperty("ItemTransition_ToIDCount", true);
return _ItemTransition_ToIDCount;
}
}
@@ -333,7 +352,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemTransitions_ToID",true);
CanReadProperty("ItemTransitions_ToID", true);
if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null))
_ItemTransitions_ToID = TransitionInfoList.GetByToID(_ItemID);
if (_ItemTransition_ToIDCount < 0)
@@ -343,7 +362,10 @@ namespace VEPROMS.CSLA.Library
}
internal void RefreshItemTransitions_ToID()
{
_ItemTransition_ToIDCount = -1; // This will cause the data to be requeried
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(_ItemID.ToString()))
foreach (ItemInfo tmp in _AllByPrimaryKey[_ItemID.ToString()])
tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried
}
// TODO: Replace base ItemInfo.ToString function as necessary
/// <summary>
@@ -365,14 +387,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _ItemInfoUnique = 0;
private int _MyItemInfoUnique;
public int MyItemInfoUnique
{
get { return _MyItemInfoUnique; }
}
private ItemInfo()
{/* require use of factory methods */
_MyItemInfoUnique = ++_ItemInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(ItemID.ToString());
if (!_AllByPrimaryKey.ContainsKey(ItemID.ToString())) return;
List<ItemInfo> listItemInfo = _AllByPrimaryKey[ItemID.ToString()]; // Get the list of items
listItemInfo.Remove(this); // Remove the item from the list
if (listItemInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ItemID.ToString()); // remove the list
}
public virtual Item Get()
{
@@ -380,9 +413,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Item tmp)
{
ItemInfo tmpInfo = GetExistingByPrimaryKey(tmp.ItemID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.ItemID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (ItemInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Item tmp)
{
@@ -390,16 +425,16 @@ namespace VEPROMS.CSLA.Library
{
MyPrevious.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value
_MyPrevious = null; // Reset list so that the next line gets a new list
MyPrevious.RefreshNextItems(); // Update List for new value
}
_MyPrevious = null; // Reset list so that the next line gets a new list
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value
if (_ContentID != tmp.ContentID)
{
MyContent.RefreshContentItems(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value
_MyContent = null; // Reset list so that the next line gets a new list
MyContent.RefreshContentItems(); // Update List for new value
}
_MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentItems(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_ItemInfoExtension.Refresh(this);
@@ -409,9 +444,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(ContentItem tmp)
{
ItemInfo tmpInfo = GetExistingByPrimaryKey(tmp.ItemID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.ItemID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (ItemInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ContentItem tmp)
{
@@ -419,9 +456,9 @@ namespace VEPROMS.CSLA.Library
{
MyPrevious.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value
_MyPrevious = null; // Reset list so that the next line gets a new list
MyPrevious.RefreshNextItems(); // Update List for new value
}
_MyPrevious = null; // Reset list so that the next line gets a new list
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_ItemInfoExtension.Refresh(this);
@@ -439,7 +476,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<ItemInfo>(new PKCriteria(itemID));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -453,14 +490,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal ItemInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode());
_MyItemInfoUnique = ++_ItemInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.Constructor", ex);
throw new DbCslaException("ItemInfo.Constructor", ex);
}
}
@@ -477,7 +515,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode());
try
{
_ItemID = dr.GetInt32("ItemID");
@@ -494,14 +532,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ItemInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -529,7 +567,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ItemInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex);
}
@@ -539,7 +577,7 @@ namespace VEPROMS.CSLA.Library
#region extension
ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension();
[Serializable()]
partial class ItemInfoExtension : extensionBase {}
partial class ItemInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{