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<PartInfo> _AllList = new List<PartInfo>();
private static Dictionary<string, PartInfo> _AllByPrimaryKey = new Dictionary<string, PartInfo>();
private static Dictionary<string, List<PartInfo>> _AllByPrimaryKey = new Dictionary<string, List<PartInfo>>();
private static void ConvertListToDictionary()
{
List<PartInfo> remove = new List<PartInfo>();
foreach (PartInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()))
{
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List<PartInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (PartInfo tmp in remove)
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = contentID.ToString() + "_" + fromType.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("ContentID",true);
CanReadProperty("ContentID", true);
if (_MyContent != null) _ContentID = _MyContent.ContentID;
return _ContentID;
}
@@ -97,7 +101,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;
}
@@ -109,7 +113,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("FromType",true);
CanReadProperty("FromType", true);
return _FromType;
}
}
@@ -119,7 +123,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemID",true);
CanReadProperty("ItemID", true);
if (_MyItem != null) _ItemID = _MyItem.ItemID;
return _ItemID;
}
@@ -130,7 +134,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyItem",true);
CanReadProperty("MyItem", true);
if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID);
return _MyItem;
}
@@ -141,7 +145,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -151,7 +155,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UserID",true);
CanReadProperty("UserID", true);
return _UserID;
}
}
@@ -171,18 +175,29 @@ namespace VEPROMS.CSLA.Library
/// <returns>A Unique ID for the current PartInfo</returns>
protected override object GetIdValue()
{
return (_ContentID.ToString()+"."+_FromType.ToString()).GetHashCode();
return (_ContentID.ToString() + "." + _FromType.ToString()).GetHashCode();
}
#endregion
#region Factory Methods
private static int _PartInfoUnique = 0;
private int _MyPartInfoUnique;
public int MyPartInfoUnique
{
get { return _MyPartInfoUnique; }
}
private PartInfo()
{/* require use of factory methods */
_MyPartInfoUnique = ++_PartInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString());
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return;
List<PartInfo> listPartInfo = _AllByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items
listPartInfo.Remove(this); // Remove the item from the list
if (listPartInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list
}
public virtual Part Get()
{
@@ -190,9 +205,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Part tmp)
{
PartInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID, tmp.FromType);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (PartInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Part tmp)
{
@@ -200,9 +217,9 @@ namespace VEPROMS.CSLA.Library
{
MyItem.RefreshItemParts(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
_MyItem = null; // Reset list so that the next line gets a new list
MyItem.RefreshItemParts(); // Update List for new value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemParts(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_PartInfoExtension.Refresh(this);
@@ -212,9 +229,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Content myContent, ContentPart tmp)
{
PartInfo tmpInfo = GetExistingByPrimaryKey(myContent.ContentID, tmp.FromType);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (PartInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ContentPart tmp)
{
@@ -222,9 +241,9 @@ namespace VEPROMS.CSLA.Library
{
MyItem.RefreshItemParts(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
_MyItem = null; // Reset list so that the next line gets a new list
MyItem.RefreshItemParts(); // Update List for new value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemParts(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_PartInfoExtension.Refresh(this);
@@ -234,9 +253,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(ItemPart tmp)
{
PartInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID, tmp.FromType);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (PartInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ItemPart tmp)
{
@@ -257,7 +278,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<PartInfo>(new PKCriteria(contentID, fromType));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -271,14 +292,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal PartInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode());
_MyPartInfoUnique = ++_PartInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("PartInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.Constructor", ex);
throw new DbCslaException("PartInfo.Constructor", ex);
}
}
@@ -299,7 +321,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PartInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.ReadData", GetHashCode());
try
{
_ContentID = dr.GetInt32("ContentID");
@@ -310,14 +332,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("PartInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("PartInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] PartInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -346,7 +368,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("PartInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("PartInfo.DataPortal_Fetch", ex);
}
@@ -356,7 +378,7 @@ namespace VEPROMS.CSLA.Library
#region extension
PartInfoExtension _PartInfoExtension = new PartInfoExtension();
[Serializable()]
partial class PartInfoExtension : extensionBase {}
partial class PartInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{