From a69a2270a6dfc0c3d1491a330607950010557031 Mon Sep 17 00:00:00 2001 From: mschill Date: Tue, 8 Sep 2026 08:55:36 -0400 Subject: [PATCH] CLSA - Ds --- .../Generated/DROUsage.cs | 376 +++++----------- .../Generated/DROUsageInfo.cs | 100 ++--- .../Generated/DROUsageInfoList.cs | 153 +++---- .../Generated/Database.cs | 362 +++++++-------- .../VEPROMS.CSLA.Library/Generated/Detail.cs | 368 +++++---------- .../Generated/DetailInfo.cs | 88 +--- .../Generated/DetailInfoList.cs | 124 ++--- .../Generated/DocVersion.cs | 418 ++++++----------- .../Generated/DocVersionAssociation.cs | 213 ++------- .../Generated/DocVersionAssociations.cs | 176 +++----- .../Generated/DocVersionInfo.cs | 120 ++--- .../Generated/DocVersionInfoList.cs | 153 +++---- .../Generated/Document.cs | 422 ++++++------------ .../Generated/DocumentAudit.cs | 336 ++++---------- .../Generated/DocumentAuditInfo.cs | 84 +--- .../Generated/DocumentAuditInfoList.cs | 116 ++--- .../Generated/DocumentDROUsage.cs | 215 ++------- .../Generated/DocumentDROUsages.cs | 181 +++----- .../Generated/DocumentEntries.cs | 181 +++----- .../Generated/DocumentEntry.cs | 220 ++------- .../Generated/DocumentInfo.cs | 84 +--- .../Generated/DocumentInfoList.cs | 126 ++---- .../Generated/DocumentPdf.cs | 226 ++-------- .../Generated/DocumentPdfs.cs | 181 +++----- 24 files changed, 1609 insertions(+), 3414 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs index 37121afd..d709daaa 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -58,6 +56,7 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DROUsage dROUsage) { @@ -67,6 +66,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(dROUsage)) _CacheList.Remove(dROUsage); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -92,15 +92,9 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; private static int _nextDROUsageID = -1; - public static int NextDROUsageID - { - get { return _nextDROUsageID--; } - } + public static int NextDROUsageID => _nextDROUsageID--; private int _DROUsageID; [System.ComponentModel.DataObjectField(true, true)] public int DROUsageID @@ -261,7 +255,7 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); + return base.IsDirty || (_MyDocument != null && _MyDocument.IsDirtyList(list)) || (_MyRODb != null && _MyRODb.IsDirtyList(list)); } public override bool IsValid { @@ -270,28 +264,16 @@ namespace VEPROMS.CSLA.Library public bool IsValidList(List list) { if (list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; + return (IsNew && !IsDirty) || base.IsValid; list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocument == null || _MyDocument.IsValidList(list)) && (_MyRODb == null || _MyRODb.IsValidList(list)); } - // CSLATODO: Replace base DROUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DROUsage - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DROUsage.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DROUsage - protected override object GetIdValue() - { - return MyDROUsageUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDROUsageUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -321,8 +303,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules?.BrokenRules); } } protected override void AddBusinessRules() @@ -369,35 +351,11 @@ namespace VEPROMS.CSLA.Library } return true; } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DROUsageID, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); _DROUsageExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -405,42 +363,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _DROUsageExtension.AddInstanceAuthorizationRules(AuthorizationRules); } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DROUsageUnique = 0; - protected static int DROUsageUnique - { get { return ++_DROUsageUnique; } } - private int _MyDROUsageUnique = DROUsageUnique; - public int MyDROUsageUnique // Absolutely Unique ID - Editable - { get { return _MyDROUsageUnique; } } + protected static int DROUsageUnique => ++_DROUsageUnique; + private readonly int _MyDROUsageUnique = DROUsageUnique; + // Absolutely Unique ID - Editable + public int MyDROUsageUnique => _MyDROUsageUnique; protected DROUsage() {/* require use of factory methods */ AddToCache(this); @@ -449,15 +379,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DROUsage() { _CountFinalized++; @@ -482,8 +408,6 @@ namespace VEPROMS.CSLA.Library } public static DROUsage New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DROUsage"); try { return DataPortal.Create(); @@ -554,8 +478,6 @@ namespace VEPROMS.CSLA.Library } public static DROUsage Get(int dROUsageID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a DROUsage"); try { DROUsage tmp = GetCachedByPrimaryKey(dROUsageID); @@ -581,14 +503,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new DROUsage(dr); return null; } - internal DROUsage(SafeDataReader dr) - { - ReadData(dr); - } + internal DROUsage(SafeDataReader dr) => ReadData(dr); public static void Delete(int dROUsageID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DROUsage"); try { DataPortal.Delete(new PKCriteria(dROUsageID)); @@ -600,12 +517,6 @@ namespace VEPROMS.CSLA.Library } public override DROUsage Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DROUsage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DROUsage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a DROUsage"); try { BuildRefreshList(); @@ -625,13 +536,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _DROUsageID; - public int DROUsageID - { get { return _DROUsageID; } } - public PKCriteria(int dROUsageID) - { - _DROUsageID = dROUsageID; - } + private readonly int _DROUsageID; + public int DROUsageID => _DROUsageID; + public PKCriteria(int dROUsageID) => _DROUsageID = dROUsageID; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -731,37 +638,44 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - if (_MyDocument != null) _MyDocument.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + _MyDocument?.Update(); + _MyRODb?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addDROUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DocID", DocID); - cm.Parameters.AddWithValue("@ROID", _ROID); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - // Output Calculated Columns - SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int); - param_DROUsageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DROUsageID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _DROUsageID = (int)cm.Parameters["@newDROUsageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addDROUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", DocID); + cm.Parameters.AddWithValue("@ROID", _ROID); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + // Output Calculated Columns + SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_DROUsageID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _DROUsageID = (int)cm.Parameters["@newDROUsageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.SQLInsert", GetHashCode()); @@ -792,11 +706,15 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); // Output Calculated Columns - SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int); - param_DROUsageID.Direction = ParameterDirection.Output; + SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_DROUsageID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -841,35 +759,40 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.SQLUpdate", GetHashCode()); try { - if (_MyDocument != null) _MyDocument.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + _MyDocument?.Update(); + _MyRODb?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - using (SqlCommand cm = cn.CreateCommand()) + if (base.IsDirty) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDROUsage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@DROUsageID", _DROUsageID); - cm.Parameters.AddWithValue("@DocID", DocID); - cm.Parameters.AddWithValue("@ROID", _ROID); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - cm.Parameters.AddWithValue("@RODbID", RODbID); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDROUsage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@DROUsageID", _DROUsageID); + cm.Parameters.AddWithValue("@DocID", DocID); + cm.Parameters.AddWithValue("@ROID", _ROID); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + cm.Parameters.AddWithValue("@RODbID", RODbID); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } } + MarkOld(); // use the open connection to update child objects } @@ -882,14 +805,17 @@ namespace VEPROMS.CSLA.Library } internal void Update() { - if (!this.IsDirty) return; + if (!IsDirty) return; if (base.IsDirty) { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = DROUsage.Add(cn, ref _DROUsageID, _MyDocument, _ROID, _Config, _DTS, _UserID, _MyRODb); - else - _LastChanged = DROUsage.Update(cn, ref _DROUsageID, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = DROUsage.Add(cn, ref _DROUsageID, _MyDocument, _ROID, _Config, _DTS, _UserID, _MyRODb); + else + _LastChanged = DROUsage.Update(cn, ref _DROUsageID, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); + } + MarkOld(); } } @@ -914,8 +840,10 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@LastChanged", lastChanged); cm.Parameters.AddWithValue("@RODbID", rODbID); // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -930,10 +858,7 @@ namespace VEPROMS.CSLA.Library } } [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_DROUsageID)); - } + protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_DROUsageID)); [Transactional(TransactionalTypes.TransactionScope)] private void DataPortal_Delete(PKCriteria criteria) { @@ -1000,16 +925,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _DROUsageID; + private readonly int _DROUsageID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int dROUsageID) - { - _DROUsageID = dROUsageID; - } + public bool Exists => _exists; + public ExistsCommand(int dROUsageID) => _DROUsageID = dROUsageID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Execute", GetHashCode()); @@ -1039,7 +958,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - DROUsageExtension _DROUsageExtension = new DROUsageExtension(); + readonly DROUsageExtension _DROUsageExtension = new DROUsageExtension(); [Serializable()] partial class DROUsageExtension : extensionBase { @@ -1048,18 +967,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual int DefaultDocID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual int DefaultDocID => 0; + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -1088,61 +998,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DROUsage) + if (destType == typeof(string) && value is DROUsage usage) { // Return the ToString value - return ((DROUsage)value).ToString(); + return usage.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DROUsageExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DROUsage -// { -// partial class DROUsageExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual int DefaultDocID -// { -// 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs index db731e11..e352cf6e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library public partial class DROUsageInfo : ReadOnlyBase, IDisposable { public event DROUsageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } + private void OnChange() => Changed?.Invoke(this); #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DROUsageInfo dROUsageInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(dROUsageInfo)) _CacheList.Remove(dROUsageInfo); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; protected DROUsage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _DROUsageID; [System.ComponentModel.DataObjectField(true, true)] public int DROUsageID @@ -175,32 +159,19 @@ namespace VEPROMS.CSLA.Library return _MyRODb; } } - // CSLATODO: Replace base DROUsageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DROUsageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DROUsageInfo.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DROUsageInfo - protected override object GetIdValue() - { - return MyDROUsageInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDROUsageInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _DROUsageInfoUnique = 0; - private static int DROUsageInfoUnique - { get { return ++_DROUsageInfoUnique; } } - private int _MyDROUsageInfoUnique = DROUsageInfoUnique; - public int MyDROUsageInfoUnique // Absolutely Unique ID - Info - { get { return _MyDROUsageInfoUnique; } } + private static int DROUsageInfoUnique => ++_DROUsageInfoUnique; + private readonly int _MyDROUsageInfoUnique = DROUsageInfoUnique; + // Absolutely Unique ID - Info + public int MyDROUsageInfoUnique => _MyDROUsageInfoUnique; protected DROUsageInfo() {/* require use of factory methods */ AddToCache(this); @@ -209,15 +180,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DROUsageInfo() { _CountFinalized++; @@ -234,10 +201,7 @@ namespace VEPROMS.CSLA.Library if (listDROUsageInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(DROUsageID.ToString()); // remove the list } - public virtual DROUsage Get() - { - return _Editable = DROUsage.Get(_DROUsageID); - } + public virtual DROUsage Get() => _Editable = DROUsage.Get(_DROUsageID); public static void Refresh(DROUsage tmp) { string key = tmp.DROUsageID.ToString(); @@ -250,22 +214,22 @@ namespace VEPROMS.CSLA.Library { if (_DocID != tmp.DocID) { - if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for old value + MyDocument?.RefreshDocumentDROUsages(); // Update List for old value _DocID = tmp.DocID; // Update the value } _MyDocument = null; // Reset list so that the next line gets a new list - if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for new value + MyDocument?.RefreshDocumentDROUsages(); // Update List for new value _ROID = tmp.ROID; _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; if (_RODbID != tmp.RODbID) { - if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for old value + MyRODb?.RefreshRODbDROUsages(); // Update List for old value _RODbID = tmp.RODbID; // Update the value } _MyRODb = null; // Reset list so that the next line gets a new list - if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for new value + MyRODb?.RefreshRODbDROUsages(); // Update List for new value _DROUsageInfoExtension.Refresh(this); OnChange();// raise an event } @@ -285,11 +249,11 @@ namespace VEPROMS.CSLA.Library _UserID = tmp.UserID; if (_RODbID != tmp.RODbID) { - if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for old value + MyRODb?.RefreshRODbDROUsages(); // Update List for old value _RODbID = tmp.RODbID; // Update the value } _MyRODb = null; // Reset list so that the next line gets a new list - if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for new value + MyRODb?.RefreshRODbDROUsages(); // Update List for new value _DROUsageInfoExtension.Refresh(this); OnChange();// raise an event } @@ -305,11 +269,11 @@ namespace VEPROMS.CSLA.Library { if (_DocID != tmp.DocID) { - if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for old value + MyDocument?.RefreshDocumentDROUsages(); // Update List for old value _DocID = tmp.DocID; // Update the value } _MyDocument = null; // Reset list so that the next line gets a new list - if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for new value + MyDocument?.RefreshDocumentDROUsages(); // Update List for new value _ROID = tmp.ROID; _Config = tmp.Config; _DTS = tmp.DTS; @@ -319,8 +283,6 @@ namespace VEPROMS.CSLA.Library } public static DROUsageInfo Get(int dROUsageID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a DROUsage"); try { DROUsageInfo tmp = GetCachedByPrimaryKey(dROUsageID); @@ -359,13 +321,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _DROUsageID; - public int DROUsageID - { get { return _DROUsageID; } } - public PKCriteria(int dROUsageID) - { - _DROUsageID = dROUsageID; - } + private readonly int _DROUsageID; + public int DROUsageID => _DROUsageID; + public PKCriteria(int dROUsageID) => _DROUsageID = dROUsageID; } private void ReadData(SafeDataReader dr) { @@ -426,7 +384,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - DROUsageInfoExtension _DROUsageInfoExtension = new DROUsageInfoExtension(); + readonly DROUsageInfoExtension _DROUsageInfoExtension = new DROUsageInfoExtension(); [Serializable()] partial class DROUsageInfoExtension : extensionBase { } [Serializable()] @@ -442,10 +400,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DROUsageInfo) + if (destType == typeof(string) && value is DROUsageInfo info) { // Return the ToString value - return ((DROUsageInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfoList.cs index 9b844706..8ba44d7b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfoList.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library { #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() + #endregion + #region Business Methods + internal new IList Items => base.Items; + public void AddEvents() { foreach (DROUsageInfo tmp in this) { @@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library for (int i = 0; i < Count; i++) { if (base[i] == sender) - this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); } } private bool _Disposed = false; private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DROUsageInfoList() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DROUsageInfoList() { _CountFinalized++; } @@ -97,26 +90,12 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DROUsageInfoList.Get", ex); } } - /// - /// Reset the list of all DROUsageInfo. - /// - public static void Reset() - { - _DROUsageInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static DROUsageInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on DROUsageInfoList.Get", ex); - // } - //} - public static DROUsageInfoList GetByDocID(int docID) + /// + /// Reset the list of all DROUsageInfo. + /// + public static void Reset() => _DROUsageInfoList = null; + + public static DROUsageInfoList GetByDocID(int docID) { try { @@ -150,7 +129,7 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal private void DataPortal_Fetch() { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfoList.DataPortal_Fetch", GetHashCode()); try { @@ -164,7 +143,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DROUsageInfo(dr)); + while (dr.Read()) Add(new DROUsageInfo(dr)); IsReadOnly = true; } } @@ -175,16 +154,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfoList.DataPortal_Fetch", ex); throw new DbCslaException("DROUsageInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } [Serializable()] private class DocIDCriteria { - public DocIDCriteria(int docID) - { - _DocID = docID; - } - private int _DocID; + public DocIDCriteria(int docID) => _DocID = docID; + private int _DocID; public int DocID { get { return _DocID; } @@ -193,7 +169,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(DocIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfoList.DataPortal_FetchDocID", GetHashCode()); try { @@ -208,7 +184,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DROUsageInfo(dr)); + while (dr.Read()) Add(new DROUsageInfo(dr)); IsReadOnly = true; } } @@ -219,16 +195,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfoList.DataPortal_FetchDocID", ex); throw new DbCslaException("DROUsageInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } [Serializable()] private class RODbIDCriteria { - public RODbIDCriteria(int rODbID) - { - _RODbID = rODbID; - } - private int _RODbID; + public RODbIDCriteria(int rODbID) => _RODbID = rODbID; + private int _RODbID; public int RODbID { get { return _RODbID; } @@ -237,7 +210,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfoList.DataPortal_FetchRODbID", GetHashCode()); try { @@ -252,7 +225,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DROUsageInfo(dr)); + while (dr.Read()) Add(new DROUsageInfo(dr)); IsReadOnly = true; } } @@ -263,48 +236,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfoList.DataPortal_FetchRODbID", ex); throw new DbCslaException("DROUsageInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public string GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public string GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DROUsageInfoListPropertyDescriptor pd = new DROUsageInfoListPropertyDescriptor(this, i); @@ -321,7 +283,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DROUsageInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private DROUsageInfo Item { get { return (DROUsageInfo)_Item; } } public DROUsageInfoListPropertyDescriptor(DROUsageInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -330,10 +291,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DROUsageInfoList) + if (destType == typeof(string) && value is DROUsageInfoList list) { // Return department and department role separated by comma. - return ((DROUsageInfoList)value).Items.Count.ToString() + " DROUsages"; + return $"{list.Items.Count} DROUsages"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs index 7cc80a48..5d034c41 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs @@ -15,7 +15,6 @@ using Csla; using Csla.Data; using System.Configuration; using System.IO; -using System.ComponentModel; using System.Diagnostics; using System.Collections.Generic; using System.Text.RegularExpressions; @@ -35,79 +34,76 @@ namespace VEPROMS.CSLA.Library private static string _DBServer = null; private static DateTime _RevDate=DateTime.MinValue; -public static DateTime RevDate -{ - get { return Database._RevDate; } - set { Database._RevDate = value; } -} + public static DateTime RevDate + { + get { return _RevDate; } + set { _RevDate = value; } + } private static string _RevDescription= "Unknown"; -public static string RevDescription -{ - get { return Database._RevDescription; } - set { Database._RevDescription = value; } -} -public static string DBServer -{ - get - { - if (_DBServer == null) + public static string RevDescription { - string cnstr = null; - try + get { return _RevDescription; } + set { _RevDescription = value; } + } + public static string DBServer + { + get { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + if (_DBServer == null) { - cnstr = cn.ConnectionString; + string cnstr = null; try { - using (SqlCommand cmd = new SqlCommand("vesp_GetSQLCodeRevision", cn)) + using (SqlConnection cn = VEPROMS_SqlConnection) { - cmd.CommandType = CommandType.StoredProcedure; - cmd.CommandTimeout = 0; - SqlDataReader dr = cmd.ExecuteReader(); - while (dr.Read()) + cnstr = cn.ConnectionString; + try { - _RevDate = dr.GetDateTime(0); - _RevDescription = dr.GetString(1); + using (SqlCommand cmd = new SqlCommand("vesp_GetSQLCodeRevision", cn)) + { + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandTimeout = 0; + SqlDataReader dr = cmd.ExecuteReader(); + while (dr.Read()) + { + _RevDate = dr.GetDateTime(0); + _RevDescription = dr.GetString(1); + } + } } + catch (Exception) + { + _RevDate = DateTime.MinValue; + _RevDescription = "Unknown"; + } + string server = ""; + string db = ""; + Match m = Regex.Match(cnstr, "Data Source=([^;]+)(;[^;]+)*;*Initial Catalog=([^;]+)(;[^;]+)*"); + if (m.Success && m.Groups.Count > 4) + { + server = m.Groups[1].Value; + db = m.Groups[3].Value; + } + _DBServer = string.Format("{0} - {1} [SQL:{2:yyMM.ddHH}]", server, db, RevDate); } } - catch (Exception ex) + catch (Exception) { - _RevDate = DateTime.MinValue; - _RevDescription = "Unknown"; + _DBServer = cnstr; } - string server = ""; - string db = ""; - Match m = Regex.Match(cnstr, "Data Source=([^;]+)(;[^;]+)*;*Initial Catalog=([^;]+)(;[^;]+)*"); - if (m.Success && m.Groups.Count > 4) - { - server = m.Groups[1].Value; - db = m.Groups[3].Value; - } - _DBServer = string.Format("{0} - {1} [SQL:{2:yyMM.ddHH}]", server, db, RevDate); } - } - catch (Exception) - { - _DBServer = cnstr; + return _DBServer; } } - return _DBServer; - } -} private static int _DefaultTimeout = 600; // 600 seconds, i.e. 10 minutes public static int DefaultTimeout { get { return _DefaultTimeout; } set { _DefaultTimeout = value; } } - public static int SQLTimeout - { - get { return _DefaultTimeout/20; } - } - public static void LogException(string s, Exception ex) + public static int SQLTimeout => _DefaultTimeout / 20; + public static void LogException(string s, Exception ex) { int i = 0; Console.WriteLine("Error - {0}", s); @@ -122,7 +118,7 @@ public static string DBServer get { return _LoggingInfo; } set { _LoggingInfo = value; } } - static System.Diagnostics.Process _CurrentProcess = System.Diagnostics.Process.GetCurrentProcess(); + static readonly System.Diagnostics.Process _CurrentProcess = Process.GetCurrentProcess(); public static void LogInfo(string s, int hashCode) { if (_LoggingInfo) @@ -136,8 +132,8 @@ public static string DBServer private static string _ConnectionName = "VEPROMS"; public static string ConnectionName { - get { return Database._ConnectionName; } - set { Database._ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ } + get { return _ConnectionName; } + set { _ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ } } private static bool _TrackDBUsage = false; public static bool TrackDBUsage @@ -145,7 +141,8 @@ public static string DBServer get { return _TrackDBUsage; } set { _TrackDBUsage = value; } } - private static Dictionary _Methods = new Dictionary(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] + private static Dictionary _Methods = new Dictionary(); public static void ShowDBTracking(string fileName) { DebugDBTrack.Open(VlnSettings.TemporaryFolder + "\\" + fileName); @@ -159,12 +156,7 @@ public static string DBServer { if (TrackDBUsage) { - string str = Volian.Base.Library.vlnStackTrace.CalledFromCSLA; - //if (str.Contains("ItemAndChildren")) - //{ - // ShowDictionary(Methods); - // Methods = new Dictionary(); - //} + string str = vlnStackTrace.CalledFromCSLA; if (!_Methods.ContainsKey(str)) _Methods.Add(str, 1); else @@ -177,7 +169,7 @@ public static string DBServer DateTime.Today.ToLongDateString(); // If DBConnection.XML exists, use the connection string from DBConnection.XML string cnOverride = System.Windows.Forms.Application.StartupPath + @"\DBConnection.XML"; - if (System.IO.File.Exists(cnOverride)) + if (File.Exists(cnOverride)) { System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); xd.Load(cnOverride); @@ -209,12 +201,8 @@ public static string DBServer } } // Otherwise get the value from the ConfigurationManager - ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName]; - if (cs == null) - { - throw new ApplicationException("Database.cs Could not find connection " + ConnectionName); - } - string constr = FixServer(cs.ConnectionString); + ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName] ?? throw new ApplicationException("Database.cs Could not find connection " + ConnectionName); + string constr = FixServer(cs.ConnectionString); if (constr.Contains("{MENU}")) { constr = ChooseDatabase(constr); @@ -240,10 +228,10 @@ public static string DBServer } private static string FixServer(string connectionString) { - string serverName = Volian.Base.Library.VlnSettings.GetServer(); + string serverName = VlnSettings.GetServer(); if (serverName != null && serverName != "") { - System.Text.RegularExpressions.Match mServer = System.Text.RegularExpressions.Regex.Match(connectionString, ".*Data Source=([^;]*).*"); + System.Text.RegularExpressions.Match mServer = Regex.Match(connectionString, ".*Data Source=([^;]*).*"); if (mServer.Success) { connectionString = connectionString.Substring(0, mServer.Groups[1].Index) + serverName + connectionString.Substring(mServer.Groups[1].Index + mServer.Groups[1].Length); @@ -254,24 +242,22 @@ public static string DBServer private static string _SelectedDatabase; public static string SelectedDatabase { - get { return Database._SelectedDatabase; } - set { Database._SelectedDatabase = value; } + get { return _SelectedDatabase; } + set { _SelectedDatabase = value; } } public static string ActiveDatabase { get { - string activeDatabase = SelectedDatabase; - if(activeDatabase == null) - activeDatabase = Regex.Replace(VEPROMS_Connection, "^.*Initial Catalog=([^;]*);.*$", "$1", RegexOptions.IgnoreCase); - return activeDatabase; + string activeDatabase = SelectedDatabase ?? Regex.Replace(VEPROMS_Connection, "^.*Initial Catalog=([^;]*);.*$", "$1", RegexOptions.IgnoreCase); + return activeDatabase; } } private static string _LastDatabase="NoDefault"; public static string LastDatabase { - get { return Database._LastDatabase; } - set { Database._LastDatabase = value; } + get { return _LastDatabase; } + set { _LastDatabase = value; } } private static string ChooseDatabase(string constr) { @@ -300,95 +286,98 @@ public static string DBServer return constr.Replace("{MENU}", _SelectedDatabase); } private static System.Windows.Forms.ContextMenuStrip BuildDatabaseMenu(string constr) - { - string tmp = constr.Replace("{MENU}", "master"); - SqlConnection cn = new SqlConnection(tmp); - cn.Open(); - // SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn); - //SqlDataAdapter da = new SqlDataAdapter("select name, case when object_id('[' + name + ']..Items') is null then 'Not PROMS' when object_id('[' + name + ']..Revisions') is not null then 'Approval' when object_id('[' + name + ']..ContentAudits') is not null then 'Change Manager' else 'Original' end functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn); - SqlDataAdapter da = new SqlDataAdapter("select name, 'Approval' functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn); - da.SelectCommand.CommandTimeout = 300; // 300 sec timeout - DataSet ds = new DataSet(); - try - { - da.Fill(ds); - } - catch (Exception ex) - { - System.Windows.Forms.MessageBox.Show(ex.GetType().Name, ex.Message); - throw(new Exception("Cannot Load Data List",ex)); - } - cn.Close(); - System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip(); - cms.Items.Add("Choose Database"); - System.Windows.Forms.ToolStripMenuItem tsmi = cms.Items[0] as System.Windows.Forms.ToolStripMenuItem; - tsmi.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaption);// System.Drawing.Color.Pink; - tsmi.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaptionText); - tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold); - foreach (DataRow dr in ds.Tables[0].Rows) - { - if (dr["functionality"].ToString() == "Approval" && !dr["name"].ToString().EndsWith("_RO")) // don't display sql ro databases in list - cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click)); - } - return cms; - } + { + string tmp = constr.Replace("{MENU}", "master"); + using (SqlConnection cn = new SqlConnection(tmp)) + { + cn.Open(); + using (SqlDataAdapter da = new SqlDataAdapter("select name, 'Approval' functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn)) + { + da.SelectCommand.CommandTimeout = 300; // 300 sec timeout + DataSet ds = new DataSet(); + try + { + da.Fill(ds); + } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show(ex.GetType().Name, ex.Message); + throw (new Exception("Cannot Load Data List", ex)); + } + cn.Close(); + System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip(); + cms.Items.Add("Choose Database"); + System.Windows.Forms.ToolStripMenuItem tsmi = cms.Items[0] as System.Windows.Forms.ToolStripMenuItem; + tsmi.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaption);// System.Drawing.Color.Pink; + tsmi.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaptionText); + tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold); + foreach (DataRow dr in ds.Tables[0].Rows) + { + if (dr["functionality"].ToString() == "Approval" && !dr["name"].ToString().EndsWith("_RO")) // don't display sql ro databases in list + cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click)); + } + return cms; + } + } + } - static void Database_Click(object sender, EventArgs e) + static void Database_Click(object sender, EventArgs e) { - System.Windows.Forms.ToolStripMenuItem tsmi = sender as System.Windows.Forms.ToolStripMenuItem; - if (tsmi != null) - { - _SelectedDatabase = tsmi.Text; - } - } + if (sender is System.Windows.Forms.ToolStripMenuItem tsmi) + { + _SelectedDatabase = tsmi.Text; + } + } public static SqlConnection VEPROMS_SqlConnection { get - { - string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch) - // Attempt to make a connection + { + string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch) + // Attempt to make a connection + + //note - cannot use using here as it will close the connection and it needs to return it as open SqlConnection cn = new SqlConnection(strConn); - try - { - cn.Open(); - return cn; - } - catch (SqlException exsql) - { - const string strAttachError = "An attempt to attach an auto-named database for file "; - if (exsql.Message.StartsWith(strAttachError)) - {// Check to see if the file is missing - string sFile = exsql.Message.Substring(strAttachError.Length); - sFile = sFile.Substring(0, sFile.IndexOf(" failed")); - // "An attempt to attach an auto-named database for file failed" - if (strConn.ToLower().IndexOf("user instance=true") < 0) - { - throw new ApplicationException("Connection String missing attribute: User Instance=True"); - } - if (System.IO.File.Exists(sFile)) - { - throw new ApplicationException("Database file " + sFile + " Cannot be opened\r\n", exsql); - } - else - { - throw new FileNotFoundException("Database file " + sFile + " Not Found", exsql); - } - } - else - { - //Open a MesageBox so the user is given some feedback that the connection has failed. - ReportInnermostException(exsql,strConn); - throw new ApplicationException("Failure on Connect", exsql); - } - } - catch (Exception ex)// Throw Application Exception on Failure - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection Error", ex); - throw new ApplicationException("Failure on Connect", ex); - } - } - } + try + { + cn.Open(); + return cn; + } + catch (SqlException exsql) + { + const string strAttachError = "An attempt to attach an auto-named database for file "; + if (exsql.Message.StartsWith(strAttachError)) + {// Check to see if the file is missing + string sFile = exsql.Message.Substring(strAttachError.Length); + sFile = sFile.Substring(0, sFile.IndexOf(" failed")); + // "An attempt to attach an auto-named database for file failed" + if (strConn.ToLower().IndexOf("user instance=true") < 0) + { + throw new ApplicationException("Connection String missing attribute: User Instance=True"); + } + if (File.Exists(sFile)) + { + throw new ApplicationException("Database file " + sFile + " Cannot be opened\r\n", exsql); + } + else + { + throw new FileNotFoundException("Database file " + sFile + " Not Found", exsql); + } + } + else + { + //Open a MesageBox so the user is given some feedback that the connection has failed. + ReportInnermostException(exsql, strConn); + throw new ApplicationException("Failure on Connect", exsql); + } + } + catch (Exception ex)// Throw Application Exception on Failure + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection Error", ex); + throw new ApplicationException("Failure on Connect", ex); + } + } + } /// /// Open a MessageBox with the exception type, the connection string and the exception message /// @@ -400,15 +389,13 @@ public static string DBServer while (ex.InnerException != null) ex = ex.InnerException; System.Windows.Forms.MessageBox.Show(string.Format("{0}\r\n\r\nConnection String ={1}", ex.Message,conn) - ,"PROMS - " + ex.GetType().FullName, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); - System.Diagnostics.Process.GetCurrentProcess().Kill(); + , $"PROMS - {ex.GetType().FullName}", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); + Process.GetCurrentProcess().Kill(); } public static void PurgeData() { try { - //SqlConnection cn = VEPROMS_SqlConnection; - //SqlCommand cmd = new SqlCommand("purgedata", cn); using (SqlConnection cn = VEPROMS_SqlConnection) { using (SqlCommand cmd = new SqlCommand("purgedata", cn)) @@ -458,8 +445,6 @@ public static string DBServer { try { - //SqlConnection cn = VEPROMS_SqlConnection; - //SqlCommand cmd = new SqlCommand("purgedata", cn); using (SqlConnection cn = Database.VEPROMS_SqlConnection) { using (SqlCommand cmd = new SqlCommand("purgedata", cn)) @@ -483,11 +468,8 @@ public static string DBServer { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private ProposedTransition _ProposedTransition; + public string ErrorMessage => _ErrorMessage; + private ProposedTransition _ProposedTransition; public ProposedTransition ProposedTransition { get { return _ProposedTransition; } @@ -508,10 +490,12 @@ public static string DBServer #region Factory Methods public static ProposedTransition Execute(int fromID, int toID) { - CanTransitionBeCreatedCommand cmd = new CanTransitionBeCreatedCommand(); - cmd.FromID = fromID; - cmd.ToID = toID; - cmd = DataPortal.Execute(cmd); + CanTransitionBeCreatedCommand cmd = new CanTransitionBeCreatedCommand + { + FromID = fromID, + ToID = toID + }; + cmd = DataPortal.Execute(cmd); return cmd.ProposedTransition; } private CanTransitionBeCreatedCommand() @@ -536,8 +520,6 @@ public static string DBServer { try { - //SqlConnection cn = VEPROMS_SqlConnection; - //SqlCommand cmd = new SqlCommand("purgedata", cn); using (SqlConnection cn = Database.VEPROMS_SqlConnection) { using (SqlCommand cmd = new SqlCommand("vesp_CanTransitionBeCreated", cn)) @@ -571,16 +553,10 @@ public static string DBServer { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private List _InvalidTransitions; - public List InvalidTransitions - { - get { return _InvalidTransitions; } - } - private int _ItemID; + public string ErrorMessage => _ErrorMessage; + private List _InvalidTransitions; + public List InvalidTransitions => _InvalidTransitions; + private int _ItemID; public int ItemID { get { return _ItemID; } @@ -595,10 +571,12 @@ public static string DBServer #region Factory Methods public static List Execute(int itemID, string newAppl) { - WillTransitionsBeValidCommand cmd = new WillTransitionsBeValidCommand(); - cmd.ItemID = itemID; - cmd.NewAppl = newAppl; - cmd = DataPortal.Execute(cmd); + WillTransitionsBeValidCommand cmd = new WillTransitionsBeValidCommand + { + ItemID = itemID, + NewAppl = newAppl + }; + cmd = DataPortal.Execute(cmd); return cmd.InvalidTransitions; } private WillTransitionsBeValidCommand() @@ -626,8 +604,6 @@ public static string DBServer { try { - //SqlConnection cn = VEPROMS_SqlConnection; - //SqlCommand cmd = new SqlCommand("purgedata", cn); using (SqlConnection cn = Database.VEPROMS_SqlConnection) { using (SqlCommand cmd = new SqlCommand("vesp_WillTransitionsBeValid", cn)) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs index dd3bd91b..b557f7f3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library if (IsDirty) refreshDetails.Add(this); } - private void ClearRefreshList() - { - _RefreshDetails = new List(); - } + private void ClearRefreshList() => _RefreshDetails = new List(); private void BuildRefreshList() { ClearRefreshList(); @@ -57,6 +52,7 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(Detail detail) { @@ -66,6 +62,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -91,15 +88,9 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; private static int _nextDetailID = -1; - public static int NextDetailID - { - get { return _nextDetailID--; } - } + public static int NextDetailID => _nextDetailID--; private int _DetailID; [System.ComponentModel.DataObjectField(true, true)] public int DetailID @@ -248,37 +239,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyContent != null && _MyContent.IsDirtyList(list)); } + public override bool IsValid => IsValidList(new List()); public bool IsValidList(List list) { if (list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; + return (IsNew && !IsDirty) || base.IsValid; list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyContent == null || _MyContent.IsValidList(list)); } - // CSLATODO: Replace base Detail.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Detail - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check Detail.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current Detail - protected override object GetIdValue() - { - return MyDetailUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDetailUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -307,8 +283,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -345,35 +321,11 @@ namespace VEPROMS.CSLA.Library } return true; } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DetailID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(ItemType, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(ItemType, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); _DetailExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -381,42 +333,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _DetailExtension.AddInstanceAuthorizationRules(AuthorizationRules); } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DetailUnique = 0; - protected static int DetailUnique - { get { return ++_DetailUnique; } } - private int _MyDetailUnique = DetailUnique; - public int MyDetailUnique // Absolutely Unique ID - Editable - { get { return _MyDetailUnique; } } + protected static int DetailUnique => ++_DetailUnique; + private readonly int _MyDetailUnique = DetailUnique; + // Absolutely Unique ID - Editable + public int MyDetailUnique => _MyDetailUnique; protected Detail() {/* require use of factory methods */ AddToCache(this); @@ -425,15 +349,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~Detail() { _CountFinalized++; @@ -458,8 +378,6 @@ namespace VEPROMS.CSLA.Library } public static Detail New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Detail"); try { return DataPortal.Create(); @@ -531,8 +449,6 @@ namespace VEPROMS.CSLA.Library } public static Detail Get(int detailID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Detail"); try { Detail tmp = GetCachedByPrimaryKey(detailID); @@ -558,14 +474,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new Detail(dr); return null; } - internal Detail(SafeDataReader dr) - { - ReadData(dr); - } + internal Detail(SafeDataReader dr) => ReadData(dr); public static void Delete(int detailID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Detail"); try { DataPortal.Delete(new PKCriteria(detailID)); @@ -577,12 +488,6 @@ namespace VEPROMS.CSLA.Library } public override Detail Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Detail"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Detail"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Detail"); try { BuildRefreshList(); @@ -602,13 +507,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _DetailID; - public int DetailID - { get { return _DetailID; } } - public PKCriteria(int detailID) - { - _DetailID = detailID; - } + private readonly int _DetailID; + public int DetailID => _DetailID; + public PKCriteria(int detailID) => _DetailID = detailID; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -707,36 +608,43 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - if (_MyContent != null) _MyContent.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + _MyContent?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addDetail"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@ItemType", _ItemType); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int); - param_DetailID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DetailID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _DetailID = (int)cm.Parameters["@newDetailID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addDetail"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@ItemType", _ItemType); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_DetailID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _DetailID = (int)cm.Parameters["@newDetailID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.SQLInsert", GetHashCode()); @@ -767,11 +675,15 @@ namespace VEPROMS.CSLA.Library if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UserID", userID); // Output Calculated Columns - SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int); - param_DetailID.Direction = ParameterDirection.Output; + SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_DetailID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -816,34 +728,39 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.SQLUpdate", GetHashCode()); try { - if (_MyContent != null) _MyContent.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + _MyContent?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - using (SqlCommand cm = cn.CreateCommand()) + if (base.IsDirty) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDetail"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@DetailID", _DetailID); - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@ItemType", _ItemType); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDetail"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@DetailID", _DetailID); + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@ItemType", _ItemType); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } } + MarkOld(); // use the open connection to update child objects } @@ -856,14 +773,17 @@ namespace VEPROMS.CSLA.Library } internal void Update() { - if (!this.IsDirty) return; + if (!IsDirty) return; if (base.IsDirty) { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Detail.Add(cn, ref _DetailID, _MyContent, _ItemType, _Text, _Config, _DTS, _UserID); - else - _LastChanged = Detail.Update(cn, ref _DetailID, _ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = Detail.Add(cn, ref _DetailID, _MyContent, _ItemType, _Text, _Config, _DTS, _UserID); + else + _LastChanged = Detail.Update(cn, ref _DetailID, _ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } } @@ -888,8 +808,10 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@LastChanged", lastChanged); // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -974,16 +896,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _DetailID; + private readonly int _DetailID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int detailID) - { - _DetailID = detailID; - } + public bool Exists => _exists; + public ExistsCommand(int detailID) => _DetailID = detailID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Execute", GetHashCode()); @@ -1013,7 +929,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - DetailExtension _DetailExtension = new DetailExtension(); + readonly DetailExtension _DetailExtension = new DetailExtension(); [Serializable()] partial class DetailExtension : extensionBase { @@ -1022,14 +938,8 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -1058,57 +968,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is Detail) + if (destType == typeof(string) && value is Detail detail) { // Return the ToString value - return ((Detail)value).ToString(); + return detail.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DetailExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class Detail -// { -// partial class DetailExtension : 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs index a66ab7aa..cd1762d3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library public partial class DetailInfo : ReadOnlyBase, IDisposable { public event DetailInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } + private void OnChange() => Changed?.Invoke(this); #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DetailInfo detailInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; protected Detail _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _DetailID; [System.ComponentModel.DataObjectField(true, true)] public int DetailID @@ -164,32 +148,19 @@ namespace VEPROMS.CSLA.Library return _UserID; } } - // CSLATODO: Replace base DetailInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DetailInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DetailInfo.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DetailInfo - protected override object GetIdValue() - { - return MyDetailInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDetailInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _DetailInfoUnique = 0; - private static int DetailInfoUnique - { get { return ++_DetailInfoUnique; } } - private int _MyDetailInfoUnique = DetailInfoUnique; - public int MyDetailInfoUnique // Absolutely Unique ID - Info - { get { return _MyDetailInfoUnique; } } + private static int DetailInfoUnique => ++_DetailInfoUnique; + private readonly int _MyDetailInfoUnique = DetailInfoUnique; + // Absolutely Unique ID - Info + public int MyDetailInfoUnique => _MyDetailInfoUnique; protected DetailInfo() {/* require use of factory methods */ AddToCache(this); @@ -198,15 +169,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DetailInfo() { _CountFinalized++; @@ -223,10 +190,7 @@ namespace VEPROMS.CSLA.Library if (listDetailInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list } - public virtual Detail Get() - { - return _Editable = Detail.Get(_DetailID); - } + public virtual Detail Get() => _Editable = Detail.Get(_DetailID); public static void Refresh(Detail tmp) { string key = tmp.DetailID.ToString(); @@ -239,11 +203,11 @@ namespace VEPROMS.CSLA.Library { if (_ContentID != tmp.ContentID) { - if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for old value + MyContent?.RefreshContentDetails(); // Update List for old value _ContentID = tmp.ContentID; // Update the value } _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for new value + MyContent?.RefreshContentDetails(); // Update List for new value _ItemType = tmp.ItemType; _Text = tmp.Text; _Config = tmp.Config; @@ -272,8 +236,6 @@ namespace VEPROMS.CSLA.Library } public static DetailInfo Get(int detailID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Detail"); try { DetailInfo tmp = GetCachedByPrimaryKey(detailID); @@ -312,13 +274,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _DetailID; - public int DetailID - { get { return _DetailID; } } - public PKCriteria(int detailID) - { - _DetailID = detailID; - } + private readonly int _DetailID; + public int DetailID => _DetailID; + public PKCriteria(int detailID) => _DetailID = detailID; } private void ReadData(SafeDataReader dr) { @@ -379,7 +337,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension(); + readonly DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension(); [Serializable()] partial class DetailInfoExtension : extensionBase { } [Serializable()] @@ -395,10 +353,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DetailInfo) + if (destType == typeof(string) && value is DetailInfo info) { // Return the ToString value - return ((DetailInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfoList.cs index c979f723..88ae567a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfoList.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library { #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() + #endregion + #region Business Methods + internal new IList Items => base.Items; + public void AddEvents() { foreach (DetailInfo tmp in this) { @@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DetailInfoList() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DetailInfoList() { _CountFinalized++; } @@ -97,26 +90,12 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DetailInfoList.Get", ex); } } - /// - /// Reset the list of all DetailInfo. - /// - public static void Reset() - { - _DetailInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static DetailInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on DetailInfoList.Get", ex); - // } - //} - public static DetailInfoList GetByContentID(int contentID) + /// + /// Reset the list of all DetailInfo. + /// + public static void Reset() => _DetailInfoList = null; + + public static DetailInfoList GetByContentID(int contentID) { try { @@ -166,11 +145,8 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ContentIDCriteria { - public ContentIDCriteria(int contentID) - { - _ContentID = contentID; - } - private int _ContentID; + public ContentIDCriteria(int contentID) => _ContentID = contentID; + private int _ContentID; public int ContentID { get { return _ContentID; } @@ -207,41 +183,30 @@ namespace VEPROMS.CSLA.Library } this.RaiseListChangedEvents = true; } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public String GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); @@ -263,7 +228,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DetailInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private DetailInfo Item { get { return (DetailInfo)_Item; } } public DetailInfoListPropertyDescriptor(DetailInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -272,10 +236,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DetailInfoList) + if (destType == typeof(string) && value is DetailInfoList list) { // Return department and department role separated by comma. - return ((DetailInfoList)value).Items.Count.ToString() + " Details"; + return $"{list.Items.Count} Details"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs index 0b18bb3d..c9b738ab 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -72,6 +70,7 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DocVersion docVersion) { @@ -81,6 +80,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -106,15 +106,9 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; private static int _nextVersionID = -1; - public static int NextVersionID - { - get { return _nextVersionID--; } - } + public static int NextVersionID => _nextVersionID--; private int _VersionID; [System.ComponentModel.DataObjectField(true, true)] public int VersionID @@ -362,10 +356,7 @@ namespace VEPROMS.CSLA.Library return _DocVersionAssociations; } } - public void Reset_DocVersionAssociations() - { - _DocVersionAssociationCount = -1; - } + public void Reset_DocVersionAssociations() => _DocVersionAssociationCount = -1; public override bool IsDirty { get @@ -380,37 +371,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_DocVersionAssociations == null ? false : _DocVersionAssociations.IsDirtyList(list)) || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list)) || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_DocVersionAssociations != null && _DocVersionAssociations.IsDirtyList(list)) || (_MyFolder != null && _MyFolder.IsDirtyList(list)) || (_MyFormat != null && _MyFormat.IsDirtyList(list)) || (_MyItem != null && _MyItem.IsDirtyList(list)); } + public override bool IsValid => IsValidList(new List()); public bool IsValidList(List list) { if (list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; + return (IsNew && !IsDirty) || base.IsValid; list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocVersionAssociations == null ? true : _DocVersionAssociations.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list)) && (_MyItem == null ? true : _MyItem.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_DocVersionAssociations == null || _DocVersionAssociations.IsValidList(list)) && (_MyFolder == null || _MyFolder.IsValidList(list)) && (_MyFormat == null || _MyFormat.IsValidList(list)) && (_MyItem == null || _MyItem.IsValidList(list)); } - // CSLATODO: Replace base DocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DocVersion.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocVersion - protected override object GetIdValue() - { - return MyDocVersionUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocVersionUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -442,8 +418,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -483,41 +459,10 @@ namespace VEPROMS.CSLA.Library } return true; } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { - //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); _DocVersionExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -525,55 +470,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _DocVersionExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _DocVersionAssociationCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocVersionUnique = 0; - protected static int DocVersionUnique - { get { return ++_DocVersionUnique; } } - private int _MyDocVersionUnique = DocVersionUnique; - public int MyDocVersionUnique // Absolutely Unique ID - Editable - { get { return _MyDocVersionUnique; } } + protected static int DocVersionUnique => ++_DocVersionUnique; + private readonly int _MyDocVersionUnique = DocVersionUnique; + // Absolutely Unique ID - Editable + public int MyDocVersionUnique => _MyDocVersionUnique; protected DocVersion() {/* require use of factory methods */ AddToCache(this); @@ -582,15 +486,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocVersion() { _CountFinalized++; @@ -615,8 +515,6 @@ namespace VEPROMS.CSLA.Library } public static DocVersion New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocVersion"); try { return DataPortal.Create(); @@ -692,8 +590,6 @@ namespace VEPROMS.CSLA.Library } public static DocVersion Get(int versionID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a DocVersion"); try { DocVersion tmp = GetCachedByPrimaryKey(versionID); @@ -725,8 +621,6 @@ namespace VEPROMS.CSLA.Library } public static void Delete(int versionID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DocVersion"); try { DataPortal.Delete(new PKCriteria(versionID)); @@ -738,12 +632,6 @@ namespace VEPROMS.CSLA.Library } public override DocVersion Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DocVersion"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocVersion"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a DocVersion"); try { BuildRefreshList(); @@ -763,13 +651,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } + private readonly int _VersionID; + public int VersionID => _VersionID; + public PKCriteria(int versionID) => _VersionID = versionID; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -876,44 +760,51 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - if (_MyFolder != null) _MyFolder.Update(); - if (_MyFormat != null) _MyFormat.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + _MyFolder?.Update(); + _MyFormat?.Update(); + _MyItem?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addDocVersion"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FolderID", FolderID); - cm.Parameters.AddWithValue("@VersionType", _VersionType); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - cm.Parameters.AddWithValue("@ItemID", ItemID); - cm.Parameters.AddWithValue("@FormatID", FormatID); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int); - param_VersionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_VersionID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _VersionID = (int)cm.Parameters["@newVersionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addDocVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FolderID", FolderID); + cm.Parameters.AddWithValue("@VersionType", _VersionType); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + cm.Parameters.AddWithValue("@ItemID", ItemID); + cm.Parameters.AddWithValue("@FormatID", FormatID); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_VersionID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _VersionID = (int)cm.Parameters["@newVersionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects - if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); + _DocVersionAssociations?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -945,11 +836,15 @@ namespace VEPROMS.CSLA.Library if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UserID", userID); // Output Calculated Columns - SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int); - param_VersionID.Direction = ParameterDirection.Output; + SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_VersionID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -994,42 +889,47 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLUpdate", GetHashCode()); try { - if (_MyFolder != null) _MyFolder.Update(); - if (_MyFormat != null) _MyFormat.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + _MyFolder?.Update(); + _MyFormat?.Update(); + _MyItem?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - using (SqlCommand cm = cn.CreateCommand()) + if (base.IsDirty) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDocVersion"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@VersionID", _VersionID); - cm.Parameters.AddWithValue("@FolderID", FolderID); - cm.Parameters.AddWithValue("@VersionType", _VersionType); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - cm.Parameters.AddWithValue("@ItemID", ItemID); - cm.Parameters.AddWithValue("@FormatID", FormatID); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDocVersion"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@VersionID", _VersionID); + cm.Parameters.AddWithValue("@FolderID", FolderID); + cm.Parameters.AddWithValue("@VersionType", _VersionType); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + cm.Parameters.AddWithValue("@ItemID", ItemID); + cm.Parameters.AddWithValue("@FormatID", FormatID); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } } + MarkOld(); // use the open connection to update child objects - if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); + _DocVersionAssociations?.Update(this); } catch (Exception ex) { @@ -1040,17 +940,20 @@ namespace VEPROMS.CSLA.Library } internal void Update() { - if (!this.IsDirty) return; + if (!IsDirty) return; if (base.IsDirty) { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID); - else - _LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID); + else + _LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } - if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); + _DocVersionAssociations?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] public static byte[] Update(SqlConnection cn, ref int versionID, int folderID, int versionType, string name, string title, int? itemID, int? formatID, string config, DateTime dts, string userID, ref byte[] lastChanged) @@ -1076,8 +979,10 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@LastChanged", lastChanged); // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -1162,16 +1067,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _VersionID; + private readonly int _VersionID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int versionID) - { - _VersionID = versionID; - } + public bool Exists => _exists; + public ExistsCommand(int versionID) => _VersionID = versionID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Execute", GetHashCode()); @@ -1201,7 +1100,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - DocVersionExtension _DocVersionExtension = new DocVersionExtension(); + readonly DocVersionExtension _DocVersionExtension = new DocVersionExtension(); [Serializable()] partial class DocVersionExtension : extensionBase { @@ -1210,18 +1109,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual int DefaultVersionType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual int DefaultVersionType => 0; + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -1250,61 +1140,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocVersion) + if (destType == typeof(string) && value is DocVersion version) { // Return the ToString value - return ((DocVersion)value).ToString(); + return version.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocVersionExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DocVersion -// { -// partial class DocVersionExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual int DefaultVersionType -// { -// 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs index 2baf6ba5..e55fa4f5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs @@ -9,12 +9,9 @@ // ======================================================================== using System; -using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; private int _AssociationID; [System.ComponentModel.DataObjectField(true, true)] public int AssociationID @@ -145,15 +139,6 @@ namespace VEPROMS.CSLA.Library } } private byte[] _LastChanged = new byte[8];//timestamp - private int _ROFst_RODbID; - public int ROFst_RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - return _ROFst_RODbID; - } - } private byte[] _ROFst_ROLookup; public byte[] ROFst_ROLookup { @@ -163,7 +148,7 @@ namespace VEPROMS.CSLA.Library return _ROFst_ROLookup; } } - private string _ROFst_Config = string.Empty; + private readonly string _ROFst_Config = string.Empty; public string ROFst_Config { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] @@ -172,7 +157,7 @@ namespace VEPROMS.CSLA.Library return _ROFst_Config; } } - private DateTime _ROFst_DTS = new DateTime(); + private readonly DateTime _ROFst_DTS = new DateTime(); public DateTime ROFst_DTS { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] @@ -181,7 +166,7 @@ namespace VEPROMS.CSLA.Library return _ROFst_DTS; } } - private string _ROFst_UserID = string.Empty; + private readonly string _ROFst_UserID = string.Empty; public string ROFst_UserID { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] @@ -195,10 +180,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocVersionAssociation - protected override object GetIdValue() - { - return MyDocVersionAssociationUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocVersionAssociationUnique; // Absolutely Unique ID // CSLATODO: Replace base DocVersionAssociation.ToString function as necessary /// /// Overrides Base ToString @@ -222,18 +204,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyROFst != null && _MyROFst.IsDirtyList(list)); } + public override bool IsValid => IsValidList(new List()); public bool IsValidList(List list) { if (list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; + return (IsNew && !IsDirty) || base.IsValid; list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyROFst == null || _MyROFst.IsValidList(list)); } #endregion #region ValidationRules @@ -264,7 +243,7 @@ namespace VEPROMS.CSLA.Library { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -289,76 +268,21 @@ namespace VEPROMS.CSLA.Library } return true; } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { - //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AssociationID, ""); - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowWrite(ROFstID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocVersionAssociationUnique = 0; - private static int DocVersionAssociationUnique - { get { return ++_DocVersionAssociationUnique; } } - private int _MyDocVersionAssociationUnique = DocVersionAssociationUnique; - public int MyDocVersionAssociationUnique // Absolutely Unique ID - Editable FK - { get { return _MyDocVersionAssociationUnique; } } - internal static DocVersionAssociation New(ROFst myROFst) - { - return new DocVersionAssociation(myROFst); - } - internal static DocVersionAssociation Get(SafeDataReader dr) - { - return new DocVersionAssociation(dr); - } + private static int DocVersionAssociationUnique => ++_DocVersionAssociationUnique; + private readonly int _MyDocVersionAssociationUnique = DocVersionAssociationUnique; + // Absolutely Unique ID - Editable FK + public int MyDocVersionAssociationUnique => _MyDocVersionAssociationUnique; + internal static DocVersionAssociation New(ROFst myROFst) => new DocVersionAssociation(myROFst); + internal static DocVersionAssociation Get(SafeDataReader dr) => new DocVersionAssociation(dr); public DocVersionAssociation() { MarkAsChild(); @@ -386,15 +310,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocVersionAssociation() { _CountFinalized++; @@ -420,12 +340,7 @@ namespace VEPROMS.CSLA.Library dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); // B2023-020: setting RO Database on new working draft crashes. Query 'getAssociationsByVersionID' had been modified // for memory improvements to not return the ROFst values, so don't Get the values. Comment out for now. - //_ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); - //_ROFst_ROLookup = (byte[])dr.GetValue("ROFst_ROLookup"); _ROFst_ROLookup = null; // B2022-026 RO Memory reduction - use ROlookup of null to know if we loaded the RO.FST file - //_ROFst_Config = dr.GetString("ROFst_Config"); - //_ROFst_DTS = dr.GetDateTime("ROFst_DTS"); - //_ROFst_UserID = dr.GetString("ROFst_UserID"); } catch (Exception ex) // FKItem Fetch { @@ -438,32 +353,42 @@ namespace VEPROMS.CSLA.Library { // if we're not dirty then don't update the database if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Association.Add(cn, ref _AssociationID, myDocVersion, _MyROFst, _Config, _DTS, _UserID); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Association.Add(cn, ref _AssociationID, myDocVersion, _MyROFst, _Config, _DTS, _UserID); + } + MarkOld(); } internal void Update(DocVersion myDocVersion) { // if we're not dirty then don't update the database if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Association.Update(cn, ref _AssociationID, myDocVersion.VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Association.Update(cn, ref _AssociationID, myDocVersion.VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(DocVersion myDocVersion) { // if we're not dirty then don't update the database if (!this.IsDirty) return; // if we're new then don't update the database if (this.IsNew) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - Association.Remove(cn, _AssociationID); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Association.Remove(cn, _AssociationID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - DocVersionAssociationExtension _DocVersionAssociationExtension = new DocVersionAssociationExtension(); + readonly DocVersionAssociationExtension _DocVersionAssociationExtension = new DocVersionAssociationExtension(); [Serializable()] partial class DocVersionAssociationExtension : extensionBase { @@ -472,14 +397,8 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -508,57 +427,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocVersionAssociation) + if (destType == typeof(string) && value is DocVersionAssociation association) { // Return the ToString value - return ((DocVersionAssociation)value).ToString(); + return association.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocVersionAssociationExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DocVersionAssociation -// { -// partial class DocVersionAssociationExtension : 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociations.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociations.cs index ff91336b..6685bed9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociations.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociations.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - // One To Many - public DocVersionAssociation this[Association myAssociation] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public DocVersionAssociation this[Association myAssociation] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public DocVersionAssociation GetItem(Association myAssociation) + public new System.Collections.Generic.IList Items => base.Items; + public DocVersionAssociation GetItem(Association myAssociation) { foreach (DocVersionAssociation association in this) if (association.AssociationID == myAssociation.AssociationID) @@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library if (!Contains(myROFst)) { DocVersionAssociation association = DocVersionAssociation.New(myROFst); - this.Add(association); + Add(association); return association; } else @@ -113,18 +105,18 @@ namespace VEPROMS.CSLA.Library get { return IsValidList(new List()); } } public bool IsValidList(List list) - { - // run through all the child objects - // and if any are invalid then the - // collection is invalid - foreach (DocVersionAssociation child in this) - if (!child.IsValidList(list)) - { - //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); - return false; - } - return true; - } + { + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (DocVersionAssociation child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } public bool Contains(ROFst myROFst) { foreach (DocVersionAssociation association in this) @@ -156,20 +148,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static DocVersionAssociations New() - { - return new DocVersionAssociations(); - } - internal static DocVersionAssociations Get(SafeDataReader dr) - { - return new DocVersionAssociations(dr); - } - public static DocVersionAssociations GetByVersionID(int versionID) + #endregion + #region Factory Methods + internal static DocVersionAssociations New() => new DocVersionAssociations(); + internal static DocVersionAssociations Get(SafeDataReader dr) => new DocVersionAssociations(dr); + public static DocVersionAssociations GetByVersionID(int versionID) { try { @@ -180,11 +166,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DocVersionAssociations.GetByVersionID", ex); } } - private DocVersionAssociations() - { - MarkAsChild(); - } - internal DocVersionAssociations(SafeDataReader dr) + private DocVersionAssociations() => MarkAsChild(); + internal DocVersionAssociations(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -193,16 +176,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocVersionAssociations() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocVersionAssociations() { _CountFinalized++; } @@ -217,19 +196,16 @@ namespace VEPROMS.CSLA.Library // called to load data from the database private void Fetch(SafeDataReader dr) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; while (dr.Read()) - this.Add(DocVersionAssociation.Get(dr)); - this.RaiseListChangedEvents = true; + Add(DocVersionAssociation.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class VersionIDCriteria { - public VersionIDCriteria(int versionID) - { - _VersionID = versionID; - } - private int _VersionID; + public VersionIDCriteria(int versionID) => _VersionID = versionID; + private int _VersionID; public int VersionID { get { return _VersionID; } @@ -238,7 +214,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(VersionIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionAssociations.DataPortal_FetchVersionID", GetHashCode()); try { @@ -252,7 +228,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new DocVersionAssociation(dr)); + while (dr.Read()) Add(new DocVersionAssociation(dr)); } } } @@ -262,11 +238,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionAssociations.DataPortal_FetchVersionID", ex); throw new DbCslaException("DocVersionAssociations.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(DocVersion docVersion) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -285,49 +261,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public string GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public string GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DocVersionAssociationsPropertyDescriptor pd = new DocVersionAssociationsPropertyDescriptor(this, i); @@ -344,7 +309,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocVersionAssociationsPropertyDescriptor : vlnListPropertyDescriptor { - private DocVersionAssociation Item { get { return (DocVersionAssociation)_Item; } } public DocVersionAssociationsPropertyDescriptor(DocVersionAssociations collection, int index) : base(collection, index) { ;} } #endregion @@ -353,10 +317,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocVersionAssociations) + if (destType == typeof(string) && value is DocVersionAssociations associations) { // Return department and department role separated by comma. - return ((DocVersionAssociations)value).Items.Count.ToString() + " Associations"; + return $"{associations.Items.Count} Associations"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs index aa0bb85b..9ef46ea0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library public partial class DocVersionInfo : ReadOnlyBase, IDisposable { public event DocVersionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } + private void OnChange() => Changed?.Invoke(this); #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DocVersionInfo docVersionInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; protected DocVersion _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _VersionID; [System.ComponentModel.DataObjectField(true, true)] public int VersionID @@ -252,32 +236,19 @@ namespace VEPROMS.CSLA.Library foreach (DocVersionInfo tmp in _CacheByPrimaryKey[_VersionID.ToString()]) tmp._DocVersionAssociationCount = -1; // This will cause the data to be requeried } - // CSLATODO: Replace base DocVersionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DocVersionInfo.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocVersionInfo - protected override object GetIdValue() - { - return MyDocVersionInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocVersionInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _DocVersionInfoUnique = 0; - private static int DocVersionInfoUnique - { get { return ++_DocVersionInfoUnique; } } - private int _MyDocVersionInfoUnique = DocVersionInfoUnique; - public int MyDocVersionInfoUnique // Absolutely Unique ID - Info - { get { return _MyDocVersionInfoUnique; } } + private static int DocVersionInfoUnique => ++_DocVersionInfoUnique; + private readonly int _MyDocVersionInfoUnique = DocVersionInfoUnique; + // Absolutely Unique ID - Info + public int MyDocVersionInfoUnique => _MyDocVersionInfoUnique; protected DocVersionInfo() {/* require use of factory methods */ AddToCache(this); @@ -286,15 +257,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocVersionInfo() { _CountFinalized++; @@ -311,10 +278,7 @@ namespace VEPROMS.CSLA.Library if (listDocVersionInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list } - public virtual DocVersion Get() - { - return _Editable = DocVersion.Get(_VersionID); - } + public virtual DocVersion Get() => _Editable = DocVersion.Get(_VersionID); public static void Refresh(DocVersion tmp) { string key = tmp.VersionID.ToString(); @@ -327,28 +291,28 @@ namespace VEPROMS.CSLA.Library { if (_FolderID != tmp.FolderID) { - if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value + MyFolder?.RefreshFolderDocVersions(); // Update List for old value _FolderID = tmp.FolderID; // Update the value } _MyFolder = null; // Reset list so that the next line gets a new list - if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for new value + MyFolder?.RefreshFolderDocVersions(); // Update List for new value _VersionType = tmp.VersionType; _Name = tmp.Name; _Title = tmp.Title; if (_ItemID != tmp.ItemID) { - if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value + MyItem?.RefreshItemDocVersions(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list - if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value + MyItem?.RefreshItemDocVersions(); // Update List for new value if (_FormatID != tmp.FormatID) { - if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value + MyFormat?.RefreshFormatDocVersions(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list - if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for new value + MyFormat?.RefreshFormatDocVersions(); // Update List for new value _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -370,18 +334,18 @@ namespace VEPROMS.CSLA.Library _Title = tmp.Title; if (_ItemID != tmp.ItemID) { - if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value + MyItem?.RefreshItemDocVersions(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list - if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value + MyItem?.RefreshItemDocVersions(); // Update List for new value if (_FormatID != tmp.FormatID) { - if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value + MyFormat?.RefreshFormatDocVersions(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list - if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for new value + MyFormat?.RefreshFormatDocVersions(); // Update List for new value _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -400,21 +364,21 @@ namespace VEPROMS.CSLA.Library { if (_FolderID != tmp.FolderID) { - if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value + MyFolder?.RefreshFolderDocVersions(); // Update List for old value _FolderID = tmp.FolderID; // Update the value } _MyFolder = null; // Reset list so that the next line gets a new list - if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for new value + MyFolder?.RefreshFolderDocVersions(); // Update List for new value _VersionType = tmp.VersionType; _Name = tmp.Name; _Title = tmp.Title; if (_ItemID != tmp.ItemID) { - if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value + MyItem?.RefreshItemDocVersions(); // Update List for old value _ItemID = tmp.ItemID; // Update the value } _MyItem = null; // Reset list so that the next line gets a new list - if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value + MyItem?.RefreshItemDocVersions(); // Update List for new value _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -433,21 +397,21 @@ namespace VEPROMS.CSLA.Library { if (_FolderID != tmp.FolderID) { - if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value + MyFolder?.RefreshFolderDocVersions(); // Update List for old value _FolderID = tmp.FolderID; // Update the value } _MyFolder = null; // Reset list so that the next line gets a new list - if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for new value + MyFolder?.RefreshFolderDocVersions(); // Update List for new value _VersionType = tmp.VersionType; _Name = tmp.Name; _Title = tmp.Title; if (_FormatID != tmp.FormatID) { - if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value + MyFormat?.RefreshFormatDocVersions(); // Update List for old value _FormatID = tmp.FormatID; // Update the value } _MyFormat = null; // Reset list so that the next line gets a new list - if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for new value + MyFormat?.RefreshFormatDocVersions(); // Update List for new value _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -456,8 +420,6 @@ namespace VEPROMS.CSLA.Library } public static DocVersionInfo Get(int versionID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a DocVersion"); try { DocVersionInfo tmp = GetCachedByPrimaryKey(versionID); @@ -496,13 +458,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } + private readonly int _VersionID; + public int VersionID => _VersionID; + public PKCriteria(int versionID) => _VersionID = versionID; } private void ReadData(SafeDataReader dr) { @@ -567,7 +525,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension(); + readonly DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension(); [Serializable()] partial class DocVersionInfoExtension : extensionBase { } [Serializable()] @@ -583,10 +541,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocVersionInfo) + if (destType == typeof(string) && value is DocVersionInfo info) { // Return the ToString value - return ((DocVersionInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfoList.cs index 18ebcfbd..0563edb3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfoList.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library { #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() + #endregion + #region Business Methods + internal new IList Items => base.Items; + public void AddEvents() { foreach (DocVersionInfo tmp in this) { @@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library for (int i = 0; i < Count; i++) { if (base[i] == sender) - this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); } } private bool _Disposed = false; private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocVersionInfoList() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocVersionInfoList() { _CountFinalized++; } @@ -104,18 +97,7 @@ namespace VEPROMS.CSLA.Library { _DocVersionInfoList = null; } - // CSLATODO: Add alternative gets - - //public static DocVersionInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on DocVersionInfoList.Get", ex); - // } - //} + public static DocVersionInfoList GetByFolderID(int folderID) { try @@ -164,7 +146,7 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal private void DataPortal_Fetch() { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_Fetch", GetHashCode()); try { @@ -178,7 +160,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DocVersionInfo(dr)); + while (dr.Read()) Add(new DocVersionInfo(dr)); IsReadOnly = true; } } @@ -189,16 +171,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_Fetch", ex); throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } [Serializable()] private class FolderIDCriteria { - public FolderIDCriteria(int folderID) - { - _FolderID = folderID; - } - private int _FolderID; + public FolderIDCriteria(int folderID) => _FolderID = folderID; + private int _FolderID; public int FolderID { get { return _FolderID; } @@ -207,7 +186,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(FolderIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchFolderID", GetHashCode()); try { @@ -222,7 +201,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DocVersionInfo(dr)); + while (dr.Read()) Add(new DocVersionInfo(dr)); IsReadOnly = true; } } @@ -233,16 +212,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_FetchFolderID", ex); throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } [Serializable()] private class FormatIDCriteria { - public FormatIDCriteria(int? formatID) - { - _FormatID = formatID; - } - private int? _FormatID; + public FormatIDCriteria(int? formatID) => _FormatID = formatID; + private int? _FormatID; public int? FormatID { get { return _FormatID; } @@ -251,7 +227,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(FormatIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchFormatID", GetHashCode()); try { @@ -266,7 +242,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DocVersionInfo(dr)); + while (dr.Read()) Add(new DocVersionInfo(dr)); IsReadOnly = true; } } @@ -277,16 +253,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_FetchFormatID", ex); throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } [Serializable()] private class ItemIDCriteria { - public ItemIDCriteria(int? itemID) - { - _ItemID = itemID; - } - private int? _ItemID; + public ItemIDCriteria(int? itemID) => _ItemID = itemID; + private int? _ItemID; public int? ItemID { get { return _ItemID; } @@ -295,7 +268,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(ItemIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchItemID", GetHashCode()); try { @@ -310,7 +283,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DocVersionInfo(dr)); + while (dr.Read()) Add(new DocVersionInfo(dr)); IsReadOnly = true; } } @@ -321,48 +294,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_FetchItemID", ex); throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public string GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public string GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DocVersionInfoListPropertyDescriptor pd = new DocVersionInfoListPropertyDescriptor(this, i); @@ -379,7 +341,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocVersionInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private DocVersionInfo Item { get { return (DocVersionInfo)_Item; } } public DocVersionInfoListPropertyDescriptor(DocVersionInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -388,10 +349,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocVersionInfoList) + if (destType == typeof(string) && value is DocVersionInfoList list) { // Return department and department role separated by comma. - return ((DocVersionInfoList)value).Items.Count.ToString() + " DocVersions"; + return $"{list.Items.Count} DocVersions"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs index 6ca09e38..037fcb56 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -95,6 +93,7 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(Document document) { @@ -104,6 +103,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -129,15 +129,9 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; private static int _nextDocID = -1; - public static int NextDocID - { - get { return _nextDocID--; } - } + public static int NextDocID => _nextDocID--; private int _DocID; [System.ComponentModel.DataObjectField(true, true)] public int DocID @@ -354,10 +348,7 @@ namespace VEPROMS.CSLA.Library return _DocumentEntries; } } - public void Reset_DocumentEntries() - { - _DocumentEntryCount = -1; - } + public void Reset_DocumentEntries() => _DocumentEntryCount = -1; private int _DocumentPdfCount = 0; /// /// Count of DocumentPdfs for this Document @@ -389,10 +380,7 @@ namespace VEPROMS.CSLA.Library return _DocumentPdfs; } } - public void Reset_DocumentPdfs() - { - _DocumentPdfCount = -1; - } + public void Reset_DocumentPdfs() => _DocumentPdfCount = -1; public override bool IsDirty { get @@ -407,37 +395,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_DocumentDROUsages == null ? false : _DocumentDROUsages.IsDirtyList(list)) || (_DocumentEntries == null ? false : _DocumentEntries.IsDirtyList(list)) || (_DocumentPdfs == null ? false : _DocumentPdfs.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_DocumentDROUsages != null && _DocumentDROUsages.IsDirtyList(list)) || (_DocumentEntries != null && _DocumentEntries.IsDirtyList(list)) || (_DocumentPdfs != null && _DocumentPdfs.IsDirtyList(list)); } + public override bool IsValid => IsValidList(new List()); public bool IsValidList(List list) { if (list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; + return (IsNew && !IsDirty) || base.IsValid; list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocumentDROUsages == null ? true : _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null ? true : _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null ? true : _DocumentPdfs.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_DocumentDROUsages == null || _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null || _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null || _DocumentPdfs.IsValidList(list)); } - // CSLATODO: Replace base Document.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Document - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check Document.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current Document - protected override object GetIdValue() - { - return MyDocumentUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocumentUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -468,8 +441,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -502,37 +475,11 @@ namespace VEPROMS.CSLA.Library _DocumentExtension.AddInstanceValidationRules(ValidationRules); // CSLATODO: Add other validation rules } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(LibTitle, ""); - //AuthorizationRules.AllowRead(DocContent, ""); - //AuthorizationRules.AllowRead(DocAscii, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FileExtension, ""); - //AuthorizationRules.AllowWrite(LibTitle, ""); - //AuthorizationRules.AllowWrite(DocContent, ""); - //AuthorizationRules.AllowWrite(DocAscii, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FileExtension, ""); _DocumentExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -540,57 +487,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _DocumentExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _DocumentDROUsageCount; - usedByCount += _DocumentEntryCount; - usedByCount += _DocumentPdfCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocumentUnique = 0; - protected static int DocumentUnique - { get { return ++_DocumentUnique; } } - private int _MyDocumentUnique = DocumentUnique; - public int MyDocumentUnique // Absolutely Unique ID - Editable - { get { return _MyDocumentUnique; } } + protected static int DocumentUnique => ++_DocumentUnique; + private readonly int _MyDocumentUnique = DocumentUnique; + // Absolutely Unique ID - Editable + public int MyDocumentUnique => _MyDocumentUnique; protected Document() {/* require use of factory methods */ AddToCache(this); @@ -599,15 +503,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~Document() { _CountFinalized++; @@ -632,8 +532,6 @@ namespace VEPROMS.CSLA.Library } public static Document New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Document"); try { return DataPortal.Create(); @@ -699,8 +597,6 @@ namespace VEPROMS.CSLA.Library } public static Document Get(int docID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Document"); try { Document tmp = GetCachedByPrimaryKey(docID); @@ -726,14 +622,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new Document(dr); return null; } - internal Document(SafeDataReader dr) - { - ReadData(dr); - } + internal Document(SafeDataReader dr) => ReadData(dr); public static void Delete(int docID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Document"); try { DataPortal.Delete(new PKCriteria(docID)); @@ -745,12 +636,6 @@ namespace VEPROMS.CSLA.Library } public override Document Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Document"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Document"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Document"); try { BuildRefreshList(); @@ -770,13 +655,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _DocID; - public int DocID - { get { return _DocID; } } - public PKCriteria(int docID) - { - _DocID = docID; - } + private readonly int _DocID; + public int DocID => _DocID; + public PKCriteria(int docID) => _DocID = docID; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -889,41 +770,48 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addDocument"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@LibTitle", _LibTitle); - cm.Parameters.AddWithValue("@DocContent", _DocContent); - cm.Parameters.AddWithValue("@DocAscii", _DocAscii); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FileExtension", _FileExtension); - // Output Calculated Columns - SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int); - param_DocID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DocID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _DocID = (int)cm.Parameters["@newDocID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addDocument"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@LibTitle", _LibTitle); + cm.Parameters.AddWithValue("@DocContent", _DocContent); + cm.Parameters.AddWithValue("@DocAscii", _DocAscii); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FileExtension", _FileExtension); + // Output Calculated Columns + SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_DocID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _DocID = (int)cm.Parameters["@newDocID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects - if (_DocumentEntries != null) _DocumentEntries.Update(this); - if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); - if (_DocumentPdfs != null) _DocumentPdfs.Update(this); + _DocumentEntries?.Update(this); + _DocumentDROUsages?.Update(this); + _DocumentPdfs?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -953,11 +841,15 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@FileExtension", fileExtension); // Output Calculated Columns - SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int); - param_DocID.Direction = ParameterDirection.Output; + SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_DocID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -1002,39 +894,44 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLUpdate", GetHashCode()); try { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - using (SqlCommand cm = cn.CreateCommand()) + if (base.IsDirty) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDocument"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@DocID", _DocID); - cm.Parameters.AddWithValue("@LibTitle", _LibTitle); - cm.Parameters.AddWithValue("@DocContent", _DocContent); - cm.Parameters.AddWithValue("@DocAscii", _DocAscii); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - cm.Parameters.AddWithValue("@FileExtension", _FileExtension); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDocument"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@DocID", _DocID); + cm.Parameters.AddWithValue("@LibTitle", _LibTitle); + cm.Parameters.AddWithValue("@DocContent", _DocContent); + cm.Parameters.AddWithValue("@DocAscii", _DocAscii); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + cm.Parameters.AddWithValue("@FileExtension", _FileExtension); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } } + MarkOld(); // use the open connection to update child objects - if (_DocumentEntries != null) _DocumentEntries.Update(this); - if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); - if (_DocumentPdfs != null) _DocumentPdfs.Update(this); + _DocumentEntries?.Update(this); + _DocumentDROUsages?.Update(this); + _DocumentPdfs?.Update(this); } catch (Exception ex) { @@ -1045,19 +942,22 @@ namespace VEPROMS.CSLA.Library } internal void Update() { - if (!this.IsDirty) return; + if (!IsDirty) return; if (base.IsDirty) { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Document.Add(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension); - else - _LastChanged = Document.Update(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, ref _LastChanged, _FileExtension); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = Document.Add(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension); + else + _LastChanged = Document.Update(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, ref _LastChanged, _FileExtension); + } + MarkOld(); } - if (_DocumentEntries != null) _DocumentEntries.Update(this); - if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); - if (_DocumentPdfs != null) _DocumentPdfs.Update(this); + _DocumentEntries?.Update(this); + _DocumentDROUsages?.Update(this); + _DocumentPdfs?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] public static byte[] Update(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, ref byte[] lastChanged, string fileExtension) @@ -1081,8 +981,10 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@LastChanged", lastChanged); cm.Parameters.AddWithValue("@FileExtension", fileExtension); // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -1097,10 +999,7 @@ namespace VEPROMS.CSLA.Library } } [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_DocID)); - } + protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_DocID)); [Transactional(TransactionalTypes.TransactionScope)] private void DataPortal_Delete(PKCriteria criteria) { @@ -1167,16 +1066,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _DocID; + private readonly int _DocID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int docID) - { - _DocID = docID; - } + public bool Exists => _exists; + public ExistsCommand(int docID) => _DocID = docID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode()); @@ -1206,7 +1099,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - DocumentExtension _DocumentExtension = new DocumentExtension(); + readonly DocumentExtension _DocumentExtension = new DocumentExtension(); [Serializable()] partial class DocumentExtension : extensionBase { @@ -1215,18 +1108,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - public virtual string DefaultFileExtension - { - get { return ".Doc"; } - } + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; + public virtual string DefaultFileExtension => ".Doc"; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -1255,61 +1139,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is Document) + if (destType == typeof(string) && value is Document doc) { // Return the ToString value - return ((Document)value).ToString(); + return doc.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocumentExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class Document -// { -// partial class DocumentExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual DateTime DefaultDTS -// { -// get { return DateTime.Now; } -// } -// public virtual string DefaultUserID -// { -// get { return Environment.UserName.ToUpper(); } -// } -// public virtual string DefaultFileExtension -// { -// get { return ".Doc"; } -// } -// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowRead(Dbid, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs index 7f1fdaf5..95dabee1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library if (IsDirty) refreshDocumentAudits.Add(this); } - private void ClearRefreshList() - { - _RefreshDocumentAudits = new List(); - } + private void ClearRefreshList() => _RefreshDocumentAudits = new List(); private void BuildRefreshList() { ClearRefreshList(); @@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library } #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DocumentAudit documentAudit) { @@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } + public static int NextAuditID => _nextAuditID--; private long _AuditID; [System.ComponentModel.DataObjectField(true, true)] public long AuditID @@ -294,40 +285,14 @@ namespace VEPROMS.CSLA.Library } } } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base DocumentAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentAudit - //public override string ToString() - //{ - // return base.ToString(); - //} + public override bool IsDirty => base.IsDirty; + public override bool IsValid => (IsNew && !IsDirty) || base.IsValid; // CSLATODO: Check DocumentAudit.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocumentAudit - protected override object GetIdValue() - { - return MyDocumentAuditUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocumentAuditUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -355,8 +320,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules?.BrokenRules); } } protected override void AddBusinessRules() @@ -389,43 +354,11 @@ namespace VEPROMS.CSLA.Library _DocumentAuditExtension.AddInstanceValidationRules(ValidationRules); // CSLATODO: Add other validation rules } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AuditID, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(LibTitle, ""); - //AuthorizationRules.AllowRead(DocContent, ""); - //AuthorizationRules.AllowRead(DocAscii, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FileExtension, ""); - //AuthorizationRules.AllowRead(DocPdf, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(LibTitle, ""); - //AuthorizationRules.AllowWrite(DocContent, ""); - //AuthorizationRules.AllowWrite(DocAscii, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FileExtension, ""); - //AuthorizationRules.AllowWrite(DocPdf, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); _DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -433,42 +366,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _DocumentAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules); } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocumentAuditUnique = 0; - protected static int DocumentAuditUnique - { get { return ++_DocumentAuditUnique; } } - private int _MyDocumentAuditUnique = DocumentAuditUnique; - public int MyDocumentAuditUnique // Absolutely Unique ID - Editable - { get { return _MyDocumentAuditUnique; } } + protected static int DocumentAuditUnique => ++_DocumentAuditUnique; + private readonly int _MyDocumentAuditUnique = DocumentAuditUnique; + // Absolutely Unique ID - Editable + public int MyDocumentAuditUnique => _MyDocumentAuditUnique; protected DocumentAudit() {/* require use of factory methods */ AddToCache(this); @@ -477,15 +382,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocumentAudit() { _CountFinalized++; @@ -510,8 +411,6 @@ namespace VEPROMS.CSLA.Library } public static DocumentAudit New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); try { return DataPortal.Create(); @@ -564,8 +463,6 @@ namespace VEPROMS.CSLA.Library } public static DocumentAudit Get(long auditID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a DocumentAudit"); try { DocumentAudit tmp = GetCachedByPrimaryKey(auditID); @@ -591,14 +488,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new DocumentAudit(dr); return null; } - internal DocumentAudit(SafeDataReader dr) - { - ReadData(dr); - } + internal DocumentAudit(SafeDataReader dr) => ReadData(dr); public static void Delete(long auditID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DocumentAudit"); try { DataPortal.Delete(new PKCriteria(auditID)); @@ -610,12 +502,6 @@ namespace VEPROMS.CSLA.Library } public override DocumentAudit Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DocumentAudit"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a DocumentAudit"); try { BuildRefreshList(); @@ -635,13 +521,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } + private readonly long _AuditID; + public long AuditID => _AuditID; + public PKCriteria(long auditID) => _AuditID = auditID; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -742,35 +624,40 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addDocumentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DocID", _DocID); - cm.Parameters.AddWithValue("@LibTitle", _LibTitle); - cm.Parameters.AddWithValue("@DocContent", _DocContent); - cm.Parameters.AddWithValue("@DocAscii", _DocAscii); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FileExtension", _FileExtension); - cm.Parameters.AddWithValue("@DocPdf", _DocPdf); - cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); - // Output Calculated Columns - SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); - param_AuditID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AuditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _AuditID = (long)cm.Parameters["@newAuditID"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addDocumentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", _DocID); + cm.Parameters.AddWithValue("@LibTitle", _LibTitle); + cm.Parameters.AddWithValue("@DocContent", _DocContent); + cm.Parameters.AddWithValue("@DocAscii", _DocAscii); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FileExtension", _FileExtension); + cm.Parameters.AddWithValue("@DocPdf", _DocPdf); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } } + MarkOld(); // update child objects if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode()); @@ -805,8 +692,10 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@DocPdf", docPdf); cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); // Output Calculated Columns - SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); - param_AuditID.Direction = ParameterDirection.Output; + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_AuditID); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -851,32 +740,35 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLUpdate", GetHashCode()); try { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - using (SqlCommand cm = cn.CreateCommand()) + if (base.IsDirty) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDocumentAudit"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AuditID", _AuditID); - cm.Parameters.AddWithValue("@DocID", _DocID); - cm.Parameters.AddWithValue("@LibTitle", _LibTitle); - cm.Parameters.AddWithValue("@DocContent", _DocContent); - cm.Parameters.AddWithValue("@DocAscii", _DocAscii); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FileExtension", _FileExtension); - cm.Parameters.AddWithValue("@DocPdf", _DocPdf); - cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); - // Output Calculated Columns - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDocumentAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@DocID", _DocID); + cm.Parameters.AddWithValue("@LibTitle", _LibTitle); + cm.Parameters.AddWithValue("@DocContent", _DocContent); + cm.Parameters.AddWithValue("@DocAscii", _DocAscii); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FileExtension", _FileExtension); + cm.Parameters.AddWithValue("@DocPdf", _DocPdf); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } } } + MarkOld(); // use the open connection to update child objects } @@ -889,14 +781,17 @@ namespace VEPROMS.CSLA.Library } internal void Update() { - if (!this.IsDirty) return; + if (!IsDirty) return; if (base.IsDirty) { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - DocumentAudit.Add(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus); - else - DocumentAudit.Update(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + DocumentAudit.Add(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus); + else + DocumentAudit.Update(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus); + } + MarkOld(); } } @@ -937,10 +832,7 @@ namespace VEPROMS.CSLA.Library } } [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_AuditID)); - } + protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AuditID)); [Transactional(TransactionalTypes.TransactionScope)] private void DataPortal_Delete(PKCriteria criteria) { @@ -992,7 +884,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); + readonly DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); [Serializable()] partial class DocumentAuditExtension : extensionBase { @@ -1029,49 +921,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentAudit) + if (destType == typeof(string) && value is DocumentAudit audit) { // Return the ToString value - return ((DocumentAudit)value).ToString(); + return audit.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocumentAuditExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DocumentAudit -// { -// partial class DocumentAuditExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowRead(Dbid, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs index a288f552..1ed1867a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library public partial class DocumentAuditInfo : ReadOnlyBase, IDisposable { public event DocumentAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } + private void OnChange() => Changed?.Invoke(this); #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DocumentAuditInfo documentAuditInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; protected DocumentAudit _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private long _AuditID; [System.ComponentModel.DataObjectField(true, true)] public long AuditID @@ -180,32 +164,19 @@ namespace VEPROMS.CSLA.Library return _DeleteStatus; } } - // CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DocumentAuditInfo.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocumentAuditInfo - protected override object GetIdValue() - { - return MyDocumentAuditInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocumentAuditInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _DocumentAuditInfoUnique = 0; - private static int DocumentAuditInfoUnique - { get { return ++_DocumentAuditInfoUnique; } } - private int _MyDocumentAuditInfoUnique = DocumentAuditInfoUnique; - public int MyDocumentAuditInfoUnique // Absolutely Unique ID - Info - { get { return _MyDocumentAuditInfoUnique; } } + private static int DocumentAuditInfoUnique => ++_DocumentAuditInfoUnique; + private readonly int _MyDocumentAuditInfoUnique = DocumentAuditInfoUnique; + // Absolutely Unique ID - Info + public int MyDocumentAuditInfoUnique => _MyDocumentAuditInfoUnique; protected DocumentAuditInfo() {/* require use of factory methods */ AddToCache(this); @@ -214,15 +185,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocumentAuditInfo() { _CountFinalized++; @@ -239,10 +206,7 @@ namespace VEPROMS.CSLA.Library if (listDocumentAuditInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list } - public virtual DocumentAudit Get() - { - return _Editable = DocumentAudit.Get(_AuditID); - } + public virtual DocumentAudit Get() => _Editable = DocumentAudit.Get(_AuditID); public static void Refresh(DocumentAudit tmp) { string key = tmp.AuditID.ToString(); @@ -267,8 +231,6 @@ namespace VEPROMS.CSLA.Library } public static DocumentAuditInfo Get(long auditID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a DocumentAudit"); try { DocumentAuditInfo tmp = GetCachedByPrimaryKey(auditID); @@ -307,13 +269,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } + private readonly long _AuditID; + public long AuditID => _AuditID; + public PKCriteria(long auditID) => _AuditID = auditID; } private void ReadData(SafeDataReader dr) { @@ -377,7 +335,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); + readonly DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); [Serializable()] partial class DocumentAuditInfoExtension : extensionBase { } [Serializable()] @@ -393,10 +351,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentAuditInfo) + if (destType == typeof(string) && value is DocumentAuditInfo info) { // Return the ToString value - return ((DocumentAuditInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs index f5375756..ae249d1c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library { #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() + #endregion + #region Business Methods + internal new IList Items => base.Items; + public void AddEvents() { foreach (DocumentAuditInfo tmp in this) { @@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocumentAuditInfoList() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocumentAuditInfoList() { _CountFinalized++; } @@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex); } } - /// - /// Reset the list of all DocumentAuditInfo. - /// - public static void Reset() - { - _DocumentAuditInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static DocumentAuditInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex); - // } - //} - private DocumentAuditInfoList() + /// + /// Reset the list of all DocumentAuditInfo. + /// + public static void Reset() => _DocumentAuditInfoList = null; + private DocumentAuditInfoList() { /* require use of factory methods */ } #endregion #region Data Access Portal @@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library } this.RaiseListChangedEvents = true; } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public string GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public string GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); @@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocumentAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private DocumentAuditInfo Item { get { return (DocumentAuditInfo)_Item; } } public DocumentAuditInfoListPropertyDescriptor(DocumentAuditInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentAuditInfoList) + if (destType == typeof(string) && value is DocumentAuditInfoList list) { // Return department and department role separated by comma. - return ((DocumentAuditInfoList)value).Items.Count.ToString() + " DocumentAudits"; + return $"{list.Items.Count} DocumentAudits"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs index b3c396de..139432bd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs @@ -9,12 +9,9 @@ // ======================================================================== using System; -using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; private int _DROUsageID; [System.ComponentModel.DataObjectField(true, true)] public int DROUsageID @@ -232,10 +226,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocumentDROUsage - protected override object GetIdValue() - { - return MyDocumentDROUsageUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocumentDROUsageUnique; // Absolutely Unique ID // CSLATODO: Replace base DocumentDROUsage.ToString function as necessary /// /// Overrides Base ToString @@ -259,18 +250,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyRODb != null && _MyRODb.IsDirtyList(list)); } + public override bool IsValid => IsValidList(new List()); public bool IsValidList(List list) { if (list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; + return (IsNew && !IsDirty) || base.IsValid; list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyRODb == null || _MyRODb.IsValidList(list)); } #endregion #region ValidationRules @@ -300,8 +288,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -331,78 +319,22 @@ namespace VEPROMS.CSLA.Library } return true; } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { - //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DROUsageID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; + } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocumentDROUsageUnique = 0; - private static int DocumentDROUsageUnique - { get { return ++_DocumentDROUsageUnique; } } - private int _MyDocumentDROUsageUnique = DocumentDROUsageUnique; - public int MyDocumentDROUsageUnique // Absolutely Unique ID - Editable FK - { get { return _MyDocumentDROUsageUnique; } } - internal static DocumentDROUsage New(string roid, RODb myRODb) - { - return new DocumentDROUsage(roid, myRODb); - } - internal static DocumentDROUsage Get(SafeDataReader dr) - { - return new DocumentDROUsage(dr); - } + private static int DocumentDROUsageUnique => ++_DocumentDROUsageUnique; + private readonly int _MyDocumentDROUsageUnique = DocumentDROUsageUnique; + // Absolutely Unique ID - Editable FK + public int MyDocumentDROUsageUnique => _MyDocumentDROUsageUnique; + internal static DocumentDROUsage New(string roid, RODb myRODb) => new DocumentDROUsage(roid, myRODb); + internal static DocumentDROUsage Get(SafeDataReader dr) => new DocumentDROUsage(dr); public DocumentDROUsage() { MarkAsChild(); @@ -431,15 +363,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocumentDROUsage() { _CountFinalized++; @@ -481,33 +409,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = DROUsage.Add(cn, ref _DROUsageID, myDocument, _ROID, _Config, _DTS, _UserID, _MyRODb); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = DROUsage.Add(cn, ref _DROUsageID, myDocument, _ROID, _Config, _DTS, _UserID, _MyRODb); + } + MarkOld(); } internal void Update(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = DROUsage.Update(cn, ref _DROUsageID, myDocument.DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = DROUsage.Update(cn, ref _DROUsageID, myDocument.DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; + if (!IsDirty) return; // if we're new then don't update the database - if (this.IsNew) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - DROUsage.Remove(cn, _DROUsageID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + DROUsage.Remove(cn, _DROUsageID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - DocumentDROUsageExtension _DocumentDROUsageExtension = new DocumentDROUsageExtension(); + readonly DocumentDROUsageExtension _DocumentDROUsageExtension = new DocumentDROUsageExtension(); [Serializable()] partial class DocumentDROUsageExtension : extensionBase { @@ -516,18 +454,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual int DefaultDocID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual int DefaultDocID => 0; + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -556,61 +485,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentDROUsage) + if (destType == typeof(string) && value is DocumentDROUsage usage) { // Return the ToString value - return ((DocumentDROUsage)value).ToString(); + return usage.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocumentDROUsageExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DocumentDROUsage -// { -// partial class DocumentDROUsageExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual int DefaultDocID -// { -// 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsages.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsages.cs index 6e620f8b..940eac31 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsages.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsages.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - // One To Many - public DocumentDROUsage this[DROUsage myDROUsage] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public DocumentDROUsage this[DROUsage myDROUsage] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public DocumentDROUsage GetItem(DROUsage myDROUsage) + public new System.Collections.Generic.IList Items => base.Items; + public DocumentDROUsage GetItem(DROUsage myDROUsage) { foreach (DocumentDROUsage dROUsage in this) if (dROUsage.DROUsageID == myDROUsage.DROUsageID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public DocumentDROUsage Add(string roid, RODb myRODb) // One to Many { DocumentDROUsage dROUsage = DocumentDROUsage.New(roid, myRODb); - this.Add(dROUsage); + Add(dROUsage); return dROUsage; } public void Remove(DROUsage myDROUsage) @@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library return true; return false; } - public override bool IsValid + public override bool IsValid => IsValidList(new List()); + public bool IsValidList(List list) { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - // run through all the child objects - // and if any are invalid then the - // collection is invalid - foreach (DocumentDROUsage child in this) - if (!child.IsValidList(list)) - { - //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); - return false; - } - return true; - } + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (DocumentDROUsage child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } #endregion #region ValidationRules public IVEHasBrokenRules HasBrokenRules @@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static DocumentDROUsages New() - { - return new DocumentDROUsages(); - } - internal static DocumentDROUsages Get(SafeDataReader dr) - { - return new DocumentDROUsages(dr); - } - public static DocumentDROUsages GetByDocID(int docID) + #endregion + #region Factory Methods + internal static DocumentDROUsages New() => new DocumentDROUsages(); + internal static DocumentDROUsages Get(SafeDataReader dr) => new DocumentDROUsages(dr); + public static DocumentDROUsages GetByDocID(int docID) { try { @@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DocumentDROUsages.GetByDocID", ex); } } - private DocumentDROUsages() - { - MarkAsChild(); - } - internal DocumentDROUsages(SafeDataReader dr) + private DocumentDROUsages() => MarkAsChild(); + internal DocumentDROUsages(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocumentDROUsages() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocumentDROUsages() { _CountFinalized++; } @@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library // called to load data from the database private void Fetch(SafeDataReader dr) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; while (dr.Read()) - this.Add(DocumentDROUsage.Get(dr)); - this.RaiseListChangedEvents = true; + Add(DocumentDROUsage.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class DocIDCriteria { - public DocIDCriteria(int docID) - { - _DocID = docID; - } - private int _DocID; + public DocIDCriteria(int docID) => _DocID = docID; + private int _DocID; public int DocID { get { return _DocID; } @@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(DocIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentDROUsages.DataPortal_FetchDocID", GetHashCode()); try { @@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new DocumentDROUsage(dr)); + while (dr.Read()) Add(new DocumentDROUsage(dr)); } } } @@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentDROUsages.DataPortal_FetchDocID", ex); throw new DbCslaException("DocumentDROUsages.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(Document document) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public string GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public string GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DocumentDROUsagesPropertyDescriptor pd = new DocumentDROUsagesPropertyDescriptor(this, i); @@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocumentDROUsagesPropertyDescriptor : vlnListPropertyDescriptor { - private DocumentDROUsage Item { get { return (DocumentDROUsage)_Item; } } public DocumentDROUsagesPropertyDescriptor(DocumentDROUsages collection, int index) : base(collection, index) { ;} } #endregion @@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentDROUsages) + if (destType == typeof(string) && value is DocumentDROUsages usages) { // Return department and department role separated by comma. - return ((DocumentDROUsages)value).Items.Count.ToString() + " DROUsages"; + return $"{usages.Items.Count} DROUsages"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs index 882b3ac9..b1e429a6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntries.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - // One To Many - public DocumentEntry this[Entry myEntry] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public DocumentEntry this[Entry myEntry] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public DocumentEntry GetItem(Entry myEntry) + public new System.Collections.Generic.IList Items => base.Items; + public DocumentEntry GetItem(Entry myEntry) { foreach (DocumentEntry entry in this) if (entry.ContentID == myEntry.ContentID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public DocumentEntry Add(Entry myEntry) // One to Many { DocumentEntry entry = DocumentEntry.New(myEntry); - this.Add(entry); + Add(entry); return entry; } public void Remove(Entry myEntry) @@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library return true; return false; } - public override bool IsValid + public override bool IsValid => IsValidList(new List()); + public bool IsValidList(List list) { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - // run through all the child objects - // and if any are invalid then the - // collection is invalid - foreach (DocumentEntry child in this) - if (!child.IsValidList(list)) - { - //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); - return false; - } - return true; - } + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (DocumentEntry child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } #endregion #region ValidationRules public IVEHasBrokenRules HasBrokenRules @@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static DocumentEntries New() - { - return new DocumentEntries(); - } - internal static DocumentEntries Get(SafeDataReader dr) - { - return new DocumentEntries(dr); - } - public static DocumentEntries GetByDocID(int docID) + #endregion + #region Factory Methods + internal static DocumentEntries New() => new DocumentEntries(); + internal static DocumentEntries Get(SafeDataReader dr) => new DocumentEntries(dr); + public static DocumentEntries GetByDocID(int docID) { try { @@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DocumentEntries.GetByDocID", ex); } } - private DocumentEntries() - { - MarkAsChild(); - } - internal DocumentEntries(SafeDataReader dr) + private DocumentEntries() => MarkAsChild(); + internal DocumentEntries(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocumentEntries() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocumentEntries() { _CountFinalized++; } @@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library // called to load data from the database private void Fetch(SafeDataReader dr) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; while (dr.Read()) - this.Add(DocumentEntry.Get(dr)); - this.RaiseListChangedEvents = true; + Add(DocumentEntry.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class DocIDCriteria { - public DocIDCriteria(int docID) - { - _DocID = docID; - } - private int _DocID; + public DocIDCriteria(int docID) => _DocID = docID; + private int _DocID; public int DocID { get { return _DocID; } @@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(DocIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentEntries.DataPortal_FetchDocID", GetHashCode()); try { @@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new DocumentEntry(dr)); + while (dr.Read()) Add(new DocumentEntry(dr)); } } } @@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentEntries.DataPortal_FetchDocID", ex); throw new DbCslaException("DocumentEntries.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(Document document) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public string GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public string GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DocumentEntriesPropertyDescriptor pd = new DocumentEntriesPropertyDescriptor(this, i); @@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocumentEntriesPropertyDescriptor : vlnListPropertyDescriptor { - private DocumentEntry Item { get { return (DocumentEntry)_Item; } } public DocumentEntriesPropertyDescriptor(DocumentEntries collection, int index) : base(collection, index) { ;} } #endregion @@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentEntries) + if (destType == typeof(string) && value is DocumentEntries entries) { // Return department and department role separated by comma. - return ((DocumentEntries)value).Items.Count.ToString() + " Entries"; + return $"{entries.Items.Count} Entries"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs index 310f0ffe..97becf42 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs @@ -9,12 +9,9 @@ // ======================================================================== using System; -using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; private int _ContentID; [System.ComponentModel.DataObjectField(true, true)] public int ContentID @@ -170,35 +164,13 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocumentEntry - protected override object GetIdValue() - { - return MyDocumentEntryUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base DocumentEntry.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentEntry - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } + protected override object GetIdValue() => MyDocumentEntryUnique; // Absolutely Unique ID + public override bool IsDirty => base.IsDirty; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] + public bool IsDirtyList(List list) => base.IsDirty; + public override bool IsValid => (IsNew && !IsDirty) || base.IsValid; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] + public bool IsValidList(List list) => (IsNew && !IsDirty) || base.IsValid; #endregion #region ValidationRules [NonSerialized] @@ -226,8 +198,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -239,72 +211,22 @@ namespace VEPROMS.CSLA.Library new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); // CSLATODO: Add other validation rules } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { - //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; + } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocumentEntryUnique = 0; - private static int DocumentEntryUnique - { get { return ++_DocumentEntryUnique; } } - private int _MyDocumentEntryUnique = DocumentEntryUnique; - public int MyDocumentEntryUnique // Absolutely Unique ID - Editable FK - { get { return _MyDocumentEntryUnique; } } - internal static DocumentEntry New(Entry myEntry) - { - return new DocumentEntry(myEntry); - } - internal static DocumentEntry Get(SafeDataReader dr) - { - return new DocumentEntry(dr); - } + private static int DocumentEntryUnique => ++_DocumentEntryUnique; + private readonly int _MyDocumentEntryUnique = DocumentEntryUnique; + // Absolutely Unique ID - Editable FK + public int MyDocumentEntryUnique => _MyDocumentEntryUnique; + internal static DocumentEntry New(Entry myEntry) => new DocumentEntry(myEntry); + internal static DocumentEntry Get(SafeDataReader dr) => new DocumentEntry(dr); public DocumentEntry() { MarkAsChild(); @@ -331,15 +253,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocumentEntry() { _CountFinalized++; @@ -379,33 +297,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Entry.Add(cn, _MyEntry.MyContent, myDocument, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Entry.Add(cn, _MyEntry.MyContent, myDocument, _DTS, _UserID); + } + MarkOld(); } internal void Update(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Entry.Update(cn, _ContentID, myDocument.DocID, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Entry.Update(cn, _ContentID, myDocument.DocID, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; + if (!IsDirty) return; // if we're new then don't update the database - if (this.IsNew) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - Entry.Remove(cn, _ContentID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Entry.Remove(cn, _ContentID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension(); + readonly DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension(); [Serializable()] partial class DocumentEntryExtension : extensionBase { @@ -414,14 +342,8 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -450,57 +372,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentEntry) + if (destType == typeof(string) && value is DocumentEntry entry) { // Return the ToString value - return ((DocumentEntry)value).ToString(); + return entry.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocumentEntryExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DocumentEntry -// { -// partial class DocumentEntryExtension : 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs index 073948a0..7fc7bd0b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library public partial class DocumentInfo : ReadOnlyBase, IDisposable { public event DocumentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } + private void OnChange() => Changed?.Invoke(this); #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Collection + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static List _CacheList = new List(); protected static void AddToCache(DocumentInfo documentInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); private static void ConvertListToDictionary() { @@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library #endregion #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; protected Document _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _DocID; [System.ComponentModel.DataObjectField(true, true)] public int DocID @@ -276,32 +260,19 @@ namespace VEPROMS.CSLA.Library foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) tmp._DocumentPdfCount = -1; // This will cause the data to be requeried } - // CSLATODO: Replace base DocumentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check DocumentInfo.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocumentInfo - protected override object GetIdValue() - { - return MyDocumentInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyDocumentInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _DocumentInfoUnique = 0; - private static int DocumentInfoUnique - { get { return ++_DocumentInfoUnique; } } - private int _MyDocumentInfoUnique = DocumentInfoUnique; - public int MyDocumentInfoUnique // Absolutely Unique ID - Info - { get { return _MyDocumentInfoUnique; } } + private static int DocumentInfoUnique => ++_DocumentInfoUnique; + private readonly int _MyDocumentInfoUnique = DocumentInfoUnique; + // Absolutely Unique ID - Info + public int MyDocumentInfoUnique => _MyDocumentInfoUnique; protected DocumentInfo() {/* require use of factory methods */ AddToCache(this); @@ -310,15 +281,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocumentInfo() { _CountFinalized++; @@ -335,10 +302,7 @@ namespace VEPROMS.CSLA.Library if (listDocumentInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list } - public virtual Document Get() - { - return _Editable = Document.Get(_DocID); - } + public virtual Document Get() => _Editable = Document.Get(_DocID); public static void Refresh(Document tmp) { string key = tmp.DocID.ToString(); @@ -361,8 +325,6 @@ namespace VEPROMS.CSLA.Library } public static DocumentInfo Get(int docID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Document"); try { DocumentInfo tmp = GetCachedByPrimaryKey(docID); @@ -401,13 +363,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _DocID; - public int DocID - { get { return _DocID; } } - public PKCriteria(int docID) - { - _DocID = docID; - } + private readonly int _DocID; + public int DocID => _DocID; + public PKCriteria(int docID) => _DocID = docID; } private void ReadData(SafeDataReader dr) { @@ -472,7 +430,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension(); + readonly DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension(); [Serializable()] partial class DocumentInfoExtension : extensionBase { } [Serializable()] @@ -488,10 +446,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentInfo) + if (destType == typeof(string) && value is DocumentInfo info) { // Return the ToString value - return ((DocumentInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfoList.cs index e7223ded..9d21bef0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfoList.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library @@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library { #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() + #endregion + #region Business Methods + internal new IList Items => base.Items; + public void AddEvents() { foreach (DocumentInfo tmp in this) { @@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library for (int i = 0; i < Count; i++) { if (base[i] == sender) - this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); } } private bool _Disposed = false; private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocumentInfoList() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocumentInfoList() { _CountFinalized++; } @@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DocumentInfoList.Get", ex); } } - /// - /// Reset the list of all DocumentInfo. - /// - public static void Reset() - { - _DocumentInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static DocumentInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on DocumentInfoList.Get", ex); - // } - //} - private DocumentInfoList() + /// + /// Reset the list of all DocumentInfo. + /// + public static void Reset() => _DocumentInfoList = null; + private DocumentInfoList() { /* require use of factory methods */ } #endregion #region Data Access Portal private void DataPortal_Fetch() { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfoList.DataPortal_Fetch", GetHashCode()); try { @@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new DocumentInfo(dr)); + while (dr.Read()) Add(new DocumentInfo(dr)); IsReadOnly = true; } } @@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfoList.DataPortal_Fetch", ex); throw new DbCslaException("DocumentInfoList.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public String GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DocumentInfoListPropertyDescriptor pd = new DocumentInfoListPropertyDescriptor(this, i); @@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocumentInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private DocumentInfo Item { get { return (DocumentInfo)_Item; } } public DocumentInfoListPropertyDescriptor(DocumentInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentInfoList) + if (destType == typeof(string) && value is DocumentInfoList list) { // Return department and department role separated by comma. - return ((DocumentInfoList)value).Items.Count.ToString() + " Documents"; + return $"{list.Items.Count} Documents"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs index dbfedc0e..92a9ae77 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs @@ -9,12 +9,9 @@ // ======================================================================== using System; -using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; private int _DebugStatus; /// /// > 0 for Debug @@ -171,35 +165,13 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current DocumentPdf - protected override object GetIdValue() - { - return MyDocumentPdfUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base DocumentPdf.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentPdf - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } + protected override object GetIdValue() => MyDocumentPdfUnique; // Absolutely Unique ID + public override bool IsDirty => base.IsDirty; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] + public bool IsDirtyList(List list) => base.IsDirty; + public override bool IsValid => (IsNew && !IsDirty) || base.IsValid; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] + public bool IsValidList(List list) => (IsNew && !IsDirty) || base.IsValid; #endregion #region ValidationRules [NonSerialized] @@ -227,8 +199,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -240,80 +212,21 @@ namespace VEPROMS.CSLA.Library new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); // CSLATODO: Add other validation rules } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { - //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DebugStatus, ""); - //AuthorizationRules.AllowRead(TopRow, ""); - //AuthorizationRules.AllowRead(PageLength, ""); - //AuthorizationRules.AllowRead(LeftMargin, ""); - //AuthorizationRules.AllowRead(PageWidth, ""); - //AuthorizationRules.AllowRead(PageCount, ""); - //AuthorizationRules.AllowWrite(PageCount, ""); - //AuthorizationRules.AllowRead(DocPdf, ""); - //AuthorizationRules.AllowWrite(DocPdf, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // CSLATODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // CSLATODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // CSLATODO: CanDelete Authorization - //bool result = false; - //if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true; - //if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true; - //return result; - return true; - } - public static bool CanEditObject() - { - // CSLATODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; } #endregion #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } + public int CurrentEditLevel => EditLevel; private static int _DocumentPdfUnique = 0; - private static int DocumentPdfUnique - { get { return ++_DocumentPdfUnique; } } - private int _MyDocumentPdfUnique = DocumentPdfUnique; - public int MyDocumentPdfUnique // Absolutely Unique ID - Editable FK - { get { return _MyDocumentPdfUnique; } } - internal static DocumentPdf New(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) - { - return new DocumentPdf(debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount); - } - internal static DocumentPdf Get(SafeDataReader dr) - { - return new DocumentPdf(dr); - } + private static int DocumentPdfUnique => ++_DocumentPdfUnique; + private readonly int _MyDocumentPdfUnique = DocumentPdfUnique; + // Absolutely Unique ID - Editable FK + public int MyDocumentPdfUnique => _MyDocumentPdfUnique; + internal static DocumentPdf New(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) => new DocumentPdf(debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount); + internal static DocumentPdf Get(SafeDataReader dr) => new DocumentPdf(dr); public DocumentPdf() { MarkAsChild(); @@ -345,15 +258,11 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; ~DocumentPdf() { _CountFinalized++; @@ -392,33 +301,42 @@ namespace VEPROMS.CSLA.Library internal void Insert(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Pdf.Add(cn, myDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Pdf.Add(cn, myDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID); + } + MarkOld(); } internal void Update(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Pdf.Update(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Pdf.Update(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } internal void DeleteSelf(Document myDocument) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; + if (!IsDirty) return; // if we're new then don't update the database - if (this.IsNew) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - Pdf.Remove(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Pdf.Remove(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth); + } + MarkNew(); } #endregion // Standard Default Code #region extension - DocumentPdfExtension _DocumentPdfExtension = new DocumentPdfExtension(); + readonly DocumentPdfExtension _DocumentPdfExtension = new DocumentPdfExtension(); [Serializable()] partial class DocumentPdfExtension : extensionBase { @@ -427,14 +345,8 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -463,57 +375,13 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentPdf) + if (destType == typeof(string) && value is DocumentPdf docpdf) { // Return the ToString value - return ((DocumentPdf)value).ToString(); + return docpdf.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create DocumentPdfExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class DocumentPdf -// { -// partial class DocumentPdfExtension : 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, ""); -// } -// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowInstanceRead(Dbid, ""); -// } -// 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 */); -// } -// } -// } -//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdfs.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdfs.cs index 5753f137..1b8fad0c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdfs.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdfs.cs @@ -13,8 +13,6 @@ using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; -using System.Configuration; -using System.IO; using System.ComponentModel; using System.Collections.Generic; using Csla.Validation; @@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - // One To Many - public DocumentPdf this[int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public DocumentPdf this[int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public DocumentPdf GetItem(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + public new System.Collections.Generic.IList Items => base.Items; + public DocumentPdf GetItem(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) { foreach (DocumentPdf pdf in this) if (pdf.DebugStatus == debugStatus && pdf.TopRow == topRow && pdf.PageLength == pageLength && pdf.LeftMargin == leftMargin && pdf.PageWidth == pageWidth) @@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library if (!Contains(debugStatus, topRow, pageLength, leftMargin, pageWidth)) { DocumentPdf pdf = DocumentPdf.New(debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount); - this.Add(pdf); + Add(pdf); return pdf; } else @@ -108,23 +100,20 @@ namespace VEPROMS.CSLA.Library return true; return false; } - public override bool IsValid + public override bool IsValid => IsValidList(new List()); + public bool IsValidList(List list) { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - // run through all the child objects - // and if any are invalid then the - // collection is invalid - foreach (DocumentPdf child in this) - if (!child.IsValidList(list)) - { - //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); - return false; - } - return true; - } + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (DocumentPdf child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } #endregion #region ValidationRules public IVEHasBrokenRules HasBrokenRules @@ -142,20 +131,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static DocumentPdfs New() - { - return new DocumentPdfs(); - } - internal static DocumentPdfs Get(SafeDataReader dr) - { - return new DocumentPdfs(dr); - } - public static DocumentPdfs GetByDocID(int docID) + #endregion + #region Factory Methods + internal static DocumentPdfs New() => new DocumentPdfs(); + internal static DocumentPdfs Get(SafeDataReader dr) => new DocumentPdfs(dr); + public static DocumentPdfs GetByDocID(int docID) { try { @@ -166,11 +149,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on DocumentPdfs.GetByDocID", ex); } } - private DocumentPdfs() - { - MarkAsChild(); - } - internal DocumentPdfs(SafeDataReader dr) + private DocumentPdfs() => MarkAsChild(); + internal DocumentPdfs(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -179,16 +159,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~DocumentPdfs() + private static int IncrementCountCreated => ++_CountCreated; + private readonly int _CountWhenCreated = IncrementCountCreated; + public static int CountCreated => _CountCreated; + public static int CountNotDisposed => _CountCreated - _CountDisposed; + public static int CountNotFinalized => _CountCreated - _CountFinalized; + ~DocumentPdfs() { _CountFinalized++; } @@ -203,19 +179,16 @@ namespace VEPROMS.CSLA.Library // called to load data from the database private void Fetch(SafeDataReader dr) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; while (dr.Read()) - this.Add(DocumentPdf.Get(dr)); - this.RaiseListChangedEvents = true; + Add(DocumentPdf.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class DocIDCriteria { - public DocIDCriteria(int docID) - { - _DocID = docID; - } - private int _DocID; + public DocIDCriteria(int docID) => _DocID = docID; + private int _DocID; public int DocID { get { return _DocID; } @@ -224,7 +197,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(DocIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentPdfs.DataPortal_FetchDocID", GetHashCode()); try { @@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new DocumentPdf(dr)); + while (dr.Read()) Add(new DocumentPdf(dr)); } } } @@ -248,11 +221,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentPdfs.DataPortal_FetchDocID", ex); throw new DbCslaException("DocumentPdfs.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(Document document) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -271,49 +244,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - public PropertyDescriptorCollection GetProperties() + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() => TypeDescriptor.GetClassName(this, true); + public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true); + public String GetComponentName() => TypeDescriptor.GetComponentName(this, true); + public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true); + public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true); + public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true); + public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true); + public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true); + public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true); + public object GetPropertyOwner(PropertyDescriptor pd) => this; + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties(); + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() { // Create a collection object to hold property descriptors PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list - for (int i = 0; i < this.Items.Count; i++) + for (int i = 0; i < Items.Count; i++) { // Create a property descriptor for the item and add to the property descriptor collection DocumentPdfsPropertyDescriptor pd = new DocumentPdfsPropertyDescriptor(this, i); @@ -330,7 +292,6 @@ namespace VEPROMS.CSLA.Library /// public partial class DocumentPdfsPropertyDescriptor : vlnListPropertyDescriptor { - private DocumentPdf Item { get { return (DocumentPdf)_Item; } } public DocumentPdfsPropertyDescriptor(DocumentPdfs collection, int index) : base(collection, index) { ;} } #endregion @@ -339,10 +300,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is DocumentPdfs) + if (destType == typeof(string) && value is DocumentPdfs pdfs) { // Return department and department role separated by comma. - return ((DocumentPdfs)value).Items.Count.ToString() + " Pdfs"; + return $"{pdfs.Items.Count} Pdfs"; } return base.ConvertTo(context, culture, value, destType); }