CSLA - Generated - C Items

This commit is contained in:
2026-09-04 13:34:46 -04:00
parent 222371302f
commit 8a55eb57d6
27 changed files with 1563 additions and 3464 deletions
+116 -259
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshChecks.Add(this);
}
private void ClearRefreshList()
{
_RefreshChecks = new List<Check>();
}
private void ClearRefreshList() => _RefreshChecks = new List<Check>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -58,6 +53,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Check> _CacheList = new List<Check>();
protected static void AddToCache(Check check)
{
@@ -67,6 +63,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(check)) _CacheList.Remove(check); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Check>> _CacheByPrimaryKey = new Dictionary<string, List<Check>>();
private static void ConvertListToDictionary()
{
@@ -92,15 +89,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextCheckID = -1;
public static int NextCheckID
{
get { return _nextCheckID--; }
}
public static int NextCheckID => _nextCheckID--;
private int _CheckID;
[System.ComponentModel.DataObjectField(true, true)]
public int CheckID
@@ -242,7 +233,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list));
return base.IsDirty || (_MyRevision != null && _MyRevision.IsDirtyList(list)) || (_MyStage != null && _MyStage.IsDirtyList(list));
}
public override bool IsValid
{
@@ -251,20 +242,10 @@ namespace VEPROMS.CSLA.Library
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyRevision == null || _MyRevision.IsValidList(list)) && (_MyStage == null || _MyStage.IsValidList(list));
}
// CSLATODO: Replace base Check.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Check</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Check.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
@@ -302,8 +283,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -318,14 +299,12 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
//ValidationRules.AddDependantProperty("x", "y");
_CheckExtension.AddValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
protected override void AddInstanceBusinessRules()
{
_CheckExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
private static bool MyRevisionRequired(Check target, Csla.Validation.RuleArgs e)
{
@@ -345,76 +324,14 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(CheckID, "<Role(s)>");
//AuthorizationRules.AllowRead(RevisionID, "<Role(s)>");
//AuthorizationRules.AllowRead(StageID, "<Role(s)>");
//AuthorizationRules.AllowRead(ConsistencyChecks, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RevisionID, "<Role(s)>");
//AuthorizationRules.AllowWrite(StageID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ConsistencyChecks, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_CheckExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_CheckExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _CheckUnique = 0;
protected static int CheckUnique
{ get { return ++_CheckUnique; } }
private int _MyCheckUnique = CheckUnique;
public int MyCheckUnique // Absolutely Unique ID - Editable
{ get { return _MyCheckUnique; } }
protected static int CheckUnique => ++_CheckUnique;
private readonly int _MyCheckUnique = CheckUnique;
// Absolutely Unique ID - Editable
public int MyCheckUnique => _MyCheckUnique;
protected Check()
{/* require use of factory methods */
AddToCache(this);
@@ -423,15 +340,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Check()
{
_CountFinalized++;
@@ -456,8 +369,6 @@ namespace VEPROMS.CSLA.Library
}
public static Check New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Check");
try
{
return DataPortal.Create<Check>();
@@ -526,8 +437,6 @@ namespace VEPROMS.CSLA.Library
}
public static Check Get(int checkID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Check");
try
{
Check tmp = GetCachedByPrimaryKey(checkID);
@@ -553,14 +462,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Check(dr);
return null;
}
internal Check(SafeDataReader dr)
{
ReadData(dr);
}
internal Check(SafeDataReader dr) => ReadData(dr);
public static void Delete(int checkID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Check");
try
{
DataPortal.Delete(new PKCriteria(checkID));
@@ -572,12 +476,6 @@ namespace VEPROMS.CSLA.Library
}
public override Check Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Check");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Check");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Check");
try
{
BuildRefreshList();
@@ -597,13 +495,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _CheckID;
public int CheckID
{ get { return _CheckID; } }
public PKCriteria(int checkID)
{
_CheckID = checkID;
}
private readonly int _CheckID;
public int CheckID => _CheckID;
public PKCriteria(int checkID) => _CheckID = checkID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -701,36 +595,43 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyRevision != null) _MyRevision.Update();
if (_MyStage != null) _MyStage.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyRevision?.Update();
_MyStage?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addCheck";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@RevisionID", RevisionID);
cm.Parameters.AddWithValue("@StageID", StageID);
cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int);
param_CheckID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_CheckID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_CheckID = (int)cm.Parameters["@newCheckID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addCheck";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@RevisionID", RevisionID);
cm.Parameters.AddWithValue("@StageID", StageID);
cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_CheckID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_CheckID = (int)cm.Parameters["@newCheckID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.SQLInsert", GetHashCode());
@@ -760,11 +661,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int);
param_CheckID.Direction = ParameterDirection.Output;
SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_CheckID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -809,34 +714,39 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.SQLUpdate", GetHashCode());
try
{
if (_MyRevision != null) _MyRevision.Update();
if (_MyStage != null) _MyStage.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyRevision?.Update();
_MyStage?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateCheck";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@CheckID", _CheckID);
cm.Parameters.AddWithValue("@RevisionID", RevisionID);
cm.Parameters.AddWithValue("@StageID", StageID);
cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateCheck";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@CheckID", _CheckID);
cm.Parameters.AddWithValue("@RevisionID", RevisionID);
cm.Parameters.AddWithValue("@StageID", StageID);
cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -849,14 +759,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID);
else
_LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID);
else
_LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
@@ -880,8 +793,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -896,10 +811,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_CheckID));
}
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_CheckID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
@@ -966,16 +878,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _CheckID;
private readonly int _CheckID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int checkID)
{
_CheckID = checkID;
}
public bool Exists => _exists;
public ExistsCommand(int checkID) => _CheckID = checkID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Execute", GetHashCode());
@@ -1005,7 +911,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
CheckExtension _CheckExtension = new CheckExtension();
readonly CheckExtension _CheckExtension = new CheckExtension();
[Serializable()]
partial class CheckExtension : extensionBase
{
@@ -1014,14 +920,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1050,10 +950,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Check)
if (destType == typeof(string) && value is Check check)
{
// Return the ToString value
return ((Check)value).ToString();
return check.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -1061,46 +961,3 @@ namespace VEPROMS.CSLA.Library
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create CheckExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Check
// {
// partial class CheckExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class CheckInfo : ReadOnlyBase<CheckInfo>, IDisposable
{
public event CheckInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<CheckInfo> _CacheList = new List<CheckInfo>();
protected static void AddToCache(CheckInfo checkInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(checkInfo)) _CacheList.Remove(checkInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<CheckInfo>> _CacheByPrimaryKey = new Dictionary<string, List<CheckInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Check _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _CheckID;
[System.ComponentModel.DataObjectField(true, true)]
public int CheckID
@@ -166,32 +150,18 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base CheckInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current CheckInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check CheckInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current CheckInfo</returns>
protected override object GetIdValue()
{
return MyCheckInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyCheckInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _CheckInfoUnique = 0;
private static int CheckInfoUnique
{ get { return ++_CheckInfoUnique; } }
private int _MyCheckInfoUnique = CheckInfoUnique;
public int MyCheckInfoUnique // Absolutely Unique ID - Info
{ get { return _MyCheckInfoUnique; } }
private static int CheckInfoUnique => ++_CheckInfoUnique;
private readonly int _MyCheckInfoUnique = CheckInfoUnique;
// Absolutely Unique ID - Info
public int MyCheckInfoUnique => _MyCheckInfoUnique;
protected CheckInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -200,15 +170,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~CheckInfo()
{
_CountFinalized++;
@@ -225,10 +191,7 @@ namespace VEPROMS.CSLA.Library
if (listCheckInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list
}
public virtual Check Get()
{
return _Editable = Check.Get(_CheckID);
}
public virtual Check Get() => _Editable = Check.Get(_CheckID);
public static void Refresh(Check tmp)
{
string key = tmp.CheckID.ToString();
@@ -241,18 +204,18 @@ namespace VEPROMS.CSLA.Library
{
if (_RevisionID != tmp.RevisionID)
{
if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value
MyRevision?.RefreshRevisionChecks(); // Update List for old value
_RevisionID = tmp.RevisionID; // Update the value
}
_MyRevision = null; // Reset list so that the next line gets a new list
if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value
MyRevision?.RefreshRevisionChecks(); // Update List for new value
if (_StageID != tmp.StageID)
{
if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value
MyStage?.RefreshStageChecks(); // Update List for old value
_StageID = tmp.StageID; // Update the value
}
_MyStage = null; // Reset list so that the next line gets a new list
if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value
MyStage?.RefreshStageChecks(); // Update List for new value
_ConsistencyChecks = tmp.ConsistencyChecks;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -271,11 +234,11 @@ namespace VEPROMS.CSLA.Library
{
if (_StageID != tmp.StageID)
{
if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value
MyStage?.RefreshStageChecks(); // Update List for old value
_StageID = tmp.StageID; // Update the value
}
_MyStage = null; // Reset list so that the next line gets a new list
if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value
MyStage?.RefreshStageChecks(); // Update List for new value
_ConsistencyChecks = tmp.ConsistencyChecks;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -294,11 +257,11 @@ namespace VEPROMS.CSLA.Library
{
if (_RevisionID != tmp.RevisionID)
{
if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value
MyRevision?.RefreshRevisionChecks(); // Update List for old value
_RevisionID = tmp.RevisionID; // Update the value
}
_MyRevision = null; // Reset list so that the next line gets a new list
if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value
MyRevision?.RefreshRevisionChecks(); // Update List for new value
_ConsistencyChecks = tmp.ConsistencyChecks;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -307,8 +270,6 @@ namespace VEPROMS.CSLA.Library
}
public static CheckInfo Get(int checkID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Check");
try
{
CheckInfo tmp = GetCachedByPrimaryKey(checkID);
@@ -347,13 +308,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _CheckID;
public int CheckID
{ get { return _CheckID; } }
public PKCriteria(int checkID)
{
_CheckID = checkID;
}
private readonly int _CheckID;
public int CheckID => _CheckID;
public PKCriteria(int checkID) => _CheckID = checkID;
}
private void ReadData(SafeDataReader dr)
{
@@ -413,7 +370,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
CheckInfoExtension _CheckInfoExtension = new CheckInfoExtension();
readonly CheckInfoExtension _CheckInfoExtension = new CheckInfoExtension();
[Serializable()]
partial class CheckInfoExtension : extensionBase { }
[Serializable()]
@@ -429,10 +386,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is CheckInfo)
if (destType == typeof(string) && value is CheckInfo info)
{
// Return the ToString value
return ((CheckInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<CheckInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<CheckInfo> Items => base.Items;
public void AddEvents()
{
foreach (CheckInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~CheckInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~CheckInfoList()
{
_CountFinalized++;
}
@@ -180,11 +173,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class RevisionIDCriteria
{
public RevisionIDCriteria(int revisionID)
{
_RevisionID = revisionID;
}
private int _RevisionID;
public RevisionIDCriteria(int revisionID) => _RevisionID = revisionID;
private int _RevisionID;
public int RevisionID
{
get { return _RevisionID; }
@@ -224,11 +214,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class StageIDCriteria
{
public StageIDCriteria(int stageID)
{
_StageID = stageID;
}
private int _StageID;
public StageIDCriteria(int stageID) => _StageID = stageID;
private int _StageID;
public int StageID
{
get { return _StageID; }
@@ -265,41 +252,31 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -321,7 +298,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class CheckInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private CheckInfo Item { get { return (CheckInfo)_Item; } }
public CheckInfoListPropertyDescriptor(CheckInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +306,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is CheckInfoList)
if (destType == typeof(string) && value is CheckInfoList list)
{
// Return department and department role separated by comma.
return ((CheckInfoList)value).Items.Count.ToString() + " Checks";
return $"{list.Items.Count} Checks";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public new Folder this[int folderID]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public new Folder this[int folderID]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<Folder> Items
{
get { return base.Items; }
}
public Folder GetItem(int folderID)
public new System.Collections.Generic.IList<Folder> Items => base.Items;
public Folder GetItem(int folderID)
{
foreach (Folder folder in this)
if (folder.FolderID == folderID)
@@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library
if (!Contains(name))
{
Folder folder = Folder.New(myParent, name, shortName);
this.Add(folder);
Add(folder);
return folder;
}
else
@@ -108,23 +100,19 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (Folder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (Folder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
public bool Contains(string name)
{
foreach (Folder folder in this)
@@ -156,20 +144,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return (hasBrokenRules?.BrokenRules);
}
}
#endregion
#region Factory Methods
internal static ChildFolders New()
{
return new ChildFolders();
}
internal static ChildFolders Get(SafeDataReader dr, Folder parent)
{
return new ChildFolders(dr, parent);
}
public static ChildFolders GetByParentID(int parentID)
#endregion
#region Factory Methods
internal static ChildFolders New() => new ChildFolders();
internal static ChildFolders Get(SafeDataReader dr, Folder parent) => new ChildFolders(dr, parent);
public static ChildFolders GetByParentID(int parentID)
{
try
{
@@ -180,11 +162,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ChildFolders.GetByParentID", ex);
}
}
private ChildFolders()
{
MarkAsChild();
}
internal ChildFolders(SafeDataReader dr, Folder parent)
private ChildFolders() => MarkAsChild();
internal ChildFolders(SafeDataReader dr, Folder parent)
{
MarkAsChild();
Fetch(dr, parent);
@@ -193,16 +172,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ChildFolders()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ChildFolders()
{
_CountFinalized++;
}
@@ -217,19 +192,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr, Folder parent)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(Folder.Get(dr, parent));
this.RaiseListChangedEvents = true;
Add(Folder.Get(dr, parent));
RaiseListChangedEvents = true;
}
[Serializable()]
private class ParentIDCriteria
{
public ParentIDCriteria(int parentID)
{
_ParentID = parentID;
}
private int _ParentID;
public ParentIDCriteria(int parentID) => _ParentID = parentID;
private int _ParentID;
public int ParentID
{
get { return _ParentID; }
@@ -238,7 +210,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ParentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ChildFolders.DataPortal_FetchParentID", GetHashCode());
try
{
@@ -252,7 +224,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new Folder(dr, criteria.ParentID));
while (dr.Read()) Add(new Folder(dr, criteria.ParentID));
}
}
}
@@ -262,11 +234,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ChildFolders.DataPortal_FetchParentID", ex);
throw new DbCslaException("ChildFolders.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Folder folder)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -285,49 +257,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ChildFoldersPropertyDescriptor pd = new ChildFoldersPropertyDescriptor(this, i);
@@ -353,10 +314,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ChildFolders)
if (destType == typeof(string) && value is ChildFolders folders)
{
// Return department and department role separated by comma.
return ((ChildFolders)value).Items.Count.ToString() + " Folders";
return $"{folders.Items.Count} Folders";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public new Format this[int formatID]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public new Format this[int formatID]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<Format> Items
{
get { return base.Items; }
}
public Format GetItem(int formatID)
public new System.Collections.Generic.IList<Format> Items => base.Items;
public Format GetItem(int formatID)
{
foreach (Format format in this)
if (format.FormatID == formatID)
@@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library
if (!Contains(name))
{
Format format = Format.New(myParent, name, data);
this.Add(format);
Add(format);
return format;
}
else
@@ -108,23 +100,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (Format child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (Format child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
public bool Contains(string name)
{
foreach (Format format in this)
@@ -156,20 +145,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return (hasBrokenRules?.BrokenRules);
}
}
#endregion
#region Factory Methods
internal static ChildFormats New()
{
return new ChildFormats();
}
internal static ChildFormats Get(SafeDataReader dr, Format parent)
{
return new ChildFormats(dr, parent);
}
public static ChildFormats GetByParentID(int parentID)
#endregion
#region Factory Methods
internal static ChildFormats New() => new ChildFormats();
internal static ChildFormats Get(SafeDataReader dr, Format parent) => new ChildFormats(dr, parent);
public static ChildFormats GetByParentID(int parentID)
{
try
{
@@ -180,11 +163,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ChildFormats.GetByParentID", ex);
}
}
private ChildFormats()
{
MarkAsChild();
}
internal ChildFormats(SafeDataReader dr, Format parent)
private ChildFormats() => MarkAsChild();
internal ChildFormats(SafeDataReader dr, Format parent)
{
MarkAsChild();
Fetch(dr, parent);
@@ -193,16 +173,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ChildFormats()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ChildFormats()
{
_CountFinalized++;
}
@@ -217,19 +193,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr, Format parent)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(Format.Get(dr, parent));
this.RaiseListChangedEvents = true;
Add(Format.Get(dr, parent));
RaiseListChangedEvents = true;
}
[Serializable()]
private class ParentIDCriteria
{
public ParentIDCriteria(int parentID)
{
_ParentID = parentID;
}
private int _ParentID;
public ParentIDCriteria(int parentID) => _ParentID = parentID;
private int _ParentID;
public int ParentID
{
get { return _ParentID; }
@@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ParentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ChildFormats.DataPortal_FetchParentID", GetHashCode());
try
{
@@ -252,7 +225,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new Format(dr, criteria.ParentID));
while (dr.Read()) Add(new Format(dr, criteria.ParentID));
}
}
}
@@ -262,11 +235,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ChildFormats.DataPortal_FetchParentID", ex);
throw new DbCslaException("ChildFormats.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -285,49 +258,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ChildFormatsPropertyDescriptor pd = new ChildFormatsPropertyDescriptor(this, i);
@@ -344,7 +306,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ChildFormatsPropertyDescriptor : vlnListPropertyDescriptor
{
private Format Item { get { return (Format)_Item; } }
public ChildFormatsPropertyDescriptor(ChildFormats collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -353,10 +314,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ChildFormats)
if (destType == typeof(string) && value is ChildFormats formats)
{
// Return department and department role separated by comma.
return ((ChildFormats)value).Items.Count.ToString() + " Formats";
return $"{formats.Items.Count} Formats";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -8,15 +8,6 @@
// $History: $
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using Csla.Validation;
using System.Reflection;
namespace VEPROMS.CSLA.Library
{
@@ -31,7 +22,7 @@ namespace VEPROMS.CSLA.Library
if (propertyInfoObj == null) return true;
if (propertyInfoObj.GetValue(target, null) == null)
{
e.Description = e.PropertyName + " is a required field";
e.Description = $"{e.PropertyName} is a required field";
return false;
}
return true;
+123 -297
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -69,6 +67,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Connection> _CacheList = new List<Connection>();
protected static void AddToCache(Connection connection)
{
@@ -78,7 +77,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(connection)) _CacheList.Remove(connection); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Connection>> _CacheByPrimaryKey = new Dictionary<string, List<Connection>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Connection>> _CacheByName = new Dictionary<string, List<Connection>>();
private static void ConvertListToDictionary()
{
@@ -113,15 +114,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextDBID = -1;
public static int NextDBID
{
get { return _nextDBID--; }
}
public static int NextDBID => _nextDBID--;
private int _DBID;
[System.ComponentModel.DataObjectField(true, true)]
public int DBID
@@ -298,10 +293,6 @@ namespace VEPROMS.CSLA.Library
return _ConnectionFolders;
}
}
public void Reset_ConnectionFolders()
{
_ConnectionFolderCount = -1;
}
public override bool IsDirty
{
get
@@ -316,37 +307,21 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_ConnectionFolders == null ? false : _ConnectionFolders.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_ConnectionFolders != null && _ConnectionFolders.IsDirtyList(list));
}
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ConnectionFolders == null ? true : _ConnectionFolders.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_ConnectionFolders == null || _ConnectionFolders.IsValidList(list));
}
// CSLATODO: Replace base Connection.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Connection</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Connection.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Connection</returns>
protected override object GetIdValue()
{
return MyConnectionUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyConnectionUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -375,8 +350,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -407,93 +382,14 @@ namespace VEPROMS.CSLA.Library
_ConnectionExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DBID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ConnectionString, "<Role(s)>");
//AuthorizationRules.AllowRead(ServerType, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(ConnectionString, "<Role(s)>");
//AuthorizationRules.AllowWrite(ServerType, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_ConnectionExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_ConnectionExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _ConnectionFolderCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ConnectionUnique = 0;
protected static int ConnectionUnique
{ get { return ++_ConnectionUnique; } }
private int _MyConnectionUnique = ConnectionUnique;
public int MyConnectionUnique // Absolutely Unique ID - Editable
{ get { return _MyConnectionUnique; } }
protected static int ConnectionUnique => ++_ConnectionUnique;
private readonly int _MyConnectionUnique = ConnectionUnique;
// Absolutely Unique ID - Editable
public int MyConnectionUnique => _MyConnectionUnique;
protected Connection()
{/* require use of factory methods */
AddToCache(this);
@@ -502,15 +398,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Connection()
{
_CountFinalized++;
@@ -547,8 +439,6 @@ namespace VEPROMS.CSLA.Library
}
public static Connection New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Connection");
try
{
return DataPortal.Create<Connection>();
@@ -613,8 +503,6 @@ namespace VEPROMS.CSLA.Library
}
public static Connection Get(int dbid)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Connection");
try
{
Connection tmp = GetCachedByPrimaryKey(dbid);
@@ -637,8 +525,6 @@ namespace VEPROMS.CSLA.Library
}
public static Connection GetByName(string name)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Connection");
try
{
Connection tmp = GetCachedByName(name);
@@ -664,14 +550,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Connection(dr);
return null;
}
internal Connection(SafeDataReader dr)
{
ReadData(dr);
}
internal Connection(SafeDataReader dr) => ReadData(dr);
public static void Delete(int dbid)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Connection");
try
{
DataPortal.Delete(new PKCriteria(dbid));
@@ -683,12 +564,6 @@ namespace VEPROMS.CSLA.Library
}
public override Connection Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Connection");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Connection");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Connection");
try
{
BuildRefreshList();
@@ -708,24 +583,16 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DBID;
public int DBID
{ get { return _DBID; } }
public PKCriteria(int dbid)
{
_DBID = dbid;
}
private readonly int _DBID;
public int DBID => _DBID;
public PKCriteria(int dbid) => _DBID = dbid;
}
[Serializable()]
private class NameCriteria
{
private string _Name;
public string Name
{ get { return _Name; } }
public NameCriteria(string name)
{
_Name = name;
}
private readonly string _Name;
public string Name => _Name;
public NameCriteria(string name) => _Name = name;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -866,39 +733,46 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addConnection";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString);
cm.Parameters.AddWithValue("@ServerType", _ServerType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_DBID = new SqlParameter("@newDBID", SqlDbType.Int);
param_DBID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_DBID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DBID = (int)cm.Parameters["@newDBID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addConnection";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString);
cm.Parameters.AddWithValue("@ServerType", _ServerType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_DBID = new SqlParameter("@newDBID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DBID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DBID = (int)cm.Parameters["@newDBID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_ConnectionFolders != null) _ConnectionFolders.Update(this);
_ConnectionFolders?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -928,11 +802,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
// Output Calculated Columns
SqlParameter param_DBID = new SqlParameter("@newDBID", SqlDbType.Int);
param_DBID.Direction = ParameterDirection.Output;
SqlParameter param_DBID = new SqlParameter("@newDBID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DBID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -977,37 +855,42 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateConnection";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DBID", _DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString);
cm.Parameters.AddWithValue("@ServerType", _ServerType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateConnection";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DBID", _DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString);
cm.Parameters.AddWithValue("@ServerType", _ServerType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_ConnectionFolders != null) _ConnectionFolders.Update(this);
_ConnectionFolders?.Update(this);
}
catch (Exception ex)
{
@@ -1018,17 +901,20 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID);
else
_LastChanged = Connection.Update(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID);
else
_LastChanged = Connection.Update(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
if (_ConnectionFolders != null) _ConnectionFolders.Update(this);
_ConnectionFolders?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int dbid, string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID, ref byte[] lastChanged)
@@ -1052,8 +938,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1138,16 +1026,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _DBID;
private readonly int _DBID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int dbid)
{
_DBID = dbid;
}
public bool Exists => _exists;
public ExistsCommand(int dbid) => _DBID = dbid;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Execute", GetHashCode());
@@ -1177,7 +1059,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ConnectionExtension _ConnectionExtension = new ConnectionExtension();
readonly ConnectionExtension _ConnectionExtension = new ConnectionExtension();
[Serializable()]
partial class ConnectionExtension : extensionBase
{
@@ -1186,18 +1068,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultServerType
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultServerType => 1;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1226,10 +1099,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Connection)
if (destType == typeof(string) && value is Connection conn)
{
// Return the ToString value
return ((Connection)value).ToString();
return conn.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -1237,50 +1110,3 @@ namespace VEPROMS.CSLA.Library
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ConnectionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Connection
// {
// partial class ConnectionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultServerType
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -255,19 +249,8 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ConnectionFolder</returns>
protected override object GetIdValue()
{
return MyConnectionFolderUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ConnectionFolder.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ConnectionFolder</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyConnectionFolderUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -282,18 +265,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list));
}
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -324,8 +304,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -363,86 +343,16 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ConnectionFolderUnique = 0;
private static int ConnectionFolderUnique
{ get { return ++_ConnectionFolderUnique; } }
private int _MyConnectionFolderUnique = ConnectionFolderUnique;
public int MyConnectionFolderUnique // Absolutely Unique ID - Editable FK
{ get { return _MyConnectionFolderUnique; } }
internal static ConnectionFolder New(Folder myParent, string name, string shortName)
{
return new ConnectionFolder(myParent, name, shortName);
}
internal static ConnectionFolder Get(SafeDataReader dr)
{
return new ConnectionFolder(dr);
}
private static int ConnectionFolderUnique => ++_ConnectionFolderUnique;
private readonly int _MyConnectionFolderUnique = ConnectionFolderUnique;
// Absolutely Unique ID - Editable FK
public int MyConnectionFolderUnique => _MyConnectionFolderUnique;
internal static ConnectionFolder New(Folder myParent, string name, string shortName) => new ConnectionFolder(myParent, name, shortName);
internal static ConnectionFolder Get(SafeDataReader dr) => new ConnectionFolder(dr);
public ConnectionFolder()
{
MarkAsChild();
@@ -474,15 +384,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ConnectionFolder()
{
_CountFinalized++;
@@ -522,33 +428,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Connection myConnection)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Connection myConnection)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, myConnection.DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, myConnection.DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping myConnection for CSLA compliance")]
internal void DeleteSelf(Connection myConnection)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Folder.Remove(cn, _FolderID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Folder.Remove(cn, _FolderID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ConnectionFolderExtension _ConnectionFolderExtension = new ConnectionFolderExtension();
readonly ConnectionFolderExtension _ConnectionFolderExtension = new ConnectionFolderExtension();
[Serializable()]
partial class ConnectionFolderExtension : extensionBase
{
@@ -557,22 +473,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual int DefaultDBID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
public virtual int DefaultDBID => 1;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -601,65 +505,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ConnectionFolder)
if (destType == typeof(string) && value is ConnectionFolder folder)
{
// Return the ToString value
return ((ConnectionFolder)value).ToString();
return folder.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ConnectionFolderExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ConnectionFolder
// {
// partial class ConnectionFolderExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual int DefaultDBID
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public ConnectionFolder this[Folder myFolder]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public ConnectionFolder this[Folder myFolder]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ConnectionFolder> Items
{
get { return base.Items; }
}
public ConnectionFolder GetItem(Folder myFolder)
public new System.Collections.Generic.IList<ConnectionFolder> Items => base.Items;
public ConnectionFolder GetItem(Folder myFolder)
{
foreach (ConnectionFolder folder in this)
if (folder.FolderID == myFolder.FolderID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ConnectionFolder Add(Folder myParent, string name, string shortName) // One to Many
{
ConnectionFolder folder = ConnectionFolder.New(myParent, name, shortName);
this.Add(folder);
Add(folder);
return folder;
}
public void Remove(Folder myFolder)
@@ -103,23 +95,19 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ConnectionFolder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ConnectionFolder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +125,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return (hasBrokenRules?.BrokenRules);
}
}
#endregion
#region Factory Methods
internal static ConnectionFolders New()
{
return new ConnectionFolders();
}
internal static ConnectionFolders Get(SafeDataReader dr)
{
return new ConnectionFolders(dr);
}
public static ConnectionFolders GetByDBID(int dbid)
#endregion
#region Factory Methods
internal static ConnectionFolders New() => new ConnectionFolders();
internal static ConnectionFolders Get(SafeDataReader dr) => new ConnectionFolders(dr);
public static ConnectionFolders GetByDBID(int dbid)
{
try
{
@@ -161,11 +143,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ConnectionFolders.GetByDBID", ex);
}
}
private ConnectionFolders()
{
MarkAsChild();
}
internal ConnectionFolders(SafeDataReader dr)
private ConnectionFolders() => MarkAsChild();
internal ConnectionFolders(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +153,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ConnectionFolders()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ConnectionFolders()
{
_CountFinalized++;
}
@@ -198,19 +173,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(ConnectionFolder.Get(dr));
this.RaiseListChangedEvents = true;
Add(ConnectionFolder.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class DBIDCriteria
{
public DBIDCriteria(int dbid)
{
_DBID = dbid;
}
private int _DBID;
public DBIDCriteria(int dbid) => _DBID = dbid;
private int _DBID;
public int DBID
{
get { return _DBID; }
@@ -219,7 +191,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(DBIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionFolders.DataPortal_FetchDBID", GetHashCode());
try
{
@@ -233,7 +205,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new ConnectionFolder(dr));
while (dr.Read()) Add(new ConnectionFolder(dr));
}
}
}
@@ -243,11 +215,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionFolders.DataPortal_FetchDBID", ex);
throw new DbCslaException("ConnectionFolders.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Connection connection)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +238,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ConnectionFoldersPropertyDescriptor pd = new ConnectionFoldersPropertyDescriptor(this, i);
@@ -325,7 +286,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ConnectionFoldersPropertyDescriptor : vlnListPropertyDescriptor
{
private ConnectionFolder Item { get { return (ConnectionFolder)_Item; } }
public ConnectionFoldersPropertyDescriptor(ConnectionFolders collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +294,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ConnectionFolders)
if (destType == typeof(string) && value is ConnectionFolders folders)
{
// Return department and department role separated by comma.
return ((ConnectionFolders)value).Items.Count.ToString() + " Folders";
return $"{folders.Items.Count} Folders";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ConnectionInfo : ReadOnlyBase<ConnectionInfo>, IDisposable
{
public event ConnectionInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ConnectionInfo> _CacheList = new List<ConnectionInfo>();
protected static void AddToCache(ConnectionInfo connectionInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(connectionInfo)) _CacheList.Remove(connectionInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ConnectionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ConnectionInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Connection _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _DBID;
[System.ComponentModel.DataObjectField(true, true)]
public int DBID
@@ -201,32 +185,19 @@ namespace VEPROMS.CSLA.Library
foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()])
tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base ConnectionInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ConnectionInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ConnectionInfo</returns>
protected override object GetIdValue()
{
return MyConnectionInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyConnectionInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _ConnectionInfoUnique = 0;
private static int ConnectionInfoUnique
{ get { return ++_ConnectionInfoUnique; } }
private int _MyConnectionInfoUnique = ConnectionInfoUnique;
public int MyConnectionInfoUnique // Absolutely Unique ID - Info
{ get { return _MyConnectionInfoUnique; } }
private static int ConnectionInfoUnique => ++_ConnectionInfoUnique;
private readonly int _MyConnectionInfoUnique = ConnectionInfoUnique;
// Absolutely Unique ID - Info
public int MyConnectionInfoUnique => _MyConnectionInfoUnique;
protected ConnectionInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -235,15 +206,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ConnectionInfo()
{
_CountFinalized++;
@@ -260,10 +227,7 @@ namespace VEPROMS.CSLA.Library
if (listConnectionInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list
}
public virtual Connection Get()
{
return _Editable = Connection.Get(_DBID);
}
public virtual Connection Get() => _Editable = Connection.Get(_DBID);
public static void Refresh(Connection tmp)
{
string key = tmp.DBID.ToString();
@@ -326,13 +290,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DBID;
public int DBID
{ get { return _DBID; } }
public PKCriteria(int dbid)
{
_DBID = dbid;
}
private readonly int _DBID;
public int DBID => _DBID;
public PKCriteria(int dbid) => _DBID = dbid;
}
private void ReadData(SafeDataReader dr)
{
@@ -395,7 +355,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension();
readonly ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension();
[Serializable()]
partial class ConnectionInfoExtension : extensionBase { }
[Serializable()]
@@ -411,10 +371,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ConnectionInfo)
if (destType == typeof(string) && value is ConnectionInfo info)
{
// Return the ToString value
return ((ConnectionInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<ConnectionInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<ConnectionInfo> Items => base.Items;
public void AddEvents()
{
foreach (ConnectionInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ConnectionInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ConnectionInfoList()
{
_CountFinalized++;
}
@@ -104,18 +97,6 @@ namespace VEPROMS.CSLA.Library
{
_ConnectionInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ConnectionInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ConnectionInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ConnectionInfoList.Get", ex);
// }
//}
private ConnectionInfoList()
{ /* require use of factory methods */ }
#endregion
@@ -149,41 +130,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +175,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ConnectionInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private ConnectionInfo Item { get { return (ConnectionInfo)_Item; } }
public ConnectionInfoListPropertyDescriptor(ConnectionInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +183,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ConnectionInfoList)
if (destType == typeof(string) && value is ConnectionInfoList list)
{
// Return department and department role separated by comma.
return ((ConnectionInfoList)value).Items.Count.ToString() + " Connections";
return $"{list.Items.Count} Connections";
}
return base.ConvertTo(context, culture, value, destType);
}
+149 -335
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -122,6 +120,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Content> _CacheList = new List<Content>();
protected static void AddToCache(Content content)
{
@@ -131,6 +130,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Content>> _CacheByPrimaryKey = new Dictionary<string, List<Content>>();
private static void ConvertListToDictionary()
{
@@ -159,15 +159,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextContentID = -1;
public static int NextContentID
{
get { return _nextContentID--; }
}
public static int NextContentID => _nextContentID--;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -369,10 +363,7 @@ namespace VEPROMS.CSLA.Library
return _ContentDetails;
}
}
public void Reset_ContentDetails()
{
_ContentDetailCount = -1;
}
public void Reset_ContentDetails() => _ContentDetailCount = -1;
private int _ContentEntryCount = 0;
/// <summary>
/// Count of ContentEntries for this Content
@@ -564,10 +555,7 @@ namespace VEPROMS.CSLA.Library
return _ContentRoUsages;
}
}
public void Reset_ContentRoUsages()
{
_ContentRoUsageCount = -1;
}
public void Reset_ContentRoUsages() => _ContentRoUsageCount = -1;
private int _ContentTransitionCount = 0;
/// <summary>
/// Count of ContentTransitions for this Content
@@ -601,10 +589,7 @@ namespace VEPROMS.CSLA.Library
return _ContentTransitions;
}
}
public void Reset_ContentTransitions()
{
_ContentTransitionCount = -1;
}
public void Reset_ContentTransitions() => _ContentTransitionCount = -1;
private int _ContentZContentCount = 0;
/// <summary>
/// Count of ContentZContents for this Content
@@ -645,37 +630,21 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirtyList(list)) || (_MyEntry == null ? false : _MyEntry.IsDirtyList(list)) || (_MyGrid == null ? false : _MyGrid.IsDirtyList(list)) || (_MyImage == null ? false : _MyImage.IsDirtyList(list)) || (_ContentItems == null ? false : _ContentItems.IsDirtyList(list)) || (_ContentParts == null ? false : _ContentParts.IsDirtyList(list)) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirtyList(list)) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirtyList(list)) || (_MyZContent == null ? false : _MyZContent.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_ContentDetails != null && _ContentDetails.IsDirtyList(list)) || (_MyEntry != null && _MyEntry.IsDirtyList(list)) || (_MyGrid != null && _MyGrid.IsDirtyList(list)) || (_MyImage != null && _MyImage.IsDirtyList(list)) || (_ContentItems != null && _ContentItems.IsDirtyList(list)) || (_ContentParts != null && _ContentParts.IsDirtyList(list)) || (_ContentRoUsages != null && _ContentRoUsages.IsDirtyList(list)) || (_ContentTransitions != null && _ContentTransitions.IsDirtyList(list)) || (_MyZContent != null && _MyZContent.IsDirtyList(list)) || (_MyFormat != null && _MyFormat.IsDirtyList(list));
}
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ContentDetails == null ? true : _ContentDetails.IsValidList(list)) && (_MyEntry == null ? true : _MyEntry.IsValidList(list)) && (_MyGrid == null ? true : _MyGrid.IsValidList(list)) && (_MyImage == null ? true : _MyImage.IsValidList(list)) && (_ContentItems == null ? true : _ContentItems.IsValidList(list)) && (_ContentParts == null ? true : _ContentParts.IsValidList(list)) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValidList(list)) && (_ContentTransitions == null ? true : _ContentTransitions.IsValidList(list)) && (_MyZContent == null ? true : _MyZContent.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_ContentDetails == null || _ContentDetails.IsValidList(list)) && (_MyEntry == null || _MyEntry.IsValidList(list)) && (_MyGrid == null || _MyGrid.IsValidList(list)) && (_MyImage == null || _MyImage.IsValidList(list)) && (_ContentItems == null || _ContentItems.IsValidList(list)) && (_ContentParts == null || _ContentParts.IsValidList(list)) && (_ContentRoUsages == null || _ContentRoUsages.IsValidList(list)) && (_ContentTransitions == null || _ContentTransitions.IsValidList(list)) && (_MyZContent == null || _MyZContent.IsValidList(list)) && (_MyFormat == null || _MyFormat.IsValidList(list));
}
// CSLATODO: Replace base Content.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Content</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Content.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Content</returns>
protected override object GetIdValue()
{
return MyContentUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -713,8 +682,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -742,37 +711,11 @@ namespace VEPROMS.CSLA.Library
_ContentExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Number, "<Role(s)>");
//AuthorizationRules.AllowRead(Text, "<Role(s)>");
//AuthorizationRules.AllowRead(Type, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Number, "<Role(s)>");
//AuthorizationRules.AllowWrite(Text, "<Role(s)>");
//AuthorizationRules.AllowWrite(Type, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_ContentExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -780,63 +723,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ContentExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _ContentDetailCount;
usedByCount += _ContentEntryCount;
usedByCount += _ContentGridCount;
usedByCount += _ContentImageCount;
usedByCount += _ContentItemCount;
usedByCount += _ContentPartCount;
usedByCount += _ContentRoUsageCount;
usedByCount += _ContentTransitionCount;
usedByCount += _ContentZContentCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ContentUnique = 0;
protected static int ContentUnique
{ get { return ++_ContentUnique; } }
private int _MyContentUnique = ContentUnique;
public int MyContentUnique // Absolutely Unique ID - Editable
{ get { return _MyContentUnique; } }
protected static int ContentUnique => ++_ContentUnique;
private readonly int _MyContentUnique = ContentUnique;
// Absolutely Unique ID - Editable
public int MyContentUnique => _MyContentUnique;
protected Content()
{/* require use of factory methods */
AddToCache(this);
@@ -850,15 +744,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Content()
{
_CountFinalized++;
@@ -891,26 +781,6 @@ namespace VEPROMS.CSLA.Library
_MyGrid = null;
}
_Text = null;
//if (_ContentDetails != null)
// _ContentDetails = null;
//if (_ContentItems != null)
//{
// _ContentItems = null;
// //foreach (ContentItem ci in _ContentItems)
// // ci.Dispose();
//}
//if (_ContentRoUsages != null)
//{
// //foreach (ContentRoUsage cr in _ContentRoUsages)
// // cr.Dispose();
// _ContentRoUsages = null;
//}
//if (_ContentTransitions != null)
//{
// foreach (ContentTransition ct in _ContentTransitions)
// ct.Dispose();
// _ContentTransitions = null;
//}
}
private void RemoveFromDictionaries()
{
@@ -925,8 +795,6 @@ namespace VEPROMS.CSLA.Library
}
public static Content New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Content");
try
{
return DataPortal.Create<Content>();
@@ -992,8 +860,6 @@ namespace VEPROMS.CSLA.Library
}
public static Content Get(int contentID, bool forcerefresh = false)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Content");
try
{
//C2019-036 View Only mode work with Checked Out Procedures
@@ -1028,14 +894,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Content(dr);
return null;
}
internal Content(SafeDataReader dr)
{
ReadData(dr);
}
internal Content(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Content");
try
{
DataPortal.Delete(new PKCriteria(contentID));
@@ -1047,12 +908,6 @@ namespace VEPROMS.CSLA.Library
}
public override Content Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Content");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Content");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Content");
try
{
BuildRefreshList();
@@ -1072,13 +927,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -1214,48 +1065,55 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addContent";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int);
param_ContentID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_ContentID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_ContentID = (int)cm.Parameters["@newContentID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addContent";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ContentID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_ContentID = (int)cm.Parameters["@newContentID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_ContentItems != null) _ContentItems.Update(this);
if (_ContentDetails != null) _ContentDetails.Update(this);
if (_MyEntry != null) _MyEntry.Update(this);
if (_MyGrid != null) _MyGrid.Update(this);
if (_MyImage != null) _MyImage.Update(this);
if (_ContentParts != null) _ContentParts.Update(this);
if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
if (_ContentTransitions != null) _ContentTransitions.Update(this);
if (_MyZContent != null) _MyZContent.Update(this);
_ContentItems?.Update(this);
_ContentDetails?.Update(this);
_MyEntry?.Update(this);
_MyGrid?.Update(this);
_MyImage?.Update(this);
_ContentParts?.Update(this);
_ContentRoUsages?.Update(this);
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1285,11 +1143,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int);
param_ContentID.Direction = ParameterDirection.Output;
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ContentID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1334,47 +1196,52 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLUpdate", GetHashCode());
try
{
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString());
cm.CommandText = "updateContent";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString());
cm.CommandText = "updateContent";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_ContentItems != null) _ContentItems.Update(this);
if (_ContentDetails != null) _ContentDetails.Update(this);
if (_MyEntry != null) _MyEntry.Update(this);
if (_MyGrid != null) _MyGrid.Update(this);
if (_MyImage != null) _MyImage.Update(this);
if (_ContentParts != null) _ContentParts.Update(this);
if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
if (_ContentTransitions != null) _ContentTransitions.Update(this);
if (_MyZContent != null) _MyZContent.Update(this);
_ContentItems?.Update(this);
_ContentDetails?.Update(this);
_MyEntry?.Update(this);
_MyGrid?.Update(this);
_MyImage?.Update(this);
_ContentParts?.Update(this);
_ContentRoUsages?.Update(this);
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
}
catch (Exception ex)
{
@@ -1385,25 +1252,28 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID);
else
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID);
else
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
if (_ContentItems != null) _ContentItems.Update(this);
if (_ContentDetails != null) _ContentDetails.Update(this);
if (_MyEntry != null) _MyEntry.Update(this);
if (_MyGrid != null) _MyGrid.Update(this);
if (_MyImage != null) _MyImage.Update(this);
if (_ContentParts != null) _ContentParts.Update(this);
if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
if (_ContentTransitions != null) _ContentTransitions.Update(this);
if (_MyZContent != null) _MyZContent.Update(this);
_ContentItems?.Update(this);
_ContentDetails?.Update(this);
_MyEntry?.Update(this);
_MyGrid?.Update(this);
_MyImage?.Update(this);
_ContentParts?.Update(this);
_ContentRoUsages?.Update(this);
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, ref byte[] lastChanged)
@@ -1427,8 +1297,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1443,10 +1315,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ContentID));
}
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_ContentID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
@@ -1513,16 +1382,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private readonly int _ContentID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
public bool Exists => _exists;
public ExistsCommand(int contentID) => _ContentID = contentID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode());
@@ -1552,7 +1415,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ContentExtension _ContentExtension = new ContentExtension();
readonly ContentExtension _ContentExtension = new ContentExtension();
[Serializable()]
partial class ContentExtension : extensionBase
{
@@ -1561,14 +1424,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1597,10 +1454,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Content)
if (destType == typeof(string) && value is Content content)
{
// Return the ToString value
return ((Content)value).ToString();
return content.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -1608,46 +1465,3 @@ namespace VEPROMS.CSLA.Library
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Content
// {
// partial class ContentExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshContentAudits.Add(this);
}
private void ClearRefreshList()
{
_RefreshContentAudits = new List<ContentAudit>();
}
private void ClearRefreshList() => _RefreshContentAudits = new List<ContentAudit>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -55,7 +50,8 @@ namespace VEPROMS.CSLA.Library
ClearRefreshList();
}
#endregion
#region Collection
#region
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ContentAudit> _CacheList = new List<ContentAudit>();
protected static void AddToCache(ContentAudit contentAudit)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(contentAudit)) _CacheList.Remove(contentAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ContentAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ContentAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -275,40 +266,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base ContentAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ContentAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check ContentAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentAudit</returns>
protected override object GetIdValue()
{
return MyContentAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -336,8 +301,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -365,41 +330,11 @@ namespace VEPROMS.CSLA.Library
_ContentAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Number, "<Role(s)>");
//AuthorizationRules.AllowRead(Text, "<Role(s)>");
//AuthorizationRules.AllowRead(Type, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Number, "<Role(s)>");
//AuthorizationRules.AllowWrite(Text, "<Role(s)>");
//AuthorizationRules.AllowWrite(Type, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_ContentAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -407,42 +342,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ContentAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ContentAuditUnique = 0;
protected static int ContentAuditUnique
{ get { return ++_ContentAuditUnique; } }
private int _MyContentAuditUnique = ContentAuditUnique;
public int MyContentAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyContentAuditUnique; } }
protected static int ContentAuditUnique => ++_ContentAuditUnique;
private readonly int _MyContentAuditUnique = ContentAuditUnique;
// Absolutely Unique ID - Editable
public int MyContentAuditUnique => _MyContentAuditUnique;
protected ContentAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -451,15 +358,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentAudit()
{
_CountFinalized++;
@@ -484,8 +387,6 @@ namespace VEPROMS.CSLA.Library
}
public static ContentAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ContentAudit");
try
{
return DataPortal.Create<ContentAudit>();
@@ -536,8 +437,6 @@ namespace VEPROMS.CSLA.Library
}
public static ContentAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a ContentAudit");
try
{
ContentAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -563,14 +462,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new ContentAudit(dr);
return null;
}
internal ContentAudit(SafeDataReader dr)
{
ReadData(dr);
}
internal ContentAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ContentAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -582,12 +476,6 @@ namespace VEPROMS.CSLA.Library
}
public override ContentAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ContentAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ContentAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a ContentAudit");
try
{
BuildRefreshList();
@@ -607,13 +495,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -713,34 +597,39 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addContentAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addContentAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLInsert", GetHashCode());
@@ -774,8 +663,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -820,31 +711,34 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateContentAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateContentAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -857,14 +751,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus);
else
ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus);
else
ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus);
}
MarkOld();
}
}
@@ -959,7 +856,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension();
readonly ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension();
[Serializable()]
partial class ContentAuditExtension : extensionBase
{
@@ -996,49 +893,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentAudit)
if (destType == typeof(string) && value is ContentAudit audit)
{
// Return the ToString value
return ((ContentAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ContentAudit
// {
// partial class ContentAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ContentAuditInfo : ReadOnlyBase<ContentAuditInfo>, IDisposable
{
public event ContentAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ContentAuditInfo> _CacheList = new List<ContentAuditInfo>();
protected static void AddToCache(ContentAuditInfo contentAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(contentAuditInfo)) _CacheList.Remove(contentAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ContentAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ContentAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected ContentAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -180,32 +164,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base ContentAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ContentAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ContentAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentAuditInfo</returns>
protected override object GetIdValue()
{
return MyContentAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _ContentAuditInfoUnique = 0;
private static int ContentAuditInfoUnique
{ get { return ++_ContentAuditInfoUnique; } }
private int _MyContentAuditInfoUnique = ContentAuditInfoUnique;
public int MyContentAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyContentAuditInfoUnique; } }
private static int ContentAuditInfoUnique => ++_ContentAuditInfoUnique;
private readonly int _MyContentAuditInfoUnique = ContentAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyContentAuditInfoUnique => _MyContentAuditInfoUnique;
protected ContentAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -214,15 +185,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentAuditInfo()
{
_CountFinalized++;
@@ -239,10 +206,7 @@ namespace VEPROMS.CSLA.Library
if (listContentAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual ContentAudit Get()
{
return _Editable = ContentAudit.Get(_AuditID);
}
public virtual ContentAudit Get() => _Editable = ContentAudit.Get(_AuditID);
public static void Refresh(ContentAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -307,13 +271,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -377,7 +337,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension();
readonly ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension();
[Serializable()]
partial class ContentAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -393,10 +353,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentAuditInfo)
if (destType == typeof(string) && value is ContentAuditInfo info)
{
// Return the ToString value
return ((ContentAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<ContentAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<ContentAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (ContentAuditInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentAuditInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all ContentAuditInfo.
/// </summary>
public static void Reset()
{
_ContentAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ContentAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ContentAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ContentAuditInfoList.Get", ex);
// }
//}
private ContentAuditInfoList()
/// <summary>
/// Reset the list of all ContentAuditInfo.
/// </summary>
public static void Reset() => _ContentAuditInfoList = null;
private ContentAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentAuditInfo Item { get { return (ContentAuditInfo)_Item; } }
public ContentAuditInfoListPropertyDescriptor(ContentAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentAuditInfoList)
if (destType == typeof(string) && value is ContentAuditInfoList list)
{
// Return department and department role separated by comma.
return ((ContentAuditInfoList)value).Items.Count.ToString() + " ContentAudits";
return $"{list.Items.Count} ContentAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _DetailID;
[System.ComponentModel.DataObjectField(true, true)]
public int DetailID
@@ -174,17 +168,19 @@ namespace VEPROMS.CSLA.Library
{
get { return base.IsDirty; }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping with CSLA")]
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
get { return (IsNew && !IsDirty) || base.IsValid; }
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping with CSLA")]
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
}
#endregion
#region ValidationRules
@@ -213,8 +209,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -295,7 +291,7 @@ namespace VEPROMS.CSLA.Library
private static int _ContentDetailUnique = 0;
private static int ContentDetailUnique
{ get { return ++_ContentDetailUnique; } }
private int _MyContentDetailUnique = ContentDetailUnique;
private readonly int _MyContentDetailUnique = ContentDetailUnique;
public int MyContentDetailUnique // Absolutely Unique ID - Editable FK
{ get { return _MyContentDetailUnique; } }
internal static ContentDetail New(int itemType, string text)
@@ -336,7 +332,7 @@ namespace VEPROMS.CSLA.Library
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
@@ -378,33 +374,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Detail.Update(cn, ref _DetailID, myContent.ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Detail.Update(cn, ref _DetailID, myContent.ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping with CSLA")]
internal void DeleteSelf(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Detail.Remove(cn, _DetailID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Detail.Remove(cn, _DetailID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ContentDetailExtension _ContentDetailExtension = new ContentDetailExtension();
readonly ContentDetailExtension _ContentDetailExtension = new ContentDetailExtension();
[Serializable()]
partial class ContentDetailExtension : extensionBase
{
@@ -449,10 +455,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentDetail)
if (destType == typeof(string) && value is ContentDetail detail)
{
// Return the ToString value
return ((ContentDetail)value).ToString();
return detail.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public ContentDetail this[Detail myDetail]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public ContentDetail this[Detail myDetail]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ContentDetail> Items
{
get { return base.Items; }
}
public ContentDetail GetItem(Detail myDetail)
public new System.Collections.Generic.IList<ContentDetail> Items => base.Items;
public ContentDetail GetItem(Detail myDetail)
{
foreach (ContentDetail detail in this)
if (detail.DetailID == myDetail.DetailID)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentDetail child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentDetail child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return (hasBrokenRules?.BrokenRules);
}
}
#endregion
#region Factory Methods
internal static ContentDetails New()
{
return new ContentDetails();
}
internal static ContentDetails Get(SafeDataReader dr)
{
return new ContentDetails(dr);
}
public static ContentDetails GetByContentID(int contentID)
#endregion
#region Factory Methods
internal static ContentDetails New() => new ContentDetails();
internal static ContentDetails Get(SafeDataReader dr) => new ContentDetails(dr);
public static ContentDetails GetByContentID(int contentID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentDetails.GetByContentID", ex);
}
}
private ContentDetails()
{
MarkAsChild();
}
internal ContentDetails(SafeDataReader dr)
private ContentDetails() => MarkAsChild();
internal ContentDetails(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentDetails()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentDetails()
{
_CountFinalized++;
}
@@ -206,11 +182,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -269,41 +242,30 @@ namespace VEPROMS.CSLA.Library
this.RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentDetailsPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentDetail Item { get { return (ContentDetail)_Item; } }
public ContentDetailsPropertyDescriptor(ContentDetails collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentDetails)
if (destType == typeof(string) && value is ContentDetails details)
{
// Return department and department role separated by comma.
return ((ContentDetails)value).Items.Count.ToString() + " Details";
return $"{details.Items.Count} Details";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,16 +26,13 @@ namespace VEPROMS.CSLA.Library
public partial class ContentInfo : ReadOnlyBase<ContentInfo>, IDisposable
{
public static event ContentInfoEvent InfoChanged;
private void OnInfoChanged(ContentInfo contentInfo)
{
if (InfoChanged != null)
InfoChanged(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private void OnInfoChanged(ContentInfo contentInfo) => InfoChanged?.Invoke(this);
public event ContentInfoEvent Changed;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private void OnChange(ContentInfo contentInfo)
{
if (Changed != null)
Changed(this);
Changed?.Invoke(this);
OnInfoChanged(this);
}
private void OnChange()
@@ -53,6 +48,7 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ContentInfo> _CacheList = new List<ContentInfo>();
protected static void AddToCache(ContentInfo contentInfo)
{
@@ -62,6 +58,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(contentInfo)) _CacheList.Remove(contentInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ContentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ContentInfo>>();
private static void ConvertListToDictionary()
{
@@ -104,21 +101,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Content _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -518,24 +502,12 @@ namespace VEPROMS.CSLA.Library
return _MyZContent;
}
}
// CSLATODO: Replace base ContentInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ContentInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ContentInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentInfo</returns>
protected override object GetIdValue()
{
return MyContentInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _ContentInfoUnique = 0;
@@ -549,9 +521,9 @@ namespace VEPROMS.CSLA.Library
return ui;
}
}
private int _MyContentInfoUnique = ContentInfoUnique;
public int MyContentInfoUnique // Absolutely Unique ID - Info
{ get { return _MyContentInfoUnique; } }
private readonly int _MyContentInfoUnique = ContentInfoUnique;
// Absolutely Unique ID - Info
public int MyContentInfoUnique => _MyContentInfoUnique;
protected ContentInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -560,15 +532,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentInfo()
{
_CountFinalized++;
@@ -606,25 +574,8 @@ namespace VEPROMS.CSLA.Library
if (_ContentItems != null)
_ContentItems = null;
_Text = null;
//if (_ContentParts != null)
// _ContentParts = null;
//if (_ContentRoUsages != null)
// _ContentRoUsages = null;
//if (_ContentTransitions != null)
// _ContentTransitions = null;
//if (_MyEntry != null)
// _MyEntry = null;
//if (_MyGrid != null)
// _MyGrid = null;
//if (_MyImage != null)
// _MyImage = null;
//if (_MyZContent != null)
// _MyZContent = null;
}
public virtual Content Get()
{
return _Editable = Content.Get(_ContentID);
}
public virtual Content Get() => _Editable = Content.Get(_ContentID);
public static void Refresh(Content tmp)
{
string key = tmp.ContentID.ToString();
@@ -675,11 +626,11 @@ namespace VEPROMS.CSLA.Library
_Type = tmp.Type;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatContents(); // Update List for old value
MyFormat?.RefreshFormatContents(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatContents(); // Update List for new value
MyFormat?.RefreshFormatContents(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -716,8 +667,6 @@ namespace VEPROMS.CSLA.Library
}
public static ContentInfo Get(int contentID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Content");
try
{
ContentInfo tmp = GetCachedByPrimaryKey(contentID);
@@ -756,13 +705,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
private void ReadData(SafeDataReader dr)
{
@@ -834,7 +779,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
ContentInfoExtension _ContentInfoExtension = new ContentInfoExtension();
readonly ContentInfoExtension _ContentInfoExtension = new ContentInfoExtension();
[Serializable()]
partial class ContentInfoExtension : extensionBase { }
[Serializable()]
@@ -850,10 +795,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentInfo)
if (destType == typeof(string) && value is ContentInfo info)
{
// Return the ToString value
return ((ContentInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<ContentInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<ContentInfo> Items => base.Items;
public void AddEvents()
{
foreach (ContentInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all ContentInfo.
/// </summary>
public static void Reset()
{
_ContentInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ContentInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ContentInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ContentInfoList.Get", ex);
// }
//}
public static ContentInfoList GetByFormatID(int? formatID)
/// <summary>
/// Reset the list of all ContentInfo.
/// </summary>
public static void Reset() => _ContentInfoList = null;
public static ContentInfoList GetByFormatID(int? formatID)
{
try
{
@@ -166,11 +144,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int? formatID)
{
_FormatID = formatID;
}
private int? _FormatID;
public FormatIDCriteria(int? formatID) => _FormatID = formatID;
private int? _FormatID;
public int? FormatID
{
get { return _FormatID; }
@@ -207,41 +182,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -263,7 +227,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentInfo Item { get { return (ContentInfo)_Item; } }
public ContentInfoListPropertyDescriptor(ContentInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -272,10 +235,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentInfoList)
if (destType == typeof(string) && value is ContentInfoList list)
{
// Return department and department role separated by comma.
return ((ContentInfoList)value).Items.Count.ToString() + " Contents";
return $"{list.Items.Count} Contents";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _ItemID;
[System.ComponentModel.DataObjectField(true, true)]
public int ItemID
@@ -131,10 +125,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentItem</returns>
protected override object GetIdValue()
{
return MyContentItemUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentItemUnique; // Absolutely Unique ID
// CSLATODO: Replace base ContentItem.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -144,22 +135,12 @@ namespace VEPROMS.CSLA.Library
//{
// return base.ToString();
//}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -188,8 +169,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -201,74 +182,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ContentItemUnique = 0;
private static int ContentItemUnique
{ get { return ++_ContentItemUnique; } }
private int _MyContentItemUnique = ContentItemUnique;
public int MyContentItemUnique // Absolutely Unique ID - Editable FK
{ get { return _MyContentItemUnique; } }
internal static ContentItem New()
{
return new ContentItem();
}
internal static ContentItem Get(SafeDataReader dr)
{
return new ContentItem(dr);
}
private static int ContentItemUnique => ++_ContentItemUnique;
private readonly int _MyContentItemUnique = ContentItemUnique;
// Absolutely Unique ID - Editable FK
public int MyContentItemUnique => _MyContentItemUnique;
internal static ContentItem New() => new ContentItem();
internal static ContentItem Get(SafeDataReader dr) => new ContentItem(dr);
public ContentItem()
{
MarkAsChild();
@@ -286,15 +215,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentItem()
{
_CountFinalized++;
@@ -328,33 +253,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, myContent.ContentID, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, myContent.ContentID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Item.Remove(cn, _ItemID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Item.Remove(cn, _ItemID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ContentItemExtension _ContentItemExtension = new ContentItemExtension();
readonly ContentItemExtension _ContentItemExtension = new ContentItemExtension();
[Serializable()]
partial class ContentItemExtension : extensionBase
{
@@ -363,14 +298,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -399,57 +328,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentItem)
if (destType == typeof(string) && value is ContentItem item)
{
// Return the ToString value
return ((ContentItem)value).ToString();
return item.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentItemExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ContentItem
// {
// partial class ContentItemExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public ContentItem this[Item myItem]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public ContentItem this[Item myItem]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ContentItem> Items
{
get { return base.Items; }
}
public ContentItem GetItem(Item myItem)
public new System.Collections.Generic.IList<ContentItem> Items => base.Items;
public ContentItem GetItem(Item myItem)
{
foreach (ContentItem item in this)
if (item.ItemID == myItem.ItemID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ContentItem Add() // One to Many
{
ContentItem item = ContentItem.New();
this.Add(item);
Add(item);
return item;
}
public void Remove(Item myItem)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentItem child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentItem child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static ContentItems New()
{
return new ContentItems();
}
internal static ContentItems Get(SafeDataReader dr)
{
return new ContentItems(dr);
}
public static ContentItems GetByContentID(int contentID)
#endregion
#region Factory Methods
internal static ContentItems New() => new ContentItems();
internal static ContentItems Get(SafeDataReader dr) => new ContentItems(dr);
public static ContentItems GetByContentID(int contentID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentItems.GetByContentID", ex);
}
}
private ContentItems()
{
MarkAsChild();
}
internal ContentItems(SafeDataReader dr)
private ContentItems() => MarkAsChild();
internal ContentItems(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentItems()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentItems()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(ContentItem.Get(dr));
this.RaiseListChangedEvents = true;
Add(ContentItem.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ContentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentItems.DataPortal_FetchContentID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new ContentItem(dr));
while (dr.Read()) Add(new ContentItem(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentItems.DataPortal_FetchContentID", ex);
throw new DbCslaException("ContentItems.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Content content)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ContentItemsPropertyDescriptor pd = new ContentItemsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentItemsPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentItem Item { get { return (ContentItem)_Item; } }
public ContentItemsPropertyDescriptor(ContentItems collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentItems)
if (destType == typeof(string) && value is ContentItems items)
{
// Return department and department role separated by comma.
return ((ContentItems)value).Items.Count.ToString() + " Items";
return $"{items.Items.Count} Items";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _FromType;
[System.ComponentModel.DataObjectField(true, true)]
public int FromType
@@ -155,10 +149,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentPart</returns>
protected override object GetIdValue()
{
return MyContentPartUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentPartUnique; // Absolutely Unique ID
// CSLATODO: Replace base ContentPart.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -182,18 +173,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyItem != null && _MyItem.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyItem == null || _MyItem.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -223,8 +211,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -246,74 +234,21 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FromType, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ContentPartUnique = 0;
private static int ContentPartUnique
{ get { return ++_ContentPartUnique; } }
private int _MyContentPartUnique = ContentPartUnique;
public int MyContentPartUnique // Absolutely Unique ID - Editable FK
{ get { return _MyContentPartUnique; } }
internal static ContentPart New(int fromType, Item myItem)
{
return new ContentPart(fromType, myItem);
}
internal static ContentPart Get(SafeDataReader dr)
{
return new ContentPart(dr);
}
private static int ContentPartUnique => ++_ContentPartUnique;
private readonly int _MyContentPartUnique = ContentPartUnique;
// Absolutely Unique ID - Editable FK
public int MyContentPartUnique => _MyContentPartUnique;
internal static ContentPart New(int fromType, Item myItem) => new ContentPart(fromType, myItem);
internal static ContentPart Get(SafeDataReader dr) => new ContentPart(dr);
public ContentPart()
{
MarkAsChild();
@@ -341,15 +276,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentPart()
{
_CountFinalized++;
@@ -392,33 +323,42 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Part.Update(cn, myContent.ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Part.Update(cn, myContent.ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
internal void DeleteSelf(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Part.Remove(cn, myContent.ContentID, _FromType);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Part.Remove(cn, myContent.ContentID, _FromType);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ContentPartExtension _ContentPartExtension = new ContentPartExtension();
readonly ContentPartExtension _ContentPartExtension = new ContentPartExtension();
[Serializable()]
partial class ContentPartExtension : extensionBase
{
@@ -427,14 +367,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -463,57 +397,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentPart)
if (destType == typeof(string) && value is ContentPart part)
{
// Return the ToString value
return ((ContentPart)value).ToString();
return part.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentPartExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ContentPart
// {
// partial class ContentPartExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public new ContentPart this[int fromType]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public new ContentPart this[int fromType]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ContentPart> Items
{
get { return base.Items; }
}
public ContentPart GetItem(int fromType)
public new System.Collections.Generic.IList<ContentPart> Items => base.Items;
public ContentPart GetItem(int fromType)
{
foreach (ContentPart part in this)
if (part.FromType == fromType)
@@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library
if (!Contains(fromType))
{
ContentPart part = ContentPart.New(fromType, myItem);
this.Add(part);
Add(part);
return part;
}
else
@@ -108,11 +100,8 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
@@ -142,20 +131,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static ContentParts New()
{
return new ContentParts();
}
internal static ContentParts Get(SafeDataReader dr)
{
return new ContentParts(dr);
}
public static ContentParts GetByContentID(int contentID)
#endregion
#region Factory Methods
internal static ContentParts New() => new ContentParts();
internal static ContentParts Get(SafeDataReader dr) => new ContentParts(dr);
public static ContentParts GetByContentID(int contentID)
{
try
{
@@ -166,11 +149,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentParts.GetByContentID", ex);
}
}
private ContentParts()
{
MarkAsChild();
}
internal ContentParts(SafeDataReader dr)
private ContentParts() => MarkAsChild();
internal ContentParts(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -179,16 +159,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentParts()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentParts()
{
_CountFinalized++;
}
@@ -203,19 +179,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(ContentPart.Get(dr));
this.RaiseListChangedEvents = true;
Add(ContentPart.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -224,7 +197,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ContentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentParts.DataPortal_FetchContentID", GetHashCode());
try
{
@@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new ContentPart(dr));
while (dr.Read()) Add(new ContentPart(dr));
}
}
}
@@ -248,11 +221,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentParts.DataPortal_FetchContentID", ex);
throw new DbCslaException("ContentParts.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Content content)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -271,49 +244,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ContentPartsPropertyDescriptor pd = new ContentPartsPropertyDescriptor(this, i);
@@ -330,7 +292,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentPartsPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentPart Item { get { return (ContentPart)_Item; } }
public ContentPartsPropertyDescriptor(ContentParts collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -339,10 +300,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentParts)
if (destType == typeof(string) && value is ContentParts parts)
{
// Return department and department role separated by comma.
return ((ContentParts)value).Items.Count.ToString() + " Parts";
return $"{parts.Items.Count} Parts";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _ROUsageID;
[System.ComponentModel.DataObjectField(true, true)]
public int ROUsageID
@@ -232,19 +226,8 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentRoUsage</returns>
protected override object GetIdValue()
{
return MyContentRoUsageUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ContentRoUsage.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ContentRoUsage</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyContentRoUsageUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -259,18 +242,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyRODb != null && _MyRODb.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyRODb == null || _MyRODb.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -300,8 +280,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -331,78 +311,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ROUsageID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(RODbID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RODbID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ContentRoUsageUnique = 0;
private static int ContentRoUsageUnique
{ get { return ++_ContentRoUsageUnique; } }
private int _MyContentRoUsageUnique = ContentRoUsageUnique;
public int MyContentRoUsageUnique // Absolutely Unique ID - Editable FK
{ get { return _MyContentRoUsageUnique; } }
internal static ContentRoUsage New(string roid, RODb myRODb)
{
return new ContentRoUsage(roid, myRODb);
}
internal static ContentRoUsage Get(SafeDataReader dr)
{
return new ContentRoUsage(dr);
}
private static int ContentRoUsageUnique => ++_ContentRoUsageUnique;
private readonly int _MyContentRoUsageUnique = ContentRoUsageUnique;
// Absolutely Unique ID - Editable FK
public int MyContentRoUsageUnique => _MyContentRoUsageUnique;
internal static ContentRoUsage New(string roid, RODb myRODb) => new ContentRoUsage(roid, myRODb);
internal static ContentRoUsage Get(SafeDataReader dr) => new ContentRoUsage(dr);
public ContentRoUsage()
{
MarkAsChild();
@@ -431,15 +355,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentRoUsage()
{
_CountFinalized++;
@@ -481,33 +401,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb);
}
MarkOld();
}
internal void Update(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent.ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent.ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
RoUsage.Remove(cn, _ROUsageID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
RoUsage.Remove(cn, _ROUsageID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ContentRoUsageExtension _ContentRoUsageExtension = new ContentRoUsageExtension();
readonly ContentRoUsageExtension _ContentRoUsageExtension = new ContentRoUsageExtension();
[Serializable()]
partial class ContentRoUsageExtension : extensionBase
{
@@ -516,18 +446,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultContentID
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultContentID => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -556,61 +477,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentRoUsage)
if (destType == typeof(string) && value is ContentRoUsage usage)
{
// Return the ToString value
return ((ContentRoUsage)value).ToString();
return usage.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentRoUsageExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ContentRoUsage
// {
// partial class ContentRoUsageExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultContentID
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public ContentRoUsage this[RoUsage myRoUsage]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public ContentRoUsage this[RoUsage myRoUsage]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ContentRoUsage> Items
{
get { return base.Items; }
}
public ContentRoUsage GetItem(RoUsage myRoUsage)
public new System.Collections.Generic.IList<ContentRoUsage> Items => base.Items;
public ContentRoUsage GetItem(RoUsage myRoUsage)
{
foreach (ContentRoUsage roUsage in this)
if (roUsage.ROUsageID == myRoUsage.ROUsageID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ContentRoUsage Add(string roid, RODb myRODb) // One to Many
{
ContentRoUsage roUsage = ContentRoUsage.New(roid, myRODb);
this.Add(roUsage);
Add(roUsage);
return roUsage;
}
public void Remove(RoUsage myRoUsage)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentRoUsage child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentRoUsage child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static ContentRoUsages New()
{
return new ContentRoUsages();
}
internal static ContentRoUsages Get(SafeDataReader dr)
{
return new ContentRoUsages(dr);
}
public static ContentRoUsages GetByContentID(int contentID)
#endregion
#region Factory Methods
internal static ContentRoUsages New() => new ContentRoUsages();
internal static ContentRoUsages Get(SafeDataReader dr) => new ContentRoUsages(dr);
public static ContentRoUsages GetByContentID(int contentID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentRoUsages.GetByContentID", ex);
}
}
private ContentRoUsages()
{
MarkAsChild();
}
internal ContentRoUsages(SafeDataReader dr)
private ContentRoUsages() => MarkAsChild();
internal ContentRoUsages(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentRoUsages()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentRoUsages()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(ContentRoUsage.Get(dr));
this.RaiseListChangedEvents = true;
Add(ContentRoUsage.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ContentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentRoUsages.DataPortal_FetchContentID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new ContentRoUsage(dr));
while (dr.Read()) Add(new ContentRoUsage(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentRoUsages.DataPortal_FetchContentID", ex);
throw new DbCslaException("ContentRoUsages.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Content content)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ContentRoUsagesPropertyDescriptor pd = new ContentRoUsagesPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentRoUsagesPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentRoUsage Item { get { return (ContentRoUsage)_Item; } }
public ContentRoUsagesPropertyDescriptor(ContentRoUsages collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentRoUsages)
if (destType == typeof(string) && value is ContentRoUsages usages)
{
// Return department and department role separated by comma.
return ((ContentRoUsages)value).Items.Count.ToString() + " RoUsages";
return $"{usages.Items.Count} RoUsages";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text.RegularExpressions;
@@ -32,11 +29,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _TransitionID;
[System.ComponentModel.DataObjectField(true, true)]
public int TransitionID
@@ -295,19 +289,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ContentTransition</returns>
protected override object GetIdValue()
{
return MyContentTransitionUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ContentTransition.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ContentTransition</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyContentTransitionUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -322,18 +304,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyItemToID == null ? false : _MyItemToID.IsDirtyList(list)) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyItemToID != null && _MyItemToID.IsDirtyList(list)) || (_MyItemRangeID != null && _MyItemRangeID.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValidList(list)) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyItemToID == null || _MyItemToID.IsValidList(list)) && (_MyItemRangeID == null || _MyItemRangeID.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -364,8 +343,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -400,82 +379,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(TransitionID, "<Role(s)>");
//AuthorizationRules.AllowRead(ToID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ToID, "<Role(s)>");
//AuthorizationRules.AllowRead(RangeID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RangeID, "<Role(s)>");
//AuthorizationRules.AllowRead(IsRange, "<Role(s)>");
//AuthorizationRules.AllowWrite(IsRange, "<Role(s)>");
//AuthorizationRules.AllowRead(TranType, "<Role(s)>");
//AuthorizationRules.AllowWrite(TranType, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ContentTransitionUnique = 0;
private static int ContentTransitionUnique
{ get { return ++_ContentTransitionUnique; } }
private int _MyContentTransitionUnique = ContentTransitionUnique;
public int MyContentTransitionUnique // Absolutely Unique ID - Editable FK
{ get { return _MyContentTransitionUnique; } }
internal static ContentTransition New(Item myItemToID, Item myItemRangeID)
{
return new ContentTransition(myItemToID, myItemRangeID);
}
internal static ContentTransition Get(SafeDataReader dr)
{
return new ContentTransition(dr);
}
private static int ContentTransitionUnique => ++_ContentTransitionUnique;
private readonly int _MyContentTransitionUnique = ContentTransitionUnique;
// Absolutely Unique ID - Editable FK
public int MyContentTransitionUnique => _MyContentTransitionUnique;
internal static ContentTransition New(Item myItemToID, Item myItemRangeID) => new ContentTransition(myItemToID, myItemRangeID);
internal static ContentTransition Get(SafeDataReader dr) => new ContentTransition(dr);
public ContentTransition()
{
MarkAsChild();
@@ -508,15 +427,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentTransition()
{
_CountFinalized++;
@@ -562,39 +477,49 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
string pattern = string.Format(@"<START\]\\v0([^#]*)\\v #Link:Transition(|Range):[0-9]* <CTID={0}>( [0-9]*){{1,2}}\[END>", _TransitionID);
Match m = Regex.Match(myContent.Text, pattern);
if (m.Groups.Count > 1 && m.Groups[1].Value.ToUpper().Contains("(PAGE ~)")) // B2020-089, check for upper case Page ~ in case step was upper cased
_Config = "<Config><Transition Formatted=\"True\" /></Config>";
else
_Config = string.Empty;
_LastChanged = Transition.Add(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
string pattern = string.Format(@"<START\]\\v0([^#]*)\\v #Link:Transition(|Range):[0-9]* <CTID={0}>( [0-9]*){{1,2}}\[END>", _TransitionID);
Match m = Regex.Match(myContent.Text, pattern);
if (m.Groups.Count > 1 && m.Groups[1].Value.ToUpper().Contains("(PAGE ~)")) // B2020-089, check for upper case Page ~ in case step was upper cased
_Config = "<Config><Transition Formatted=\"True\" /></Config>";
else
_Config = string.Empty;
_LastChanged = Transition.Add(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Transition.Update(cn, ref _TransitionID, myContent.ContentID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Transition.Update(cn, ref _TransitionID, myContent.ContentID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Content myContent)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Transition.Remove(cn, _TransitionID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Transition.Remove(cn, _TransitionID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ContentTransitionExtension _ContentTransitionExtension = new ContentTransitionExtension();
readonly ContentTransitionExtension _ContentTransitionExtension = new ContentTransitionExtension();
[Serializable()]
partial class ContentTransitionExtension : extensionBase
{
@@ -603,22 +528,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultIsRange
{
get { return 0; }
}
public virtual int DefaultTranType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultIsRange => 0;
public virtual int DefaultTranType => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -647,65 +560,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentTransition)
if (destType == typeof(string) && value is ContentTransition transition)
{
// Return the ToString value
return ((ContentTransition)value).ToString();
return transition.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentTransitionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ContentTransition
// {
// partial class ContentTransitionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultIsRange
// {
// get { return 0; }
// }
// public virtual int DefaultTranType
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public ContentTransition this[Transition myTransition]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public ContentTransition this[Transition myTransition]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ContentTransition> Items
{
get { return base.Items; }
}
public ContentTransition GetItem(Transition myTransition)
public new System.Collections.Generic.IList<ContentTransition> Items => base.Items;
public ContentTransition GetItem(Transition myTransition)
{
foreach (ContentTransition transition in this)
if (transition.TransitionID == myTransition.TransitionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ContentTransition Add(Item myItemToID, Item myItemRangeID) // One to Many
{
ContentTransition transition = ContentTransition.New(myItemToID, myItemRangeID);
this.Add(transition);
Add(transition);
return transition;
}
public void Remove(Transition myTransition)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentTransition child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ContentTransition child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static ContentTransitions New()
{
return new ContentTransitions();
}
internal static ContentTransitions Get(SafeDataReader dr)
{
return new ContentTransitions(dr);
}
public static ContentTransitions GetByFromID(int fromID)
#endregion
#region Factory Methods
internal static ContentTransitions New() => new ContentTransitions();
internal static ContentTransitions Get(SafeDataReader dr) => new ContentTransitions(dr);
public static ContentTransitions GetByFromID(int fromID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ContentTransitions.GetByFromID", ex);
}
}
private ContentTransitions()
{
MarkAsChild();
}
internal ContentTransitions(SafeDataReader dr)
private ContentTransitions() => MarkAsChild();
internal ContentTransitions(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ContentTransitions()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ContentTransitions()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(ContentTransition.Get(dr));
this.RaiseListChangedEvents = true;
Add(ContentTransition.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FromIDCriteria
{
public FromIDCriteria(int fromID)
{
_FromID = fromID;
}
private int _FromID;
public FromIDCriteria(int fromID) => _FromID = fromID;
private int _FromID;
public int FromID
{
get { return _FromID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FromIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentTransitions.DataPortal_FetchFromID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new ContentTransition(dr));
while (dr.Read()) Add(new ContentTransition(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentTransitions.DataPortal_FetchFromID", ex);
throw new DbCslaException("ContentTransitions.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Content content)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ContentTransitionsPropertyDescriptor pd = new ContentTransitionsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ContentTransitionsPropertyDescriptor : vlnListPropertyDescriptor
{
private ContentTransition Item { get { return (ContentTransition)_Item; } }
public ContentTransitionsPropertyDescriptor(ContentTransitions collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ContentTransitions)
if (destType == typeof(string) && value is ContentTransitions transitions)
{
// Return department and department role separated by comma.
return ((ContentTransitions)value).Items.Count.ToString() + " Transitions";
return $"{transitions.Items.Count} Transitions";
}
return base.ConvertTo(context, culture, value, destType);
}