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