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

@@ -47,20 +47,24 @@ namespace VEPROMS.CSLA.Library
foreach (Part tmp in _RefreshParts)
{
PartInfo.Refresh(tmp);
if(tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent);
if(tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem);
if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent);
if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem);
}
}
#endregion
#region Collection
protected static List<Part> _AllList = new List<Part>();
private static Dictionary<string, Part> _AllByPrimaryKey = new Dictionary<string, Part>();
private static Dictionary<string, List<Part>> _AllByPrimaryKey = new Dictionary<string, List<Part>>();
private static void ConvertListToDictionary()
{
List<Part> remove = new List<Part>();
foreach (Part 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<Part>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (Part tmp in remove)
@@ -70,7 +74,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
@@ -87,7 +91,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;
}
@@ -99,7 +103,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 = Content.Get(_ContentID);
return _MyContent;
}
@@ -111,7 +115,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("FromType",true);
CanReadProperty("FromType", true);
return _FromType;
}
}
@@ -121,7 +125,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;
}
@@ -132,14 +136,14 @@ 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 = Item.Get(_ItemID);
return _MyItem;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyItem",true);
CanWriteProperty("MyItem", true);
if (_MyItem != value)
{
_MyItem = value;
@@ -153,13 +157,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DTS",true);
CanWriteProperty("DTS", true);
if (_DTS != value)
{
_DTS = value;
@@ -173,13 +177,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UserID",true);
CanReadProperty("UserID", true);
return _UserID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("UserID",true);
CanWriteProperty("UserID", true);
if (value == null) value = string.Empty;
if (_UserID != value)
{
@@ -191,11 +195,11 @@ namespace VEPROMS.CSLA.Library
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty || (_MyContent == null? false : _MyContent.IsDirty) || (_MyItem == null? false : _MyItem.IsDirty); }
get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null? true : _MyContent.IsValid) && (_MyItem == null? true : _MyItem.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); }
}
// TODO: Replace base Part.ToString function as necessary
/// <summary>
@@ -213,27 +217,28 @@ namespace VEPROMS.CSLA.Library
/// <returns>A Unique ID for the current Part</returns>
protected override object GetIdValue()
{
return (_ContentID.ToString()+"."+_FromType.ToString()).GetHashCode();
return (_ContentID.ToString() + "." + _FromType.ToString()).GetHashCode();
}
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules=false;
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
get {
if(_CheckingBrokenRules)return null;
get
{
if (_CheckingBrokenRules) return null;
if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
try
{
_CheckingBrokenRules=true;
_CheckingBrokenRules = true;
IVEHasBrokenRules hasBrokenRules = null;
if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules;
if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -333,14 +338,25 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _PartUnique = 0;
private int _MyPartUnique;
public int MyPartUnique
{
get { return _MyPartUnique; }
}
protected Part()
{/* require use of factory methods */
_MyPartUnique = ++_PartUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString());
if (!_AllByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return;
List<Part> listPart = _AllByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items
listPart.Remove(this); // Remove the item from the list
if (listPart.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list
}
public static Part New()
{
@@ -399,7 +415,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<Part>(new PKCriteria(contentID, fromType));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -482,7 +498,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.ReadData", GetHashCode());
try
{
_ContentID = dr.GetInt32("ContentID");
@@ -495,14 +511,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Part.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -531,7 +547,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Part.DataPortal_Fetch", ex);
}
@@ -552,13 +568,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Part.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -567,8 +583,8 @@ namespace VEPROMS.CSLA.Library
if (!this.IsDirty) return;
try
{
if(_MyContent != null) _MyContent.Update();
if(_MyItem != null) _MyItem.Update();
if (_MyContent != null) _MyContent.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
@@ -591,11 +607,11 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// update child objects
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Part.SQLInsert", ex);
}
@@ -603,7 +619,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -628,7 +644,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Add", ex);
throw new DbCslaException("Part.Add", ex);
}
}
@@ -636,7 +652,7 @@ namespace VEPROMS.CSLA.Library
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -650,7 +666,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -659,11 +675,11 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.SQLUpdate", GetHashCode());
try
{
if(_MyContent != null) _MyContent.Update();
if(_MyItem != null) _MyItem.Update();
if (_MyContent != null) _MyContent.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
@@ -693,7 +709,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -714,7 +730,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -740,7 +756,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Update", ex);
throw new DbCslaException("Part.Update", ex);
}
}
@@ -752,7 +768,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -769,7 +785,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Part.DataPortal_Delete", ex);
}
@@ -777,7 +793,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int contentID, int fromType)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -793,7 +809,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Remove", ex);
throw new DbCslaException("Part.Remove", ex);
}
}
@@ -829,7 +845,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Part.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -848,7 +864,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Part.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Execute", ex);
throw new DbCslaException("Part.DataPortal_Execute", ex);
}
}