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<ZContentInfo> _AllList = new List<ZContentInfo>();
private static Dictionary<string, ZContentInfo> _AllByPrimaryKey = new Dictionary<string, ZContentInfo>();
private static Dictionary<string, List<ZContentInfo>> _AllByPrimaryKey = new Dictionary<string, List<ZContentInfo>>();
private static void ConvertListToDictionary()
{
List<ZContentInfo> remove = new List<ZContentInfo>();
foreach (ZContentInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.ContentID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
{
_AllByPrimaryKey[tmp.ContentID.ToString()] = new List<ZContentInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (ZContentInfo tmp in remove)
@@ -53,7 +57,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = contentID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
return null;
}
#endregion
@@ -81,7 +85,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;
}
@@ -93,7 +97,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;
}
@@ -104,7 +108,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("OldStepSequence",true);
CanReadProperty("OldStepSequence", true);
return _OldStepSequence;
}
}
@@ -128,14 +132,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _ZContentInfoUnique = 0;
private int _MyZContentInfoUnique;
public int MyZContentInfoUnique
{
get { return _MyZContentInfoUnique; }
}
private ZContentInfo()
{/* require use of factory methods */
_MyZContentInfoUnique = ++_ZContentInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(ContentID.ToString());
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString())) return;
List<ZContentInfo> listZContentInfo = _AllByPrimaryKey[ContentID.ToString()]; // Get the list of items
listZContentInfo.Remove(this); // Remove the item from the list
if (listZContentInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
public virtual ZContent Get()
{
@@ -143,9 +158,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(ZContent tmp)
{
ZContentInfo tmpInfo = GetExistingByPrimaryKey(tmp.ContentID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.ContentID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (ZContentInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ZContent tmp)
{
@@ -164,7 +181,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<ZContentInfo>(new PKCriteria(contentID));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
@@ -181,14 +198,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal ZContentInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode());
_MyZContentInfoUnique = ++_ZContentInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZContentInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.Constructor", ex);
throw new DbCslaException("ZContentInfo.Constructor", ex);
}
}
@@ -205,7 +223,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZContentInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.ReadData", GetHashCode());
try
{
_ContentID = dr.GetInt32("ContentID");
@@ -213,14 +231,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZContentInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZContentInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZContentInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -248,7 +266,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZContentInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZContentInfo.DataPortal_Fetch", ex);
}
@@ -258,7 +276,7 @@ namespace VEPROMS.CSLA.Library
#region extension
ZContentInfoExtension _ZContentInfoExtension = new ZContentInfoExtension();
[Serializable()]
partial class ZContentInfoExtension : extensionBase {}
partial class ZContentInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{