From d238d6aed2dfb5f4bbd5cb4f5fb4d974f8dc8939 Mon Sep 17 00:00:00 2001 From: mschill Date: Fri, 11 Sep 2026 16:03:51 -0400 Subject: [PATCH] CSLA - R - Group 1 --- PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs | 434 ++++++------------ .../Generated/RODbDROUsage.cs | 222 ++------- .../Generated/RODbDROUsages.cs | 181 +++----- .../Generated/RODbInfo.cs | 84 +--- .../Generated/RODbInfoList.cs | 126 ++--- .../Generated/RODbROFst.cs | 222 ++------- .../Generated/RODbROFsts.cs | 181 +++----- .../Generated/RODbROImage.cs | 224 ++------- .../Generated/RODbROImages.cs | 181 +++----- .../Generated/RODbRoUsage.cs | 222 ++------- .../Generated/RODbRoUsages.cs | 181 +++----- PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs | 415 ++++++----------- .../Generated/ROFstAssociation.cs | 211 ++------- .../Generated/ROFstAssociations.cs | 181 +++----- .../Generated/ROFstFigure.cs | 211 ++------- .../Generated/ROFstFigures.cs | 181 +++----- .../Generated/ROFstInfo.cs | 108 +---- .../Generated/ROFstInfoList.cs | 139 ++---- .../VEPROMS.CSLA.Library/Generated/ROImage.cs | 419 ++++++----------- .../Generated/ROImageFigure.cs | 211 ++------- .../Generated/ROImageFigures.cs | 181 +++----- .../Generated/ROImageInfo.cs | 88 +--- .../Generated/ROImageInfoList.cs | 139 ++---- .../Generated/Revision.cs | 416 +++++------------ .../Generated/RevisionCheck.cs | 211 ++------- .../Generated/RevisionChecks.cs | 174 +++---- .../Generated/RevisionInfo.cs | 84 +--- .../Generated/RevisionInfoList.cs | 126 ++--- .../Generated/RevisionVersion.cs | 195 ++------ .../Generated/RevisionVersions.cs | 181 +++----- PROMS/VEPROMS.CSLA.Library/Generated/Role.cs | 396 +++++----------- .../Generated/RoleAssignment.cs | 224 ++------- .../Generated/RoleAssignments.cs | 181 +++----- 33 files changed, 2101 insertions(+), 4829 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs index 5ffab757..68ca2180 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODb.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; @@ -108,6 +106,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(RODb rODb) { @@ -117,7 +116,9 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(rODb)) _CacheList.Remove(rODb); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByFolderPath = new Dictionary>(); private static void ConvertListToDictionary() { @@ -152,15 +153,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 _nextRODbID = -1; - public static int NextRODbID - { - get { return _nextRODbID--; } - } + public static int NextRODbID => _nextRODbID--; private int _RODbID; [System.ComponentModel.DataObjectField(true, true)] public int RODbID @@ -325,10 +320,7 @@ namespace VEPROMS.CSLA.Library return _RODbDROUsages; } } - public void Reset_RODbDROUsages() - { - _RODbDROUsageCount = -1; - } + public void Reset_RODbDROUsages() => _RODbDROUsageCount = -1; private int _RODbROFstCount = 0; /// /// Count of RODbROFsts for this RODb @@ -360,10 +352,7 @@ namespace VEPROMS.CSLA.Library return _RODbROFsts; } } - public void Reset_RODbROFsts() - { - _RODbROFstCount = -1; - } + public void Reset_RODbROFsts() => _RODbROFstCount = -1; private int _RODbROImageCount = 0; /// /// Count of RODbROImages for this RODb @@ -395,10 +384,7 @@ namespace VEPROMS.CSLA.Library return _RODbROImages; } } - public void Reset_RODbROImages() - { - _RODbROImageCount = -1; - } + public void Reset_RODbROImages() => _RODbROImageCount = -1; private int _RODbRoUsageCount = 0; /// /// Count of RODbRoUsages for this RODb @@ -430,10 +416,7 @@ namespace VEPROMS.CSLA.Library return _RODbRoUsages; } } - public void Reset_RODbRoUsages() - { - _RODbRoUsageCount = -1; - } + public void Reset_RODbRoUsages() => _RODbRoUsageCount = -1; public override bool IsDirty { get @@ -448,37 +431,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_RODbDROUsages == null ? false : _RODbDROUsages.IsDirtyList(list)) || (_RODbROFsts == null ? false : _RODbROFsts.IsDirtyList(list)) || (_RODbROImages == null ? false : _RODbROImages.IsDirtyList(list)) || (_RODbRoUsages == null ? false : _RODbRoUsages.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_RODbDROUsages != null && _RODbDROUsages.IsDirtyList(list)) || (_RODbROFsts != null && _RODbROFsts.IsDirtyList(list)) || (_RODbROImages != null && _RODbROImages.IsDirtyList(list)) || (_RODbRoUsages != null && _RODbRoUsages.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) && (_RODbDROUsages == null ? true : _RODbDROUsages.IsValidList(list)) && (_RODbROFsts == null ? true : _RODbROFsts.IsValidList(list)) && (_RODbROImages == null ? true : _RODbROImages.IsValidList(list)) && (_RODbRoUsages == null ? true : _RODbRoUsages.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_RODbDROUsages == null || _RODbDROUsages.IsValidList(list)) && (_RODbROFsts == null || _RODbROFsts.IsValidList(list)) && (_RODbROImages == null || _RODbROImages.IsValidList(list)) && (_RODbRoUsages == null || _RODbRoUsages.IsValidList(list)); } - // CSLATODO: Replace base RODb.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODb - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check RODb.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 RODb - protected override object GetIdValue() - { - return MyRODbUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyRODbUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -510,8 +478,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() @@ -548,35 +516,11 @@ namespace VEPROMS.CSLA.Library _RODbExtension.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(RODbID, ""); - //AuthorizationRules.AllowRead(ROName, ""); - //AuthorizationRules.AllowRead(FolderPath, ""); - //AuthorizationRules.AllowRead(DBConnectionString, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ROName, ""); - //AuthorizationRules.AllowWrite(FolderPath, ""); - //AuthorizationRules.AllowWrite(DBConnectionString, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); _RODbExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -584,58 +528,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _RODbExtension.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 += _RODbDROUsageCount; - usedByCount += _RODbROFstCount; - usedByCount += _RODbROImageCount; - usedByCount += _RODbRoUsageCount; - 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 _RODbUnique = 0; - protected static int RODbUnique - { get { return ++_RODbUnique; } } - private int _MyRODbUnique = RODbUnique; - public int MyRODbUnique // Absolutely Unique ID - Editable - { get { return _MyRODbUnique; } } + protected static int RODbUnique => ++_RODbUnique; + private readonly int _MyRODbUnique = RODbUnique; + // Absolutely Unique ID - Editable + public int MyRODbUnique => _MyRODbUnique; protected RODb() {/* require use of factory methods */ AddToCache(this); @@ -644,15 +544,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; ~RODb() { _CountFinalized++; @@ -689,8 +585,6 @@ namespace VEPROMS.CSLA.Library } public static RODb New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RODb"); try { return DataPortal.Create(); @@ -762,8 +656,6 @@ namespace VEPROMS.CSLA.Library } public static RODb Get(int rODbID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RODb"); try { RODb tmp = GetCachedByPrimaryKey(rODbID); @@ -786,8 +678,6 @@ namespace VEPROMS.CSLA.Library } public static RODb GetByFolderPath(string folderPath) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RODb"); try { RODb tmp = GetCachedByFolderPath(folderPath); @@ -813,14 +703,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new RODb(dr); return null; } - internal RODb(SafeDataReader dr) - { - ReadData(dr); - } + internal RODb(SafeDataReader dr) => ReadData(dr); public static void Delete(int rODbID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RODb"); try { DataPortal.Delete(new PKCriteria(rODbID)); @@ -832,12 +717,6 @@ namespace VEPROMS.CSLA.Library } public override RODb Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RODb"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RODb"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a RODb"); try { BuildRefreshList(); @@ -857,24 +736,16 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - public PKCriteria(int rODbID) - { - _RODbID = rODbID; - } + private readonly int _RODbID; + public int RODbID => _RODbID; + public PKCriteria(int rODbID) => _RODbID = rODbID; } [Serializable()] private class FolderPathCriteria { - private string _FolderPath; - public string FolderPath - { get { return _FolderPath; } } - public FolderPathCriteria(string folderPath) - { - _FolderPath = folderPath; - } + private readonly string _FolderPath; + public string FolderPath => _FolderPath; + public FolderPathCriteria(string folderPath) => _FolderPath = folderPath; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -1025,41 +896,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 = "addRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROName", _ROName); - cm.Parameters.AddWithValue("@FolderPath", _FolderPath); - cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); - 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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); - param_RODbID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RODbID); - 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 - _RODbID = (int)cm.Parameters["@newRODbID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROName", _ROName); + cm.Parameters.AddWithValue("@FolderPath", _FolderPath); + cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); + 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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_RODbID); + 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 + _RODbID = (int)cm.Parameters["@newRODbID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbDROUsages != null) _RODbDROUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); + _RODbRoUsages?.Update(this); + _RODbDROUsages?.Update(this); + _RODbROFsts?.Update(this); + _RODbROImages?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -1088,11 +966,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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); - param_RODbID.Direction = ParameterDirection.Output; + SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_RODbID); - 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(); @@ -1137,39 +1019,44 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.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 = "updateRODb"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RODbID", _RODbID); - cm.Parameters.AddWithValue("@ROName", _ROName); - cm.Parameters.AddWithValue("@FolderPath", _FolderPath); - cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); - 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 = "updateRODb"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RODbID", _RODbID); + cm.Parameters.AddWithValue("@ROName", _ROName); + cm.Parameters.AddWithValue("@FolderPath", _FolderPath); + cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); + 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 (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbDROUsages != null) _RODbDROUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); + _RODbRoUsages?.Update(this); + _RODbDROUsages?.Update(this); + _RODbROFsts?.Update(this); + _RODbROImages?.Update(this); } catch (Exception ex) { @@ -1180,20 +1067,23 @@ 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 = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID); - else - _LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID); + else + _LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbDROUsages != null) _RODbDROUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); + _RODbRoUsages?.Update(this); + _RODbDROUsages?.Update(this); + _RODbROFsts?.Update(this); + _RODbROImages?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] public static byte[] Update(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID, ref byte[] lastChanged) @@ -1216,8 +1106,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(); @@ -1302,16 +1194,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _RODbID; + private readonly int _RODbID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rODbID) - { - _RODbID = rODbID; - } + public bool Exists => _exists; + public ExistsCommand(int rODbID) => _RODbID = rODbID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Execute", GetHashCode()); @@ -1327,7 +1213,7 @@ namespace VEPROMS.CSLA.Library cm.CommandText = "existsRODb"; cm.Parameters.AddWithValue("@RODbID", _RODbID); int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); + _exists = count > 0; } } } @@ -1341,7 +1227,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - RODbExtension _RODbExtension = new RODbExtension(); + readonly RODbExtension _RODbExtension = new RODbExtension(); [Serializable()] partial class RODbExtension : extensionBase { @@ -1350,14 +1236,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) { @@ -1386,57 +1266,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 RODb) + if (destType == typeof(string) && value is RODb db) { // Return the ToString value - return ((RODb)value).ToString(); + return db.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RODbExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RODb -// { -// partial class RODbExtension : 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/RODbDROUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.cs index a49b9cfe..0702cf4a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.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 @@ -238,19 +232,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RODbDROUsage - protected override object GetIdValue() - { - return MyRODbDROUsageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbDROUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbDROUsage - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyRODbDROUsageUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -265,18 +247,15 @@ 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)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyDocument != null && _MyDocument.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) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocument == null || _MyDocument.IsValidList(list)); } #endregion #region ValidationRules @@ -306,8 +285,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() @@ -337,78 +316,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(DocID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //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 _RODbDROUsageUnique = 0; - private static int RODbDROUsageUnique - { get { return ++_RODbDROUsageUnique; } } - private int _MyRODbDROUsageUnique = RODbDROUsageUnique; - public int MyRODbDROUsageUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbDROUsageUnique; } } - internal static RODbDROUsage New(string roid) - { - return new RODbDROUsage(roid); - } - internal static RODbDROUsage Get(SafeDataReader dr) - { - return new RODbDROUsage(dr); - } + private static int RODbDROUsageUnique => ++_RODbDROUsageUnique; + private readonly int _MyRODbDROUsageUnique = RODbDROUsageUnique; + // Absolutely Unique ID - Editable FK + public int MyRODbDROUsageUnique => _MyRODbDROUsageUnique; + internal static RODbDROUsage New(string roid) => new RODbDROUsage(roid); + internal static RODbDROUsage Get(SafeDataReader dr) => new RODbDROUsage(dr); public RODbDROUsage() { MarkAsChild(); @@ -438,15 +361,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; ~RODbDROUsage() { _CountFinalized++; @@ -489,33 +408,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(RODb myRODb) { // 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(RODb myRODb) { // 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, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = DROUsage.Update(cn, ref _DROUsageID, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(RODb myRODb) { // 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 - RODbDROUsageExtension _RODbDROUsageExtension = new RODbDROUsageExtension(); + readonly RODbDROUsageExtension _RODbDROUsageExtension = new RODbDROUsageExtension(); [Serializable()] partial class RODbDROUsageExtension : extensionBase { @@ -524,18 +453,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) { @@ -564,61 +484,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 RODbDROUsage) + if (destType == typeof(string) && value is RODbDROUsage usage) { // Return the ToString value - return ((RODbDROUsage)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 RODbDROUsageExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RODbDROUsage -// { -// partial class RODbDROUsageExtension : 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/RODbDROUsages.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsages.cs index b0c47e23..9d744aca 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsages.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsages.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 RODbDROUsage this[DROUsage myDROUsage] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RODbDROUsage 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 RODbDROUsage GetItem(DROUsage myDROUsage) + public new System.Collections.Generic.IList Items => base.Items; + public RODbDROUsage GetItem(DROUsage myDROUsage) { foreach (RODbDROUsage dROUsage in this) if (dROUsage.DROUsageID == myDROUsage.DROUsageID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public RODbDROUsage Add(string roid) // One to Many { RODbDROUsage dROUsage = RODbDROUsage.New(roid); - 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 (RODbDROUsage 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 (RODbDROUsage 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 RODbDROUsages New() - { - return new RODbDROUsages(); - } - internal static RODbDROUsages Get(SafeDataReader dr) - { - return new RODbDROUsages(dr); - } - public static RODbDROUsages GetByRODbID(int rODbID) + #endregion + #region Factory Methods + internal static RODbDROUsages New() => new RODbDROUsages(); + internal static RODbDROUsages Get(SafeDataReader dr) => new RODbDROUsages(dr); + public static RODbDROUsages GetByRODbID(int rODbID) { try { @@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RODbDROUsages.GetByRODbID", ex); } } - private RODbDROUsages() - { - MarkAsChild(); - } - internal RODbDROUsages(SafeDataReader dr) + private RODbDROUsages() => MarkAsChild(); + internal RODbDROUsages(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; } } - ~RODbDROUsages() + 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; + ~RODbDROUsages() { _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(RODbDROUsage.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RODbDROUsage.Get(dr)); + 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; } @@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbDROUsages.DataPortal_FetchRODbID", 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 RODbDROUsage(dr)); + while (dr.Read()) Add(new RODbDROUsage(dr)); } } } @@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbDROUsages.DataPortal_FetchRODbID", ex); throw new DbCslaException("RODbDROUsages.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(RODb rODb) { - 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 RODbDROUsagesPropertyDescriptor pd = new RODbDROUsagesPropertyDescriptor(this, i); @@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RODbDROUsagesPropertyDescriptor : vlnListPropertyDescriptor { - private RODbDROUsage Item { get { return (RODbDROUsage)_Item; } } public RODbDROUsagesPropertyDescriptor(RODbDROUsages 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 RODbDROUsages) + if (destType == typeof(string) && value is RODbDROUsages usages) { // Return department and department role separated by comma. - return ((RODbDROUsages)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/RODbInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.cs index 2f0fc1b8..89042367 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.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 RODbInfo : ReadOnlyBase, IDisposable { public event RODbInfoEvent 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(RODbInfo rODbInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(rODbInfo)) _CacheList.Remove(rODbInfo); // 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 RODb _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _RODbID; [System.ComponentModel.DataObjectField(true, true)] public int RODbID @@ -306,32 +290,19 @@ namespace VEPROMS.CSLA.Library foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) tmp._RODbRoUsageCount = -1; // This will cause the data to be requeried } - // CSLATODO: Replace base RODbInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check RODbInfo.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 RODbInfo - protected override object GetIdValue() - { - return MyRODbInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyRODbInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _RODbInfoUnique = 0; - private static int RODbInfoUnique - { get { return ++_RODbInfoUnique; } } - private int _MyRODbInfoUnique = RODbInfoUnique; - public int MyRODbInfoUnique // Absolutely Unique ID - Info - { get { return _MyRODbInfoUnique; } } + private static int RODbInfoUnique => ++_RODbInfoUnique; + private readonly int _MyRODbInfoUnique = RODbInfoUnique; + // Absolutely Unique ID - Info + public int MyRODbInfoUnique => _MyRODbInfoUnique; protected RODbInfo() {/* require use of factory methods */ AddToCache(this); @@ -340,15 +311,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; ~RODbInfo() { _CountFinalized++; @@ -365,10 +332,7 @@ namespace VEPROMS.CSLA.Library if (listRODbInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list } - public virtual RODb Get() - { - return _Editable = RODb.Get(_RODbID); - } + public virtual RODb Get() => _Editable = RODb.Get(_RODbID); public static void Refresh(RODb tmp) { string key = tmp.RODbID.ToString(); @@ -390,8 +354,6 @@ namespace VEPROMS.CSLA.Library } public static RODbInfo Get(int rODbID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a RODb"); try { RODbInfo tmp = GetCachedByPrimaryKey(rODbID); @@ -430,13 +392,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - public PKCriteria(int rODbID) - { - _RODbID = rODbID; - } + private readonly int _RODbID; + public int RODbID => _RODbID; + public PKCriteria(int rODbID) => _RODbID = rODbID; } private void ReadData(SafeDataReader dr) { @@ -501,7 +459,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - RODbInfoExtension _RODbInfoExtension = new RODbInfoExtension(); + readonly RODbInfoExtension _RODbInfoExtension = new RODbInfoExtension(); [Serializable()] partial class RODbInfoExtension : extensionBase { } [Serializable()] @@ -517,10 +475,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 RODbInfo) + if (destType == typeof(string) && value is RODbInfo info) { // Return the ToString value - return ((RODbInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfoList.cs index fe4949a4..1e99fbdc 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfoList.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 (RODbInfo 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; } } - ~RODbInfoList() + 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; + ~RODbInfoList() { _CountFinalized++; } @@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RODbInfoList.Get", ex); } } - /// - /// Reset the list of all RODbInfo. - /// - public static void Reset() - { - _RODbInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static RODbInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on RODbInfoList.Get", ex); - // } - //} - private RODbInfoList() + /// + /// Reset the list of all RODbInfo. + /// + public static void Reset() => _RODbInfoList = null; + private RODbInfoList() { /* 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}] RODbInfoList.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 RODbInfo(dr)); + while (dr.Read()) Add(new RODbInfo(dr)); IsReadOnly = true; } } @@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfoList.DataPortal_Fetch", ex); throw new DbCslaException("RODbInfoList.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 RODbInfoListPropertyDescriptor pd = new RODbInfoListPropertyDescriptor(this, i); @@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RODbInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private RODbInfo Item { get { return (RODbInfo)_Item; } } public RODbInfoListPropertyDescriptor(RODbInfoList 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 RODbInfoList) + if (destType == typeof(string) && value is RODbInfoList list) { // Return department and department role separated by comma. - return ((RODbInfoList)value).Items.Count.ToString() + " RODbs"; + return $"{list.Items.Count} RODbs"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs index 5ab70e94..b27c542d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.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 _ROFstID; [System.ComponentModel.DataObjectField(true, true)] public int ROFstID @@ -138,35 +132,13 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RODbROFst - protected override object GetIdValue() - { - return MyRODbROFstUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbROFst - //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() => MyRODbROFstUnique; // 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] @@ -194,8 +166,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() @@ -210,76 +182,22 @@ namespace VEPROMS.CSLA.Library new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); // CSLATODO: Add other validation rules } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(ROLookup, ""); - //AuthorizationRules.AllowWrite(ROLookup, ""); - //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 _RODbROFstUnique = 0; - private static int RODbROFstUnique - { get { return ++_RODbROFstUnique; } } - private int _MyRODbROFstUnique = RODbROFstUnique; - public int MyRODbROFstUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbROFstUnique; } } - internal static RODbROFst New(byte[] rOLookup) - { - return new RODbROFst(rOLookup); - } - internal static RODbROFst Get(SafeDataReader dr) - { - return new RODbROFst(dr); - } + private static int RODbROFstUnique => ++_RODbROFstUnique; + private readonly int _MyRODbROFstUnique = RODbROFstUnique; + // Absolutely Unique ID - Editable FK + public int MyRODbROFstUnique => _MyRODbROFstUnique; + internal static RODbROFst New(byte[] rOLookup) => new RODbROFst(rOLookup); + internal static RODbROFst Get(SafeDataReader dr) => new RODbROFst(dr); public RODbROFst() { MarkAsChild(); @@ -307,15 +225,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; ~RODbROFst() { _CountFinalized++; @@ -350,33 +264,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROLookup, _Config, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROLookup, _Config, _DTS, _UserID); + } + MarkOld(); } internal void Update(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb.RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb.RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(RODb myRODb) { // 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"]; - ROFst.Remove(cn, _ROFstID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + ROFst.Remove(cn, _ROFstID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); + readonly RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); [Serializable()] partial class RODbROFstExtension : extensionBase { @@ -385,14 +309,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) { @@ -421,57 +339,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 RODbROFst) + if (destType == typeof(string) && value is RODbROFst fst) { // Return the ToString value - return ((RODbROFst)value).ToString(); + return fst.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RODbROFstExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RODbROFst -// { -// partial class RODbROFstExtension : 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/RODbROFsts.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFsts.cs index 6ae37450..b5acd815 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFsts.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFsts.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 RODbROFst this[ROFst myROFst] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RODbROFst this[ROFst myROFst] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public RODbROFst GetItem(ROFst myROFst) + public new System.Collections.Generic.IList Items => base.Items; + public RODbROFst GetItem(ROFst myROFst) { foreach (RODbROFst rOFst in this) if (rOFst.ROFstID == myROFst.ROFstID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public RODbROFst Add(byte[] rOLookup) // One to Many { RODbROFst rOFst = RODbROFst.New(rOLookup); - this.Add(rOFst); + Add(rOFst); return rOFst; } public void Remove(ROFst myROFst) @@ -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 (RODbROFst 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 (RODbROFst 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(DateTime dts) { foreach (RODbROFst rOFst in this) @@ -151,20 +140,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static RODbROFsts New() - { - return new RODbROFsts(); - } - internal static RODbROFsts Get(SafeDataReader dr) - { - return new RODbROFsts(dr); - } - public static RODbROFsts GetByRODbID(int rODbID) + #endregion + #region Factory Methods + internal static RODbROFsts New() => new RODbROFsts(); + internal static RODbROFsts Get(SafeDataReader dr) => new RODbROFsts(dr); + public static RODbROFsts GetByRODbID(int rODbID) { try { @@ -175,11 +158,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RODbROFsts.GetByRODbID", ex); } } - private RODbROFsts() - { - MarkAsChild(); - } - internal RODbROFsts(SafeDataReader dr) + private RODbROFsts() => MarkAsChild(); + internal RODbROFsts(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -188,16 +168,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; } } - ~RODbROFsts() + 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; + ~RODbROFsts() { _CountFinalized++; } @@ -212,19 +188,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(RODbROFst.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RODbROFst.Get(dr)); + 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; } @@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROFsts.DataPortal_FetchRODbID", GetHashCode()); try { @@ -247,7 +220,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new RODbROFst(dr)); + while (dr.Read()) Add(new RODbROFst(dr)); } } } @@ -257,11 +230,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROFsts.DataPortal_FetchRODbID", ex); throw new DbCslaException("RODbROFsts.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(RODb rODb) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -280,49 +253,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 RODbROFstsPropertyDescriptor pd = new RODbROFstsPropertyDescriptor(this, i); @@ -339,7 +301,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RODbROFstsPropertyDescriptor : vlnListPropertyDescriptor { - private RODbROFst Item { get { return (RODbROFst)_Item; } } public RODbROFstsPropertyDescriptor(RODbROFsts collection, int index) : base(collection, index) { ;} } #endregion @@ -348,10 +309,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 RODbROFsts) + if (destType == typeof(string) && value is RODbROFsts fsts) { // Return department and department role separated by comma. - return ((RODbROFsts)value).Items.Count.ToString() + " ROFsts"; + return $"{fsts.Items.Count} ROFsts"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs index 3107a9e3..04b4003d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.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 _ImageID; [System.ComponentModel.DataObjectField(true, true)] public int ImageID @@ -157,35 +151,13 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RODbROImage - protected override object GetIdValue() - { - return MyRODbROImageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbROImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbROImage - //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() => MyRODbROImageUnique; // 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] @@ -213,8 +185,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() @@ -234,78 +206,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(ImageID, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowRead(Content, ""); - //AuthorizationRules.AllowWrite(Content, ""); - //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 _RODbROImageUnique = 0; - private static int RODbROImageUnique - { get { return ++_RODbROImageUnique; } } - private int _MyRODbROImageUnique = RODbROImageUnique; - public int MyRODbROImageUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbROImageUnique; } } - internal static RODbROImage New(string fileName, byte[] content) - { - return new RODbROImage(fileName, content); - } - internal static RODbROImage Get(SafeDataReader dr) - { - return new RODbROImage(dr); - } + private static int RODbROImageUnique => ++_RODbROImageUnique; + private readonly int _MyRODbROImageUnique = RODbROImageUnique; + // Absolutely Unique ID - Editable FK + public int MyRODbROImageUnique => _MyRODbROImageUnique; + internal static RODbROImage New(string fileName, byte[] content) => new RODbROImage(fileName, content); + internal static RODbROImage Get(SafeDataReader dr) => new RODbROImage(dr); public RODbROImage() { MarkAsChild(); @@ -334,15 +250,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; ~RODbROImage() { _CountFinalized++; @@ -378,33 +290,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROImage.Add(cn, ref _ImageID, myRODb, _FileName, _Content, _Config, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = ROImage.Add(cn, ref _ImageID, myRODb, _FileName, _Content, _Config, _DTS, _UserID); + } + MarkOld(); } internal void Update(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROImage.Update(cn, ref _ImageID, myRODb.RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = ROImage.Update(cn, ref _ImageID, myRODb.RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(RODb myRODb) { // 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"]; - ROImage.Remove(cn, _ImageID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + ROImage.Remove(cn, _ImageID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - RODbROImageExtension _RODbROImageExtension = new RODbROImageExtension(); + readonly RODbROImageExtension _RODbROImageExtension = new RODbROImageExtension(); [Serializable()] partial class RODbROImageExtension : extensionBase { @@ -413,14 +335,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) { @@ -449,57 +365,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 RODbROImage) + if (destType == typeof(string) && value is RODbROImage image) { // Return the ToString value - return ((RODbROImage)value).ToString(); + return image.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RODbROImageExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RODbROImage -// { -// partial class RODbROImageExtension : 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/RODbROImages.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImages.cs index e7fe25fe..d2bff599 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImages.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImages.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 RODbROImage this[ROImage myROImage] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RODbROImage this[ROImage myROImage] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public RODbROImage GetItem(ROImage myROImage) + public new System.Collections.Generic.IList Items => base.Items; + public RODbROImage GetItem(ROImage myROImage) { foreach (RODbROImage rOImage in this) if (rOImage.ImageID == myROImage.ImageID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public RODbROImage Add(string fileName, byte[] content) // One to Many { RODbROImage rOImage = RODbROImage.New(fileName, content); - this.Add(rOImage); + Add(rOImage); return rOImage; } public void Remove(ROImage myROImage) @@ -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 (RODbROImage 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 (RODbROImage child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } public bool Contains(string fileName, DateTime dts) { foreach (RODbROImage rOImage in this) @@ -151,20 +140,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static RODbROImages New() - { - return new RODbROImages(); - } - internal static RODbROImages Get(SafeDataReader dr) - { - return new RODbROImages(dr); - } - public static RODbROImages GetByRODbID(int rODbID) + #endregion + #region Factory Methods + internal static RODbROImages New() => new RODbROImages(); + internal static RODbROImages Get(SafeDataReader dr) => new RODbROImages(dr); + public static RODbROImages GetByRODbID(int rODbID) { try { @@ -175,11 +158,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RODbROImages.GetByRODbID", ex); } } - private RODbROImages() - { - MarkAsChild(); - } - internal RODbROImages(SafeDataReader dr) + private RODbROImages() => MarkAsChild(); + internal RODbROImages(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -188,16 +168,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; } } - ~RODbROImages() + 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; + ~RODbROImages() { _CountFinalized++; } @@ -212,19 +188,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(RODbROImage.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RODbROImage.Get(dr)); + 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; } @@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROImages.DataPortal_FetchRODbID", GetHashCode()); try { @@ -247,7 +220,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new RODbROImage(dr)); + while (dr.Read()) Add(new RODbROImage(dr)); } } } @@ -257,11 +230,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROImages.DataPortal_FetchRODbID", ex); throw new DbCslaException("RODbROImages.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(RODb rODb) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -280,49 +253,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 RODbROImagesPropertyDescriptor pd = new RODbROImagesPropertyDescriptor(this, i); @@ -339,7 +301,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RODbROImagesPropertyDescriptor : vlnListPropertyDescriptor { - private RODbROImage Item { get { return (RODbROImage)_Item; } } public RODbROImagesPropertyDescriptor(RODbROImages collection, int index) : base(collection, index) { ;} } #endregion @@ -348,10 +309,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 RODbROImages) + if (destType == typeof(string) && value is RODbROImages images) { // Return department and department role separated by comma. - return ((RODbROImages)value).Items.Count.ToString() + " ROImages"; + return $"{images.Items.Count} ROImages"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs index 3ea92f4e..b767c969 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.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 _ROUsageID; [System.ComponentModel.DataObjectField(true, true)] public int ROUsageID @@ -238,19 +232,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RODbRoUsage - protected override object GetIdValue() - { - return MyRODbRoUsageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbRoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbRoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyRODbRoUsageUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -265,18 +247,15 @@ 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)); } #endregion #region ValidationRules @@ -306,8 +285,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() @@ -337,78 +316,22 @@ namespace VEPROMS.CSLA.Library } return true; } - // Sample data comparison validation rule - //private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e) - //{ - // if (_started > _ended) - // { - // e.Description = "Start date can't be after end date"; - // return false; - // } - // else - // return true; - //} #endregion #region Authorization Rules protected override void AddAuthorizationRules() { //CSLATODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROUsageID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //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 _RODbRoUsageUnique = 0; - private static int RODbRoUsageUnique - { get { return ++_RODbRoUsageUnique; } } - private int _MyRODbRoUsageUnique = RODbRoUsageUnique; - public int MyRODbRoUsageUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbRoUsageUnique; } } - internal static RODbRoUsage New(string roid) - { - return new RODbRoUsage(roid); - } - internal static RODbRoUsage Get(SafeDataReader dr) - { - return new RODbRoUsage(dr); - } + private static int RODbRoUsageUnique => ++_RODbRoUsageUnique; + private readonly int _MyRODbRoUsageUnique = RODbRoUsageUnique; + // Absolutely Unique ID - Editable FK + public int MyRODbRoUsageUnique => _MyRODbRoUsageUnique; + internal static RODbRoUsage New(string roid) => new RODbRoUsage(roid); + internal static RODbRoUsage Get(SafeDataReader dr) => new RODbRoUsage(dr); public RODbRoUsage() { MarkAsChild(); @@ -438,15 +361,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; ~RODbRoUsage() { _CountFinalized++; @@ -489,33 +408,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, myRODb); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, myRODb); + } + MarkOld(); } internal void Update(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(RODb myRODb) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; + if (!IsDirty) return; // if we're new then don't update the database - if (this.IsNew) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - RoUsage.Remove(cn, _ROUsageID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + RoUsage.Remove(cn, _ROUsageID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - RODbRoUsageExtension _RODbRoUsageExtension = new RODbRoUsageExtension(); + readonly RODbRoUsageExtension _RODbRoUsageExtension = new RODbRoUsageExtension(); [Serializable()] partial class RODbRoUsageExtension : extensionBase { @@ -524,18 +453,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual int DefaultContentID => 0; + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -564,61 +484,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 RODbRoUsage) + if (destType == typeof(string) && value is RODbRoUsage usage) { // Return the ToString value - return ((RODbRoUsage)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 RODbRoUsageExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RODbRoUsage -// { -// partial class RODbRoUsageExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual int DefaultContentID -// { -// get { return 0; } -// } -// public virtual DateTime DefaultDTS -// { -// get { return DateTime.Now; } -// } -// public virtual string DefaultUserID -// { -// get { return Environment.UserName.ToUpper(); } -// } -// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowRead(Dbid, ""); -// } -// 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/RODbRoUsages.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsages.cs index 51f120b4..224cf377 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsages.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsages.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 RODbRoUsage this[RoUsage myRoUsage] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RODbRoUsage this[RoUsage myRoUsage] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public RODbRoUsage GetItem(RoUsage myRoUsage) + public new System.Collections.Generic.IList Items => base.Items; + public RODbRoUsage GetItem(RoUsage myRoUsage) { foreach (RODbRoUsage roUsage in this) if (roUsage.ROUsageID == myRoUsage.ROUsageID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public RODbRoUsage Add(string roid) // One to Many { RODbRoUsage roUsage = RODbRoUsage.New(roid); - this.Add(roUsage); + Add(roUsage); return roUsage; } public void Remove(RoUsage myRoUsage) @@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library return true; return false; } - public override bool IsValid + public override bool IsValid => IsValidList(new List()); + 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 (RODbRoUsage 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 (RODbRoUsage 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 RODbRoUsages New() - { - return new RODbRoUsages(); - } - internal static RODbRoUsages Get(SafeDataReader dr) - { - return new RODbRoUsages(dr); - } - public static RODbRoUsages GetByRODbID(int rODbID) + #endregion + #region Factory Methods + internal static RODbRoUsages New() => new RODbRoUsages(); + internal static RODbRoUsages Get(SafeDataReader dr) => new RODbRoUsages(dr); + public static RODbRoUsages GetByRODbID(int rODbID) { try { @@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RODbRoUsages.GetByRODbID", ex); } } - private RODbRoUsages() - { - MarkAsChild(); - } - internal RODbRoUsages(SafeDataReader dr) + private RODbRoUsages() => MarkAsChild(); + internal RODbRoUsages(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; } } - ~RODbRoUsages() + 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; + ~RODbRoUsages() { _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(RODbRoUsage.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RODbRoUsage.Get(dr)); + 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; } @@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbRoUsages.DataPortal_FetchRODbID", 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 RODbRoUsage(dr)); + while (dr.Read()) Add(new RODbRoUsage(dr)); } } } @@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbRoUsages.DataPortal_FetchRODbID", ex); throw new DbCslaException("RODbRoUsages.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(RODb rODb) { - 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 RODbRoUsagesPropertyDescriptor pd = new RODbRoUsagesPropertyDescriptor(this, i); @@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RODbRoUsagesPropertyDescriptor : vlnListPropertyDescriptor { - private RODbRoUsage Item { get { return (RODbRoUsage)_Item; } } public RODbRoUsagesPropertyDescriptor(RODbRoUsages 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 RODbRoUsages) + if (destType == typeof(string) && value is RODbRoUsages usages) { // Return department and department role separated by comma. - return ((RODbRoUsages)value).Items.Count.ToString() + " RoUsages"; + return $"{usages.Items.Count} RoUsages"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs index 33713bf3..2701066e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.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; @@ -85,7 +83,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(ROFst rOFst) { @@ -100,7 +98,9 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(rOFst)) _CacheList.Remove(rOFst); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByRODbID_DTS = new Dictionary>(); private static void ConvertListToDictionary() { @@ -129,7 +129,7 @@ namespace VEPROMS.CSLA.Library protected static ROFst GetCachedByRODbID_DTS(int rODbID, DateTime dts) { ConvertListToDictionary(); - string key = rODbID.ToString() + "_" + dts.ToString(); + string key = $"{rODbID}_{dts}"; if (_CacheByRODbID_DTS.ContainsKey(key)) return _CacheByRODbID_DTS[key][0]; return null; } @@ -139,15 +139,9 @@ namespace VEPROMS.CSLA.Library #region Business Methods private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } + public string ErrorMessage => _ErrorMessage; private static int _nextROFstID = -1; - public static int NextROFstID - { - get { return _nextROFstID--; } - } + public static int NextROFstID => _nextROFstID--; private int _ROFstID; [System.ComponentModel.DataObjectField(true, true)] public int ROFstID @@ -302,10 +296,7 @@ namespace VEPROMS.CSLA.Library return _ROFstAssociations; } } - public void Reset_ROFstAssociations() - { - _ROFstAssociationCount = -1; - } + public void Reset_ROFstAssociations() => _ROFstAssociationCount = -1; private int _ROFstFigureCount = 0; /// /// Count of ROFstFigures for this ROFst @@ -337,10 +328,7 @@ namespace VEPROMS.CSLA.Library return _ROFstFigures; } } - public void Reset_ROFstFigures() - { - _ROFstFigureCount = -1; - } + public void Reset_ROFstFigures() => _ROFstFigureCount = -1; public override bool IsDirty { get @@ -355,37 +343,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_ROFstAssociations == null ? false : _ROFstAssociations.IsDirtyList(list)) || (_ROFstFigures == null ? false : _ROFstFigures.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_ROFstAssociations != null && _ROFstAssociations.IsDirtyList(list)) || (_ROFstFigures != null && _ROFstFigures.IsDirtyList(list)) || (_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) && (_ROFstAssociations == null ? true : _ROFstAssociations.IsValidList(list)) && (_ROFstFigures == null ? true : _ROFstFigures.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_ROFstAssociations == null || _ROFstAssociations.IsValidList(list)) && (_ROFstFigures == null || _ROFstFigures.IsValidList(list)) && (_MyRODb == null || _MyRODb.IsValidList(list)); } - // CSLATODO: Replace base ROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFst - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check ROFst.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 ROFst - protected override object GetIdValue() - { - return MyROFstUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyROFstUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -416,8 +389,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() @@ -449,33 +422,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(ROFstID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(ROLookup, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - //AuthorizationRules.AllowWrite(ROLookup, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); _ROFstExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -483,56 +434,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _ROFstExtension.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 += _ROFstAssociationCount; - usedByCount += _ROFstFigureCount; - 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 _ROFstUnique = 0; - protected static int ROFstUnique - { get { return ++_ROFstUnique; } } - private int _MyROFstUnique = ROFstUnique; - public int MyROFstUnique // Absolutely Unique ID - Editable - { get { return _MyROFstUnique; } } + protected static int ROFstUnique => ++_ROFstUnique; + private readonly int _MyROFstUnique = ROFstUnique; + // Absolutely Unique ID - Editable + public int MyROFstUnique => _MyROFstUnique; protected ROFst() {/* require use of factory methods */ AddToCache(this); @@ -541,15 +450,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; ~ROFst() { _CountFinalized++; @@ -588,8 +493,6 @@ namespace VEPROMS.CSLA.Library public static ROFst New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFst"); try { return DataPortal.Create(); @@ -640,7 +543,7 @@ namespace VEPROMS.CSLA.Library if (tmp.ROLookup != null && tmp.ROFstID > 0) { //Force Load the new Lookup Data - var RofstLookup = new ROFSTLookup(tmp.ROFstID); + _ = new ROFSTLookup(tmp.ROFstID); tmp.ROLookup = null; } } @@ -667,7 +570,7 @@ namespace VEPROMS.CSLA.Library // B2022-026 RO Memory reduction //Force Load the new Lookup Data - var RofstLookup = new ROFSTLookup(tmp.ROFstID); + _ = new ROFSTLookup(tmp.ROFstID); tmp.ROLookup = null; } else @@ -685,8 +588,6 @@ namespace VEPROMS.CSLA.Library public static ROFst Get(int rOFstID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROFst"); try { ROFst tmp = GetCachedByPrimaryKey(rOFstID); @@ -712,8 +613,6 @@ namespace VEPROMS.CSLA.Library public static ROFst GetByRODbID_DTS(int rODbID, DateTime dts) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROFst"); try { ROFst tmp = GetCachedByRODbID_DTS(rODbID, dts); @@ -739,14 +638,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new ROFst(dr); return null; } - internal ROFst(SafeDataReader dr) - { - ReadData(dr); - } + internal ROFst(SafeDataReader dr) => ReadData(dr); public static void Delete(int rOFstID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFst"); try { DataPortal.Delete(new PKCriteria(rOFstID)); @@ -758,12 +652,6 @@ namespace VEPROMS.CSLA.Library } public override ROFst Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFst"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFst"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROFst"); try { BuildRefreshList(); @@ -784,23 +672,17 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } + private readonly int _ROFstID; + public int ROFstID => _ROFstID; + public PKCriteria(int rOFstID) => _ROFstID = rOFstID; } [Serializable()] private class RODbID_DTSCriteria { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - private DateTime _DTS; - public DateTime DTS - { get { return _DTS; } } + private readonly int _RODbID; + public int RODbID => _RODbID; + private readonly DateTime _DTS; + public DateTime DTS => _DTS; public RODbID_DTSCriteria(int rODbID, DateTime dts) { _RODbID = rODbID; @@ -954,45 +836,52 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + _MyRODb?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addROFst"; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@ROLookup", _ROLookup); - cm.Parameters.AddWithValue("@Config", _Config); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@ROLookup", _ROLookup); + 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_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); - param_ROFstID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROFstID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); + // Output Calculated Columns + SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_ROFstID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); - cm.ExecuteNonQuery(); + cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _ROFstID = (int)cm.Parameters["@newROFstID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + // Save all values being returned from the Procedure + _ROFstID = (int)cm.Parameters["@newROFstID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - // Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction - _ROLookup = null; + // Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction + _ROLookup = null; + } } + MarkOld(); // update child objects - if (_ROFstAssociations != null) _ROFstAssociations.Update(this); - if (_ROFstFigures != null) _ROFstFigures.Update(this); + _ROFstAssociations?.Update(this); + _ROFstFigures?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -1023,11 +912,15 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@UserID", userID); // Output Calculated Columns - SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); - param_ROFstID.Direction = ParameterDirection.Output; + SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_ROFstID); - 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); cm.ExecuteNonQuery(); @@ -1078,40 +971,45 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLUpdate", GetHashCode()); try { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + _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 = "updateROFst"; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateROFst"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@ROLookup", ROFSTLookup.GetRofstLookupBytes(_ROFstID)); // B2022-026 RO Memory reduction - new calls - 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); + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@ROLookup", ROFSTLookup.GetRofstLookupBytes(_ROFstID)); // B2022-026 RO Memory reduction - new calls + 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); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); - cm.ExecuteNonQuery(); + cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } } + MarkOld(); // use the open connection to update child objects - if (_ROFstAssociations != null) _ROFstAssociations.Update(this); - if (_ROFstFigures != null) _ROFstFigures.Update(this); + _ROFstAssociations?.Update(this); + _ROFstFigures?.Update(this); } catch (Exception ex) { @@ -1123,18 +1021,21 @@ 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 = ROFst.Add(cn, ref _ROFstID, _MyRODb, _ROLookup, _Config, _DTS, _UserID); - else - _LastChanged = ROFst.Update(cn, ref _ROFstID, _RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = ROFst.Add(cn, ref _ROFstID, _MyRODb, _ROLookup, _Config, _DTS, _UserID); + else + _LastChanged = ROFst.Update(cn, ref _ROFstID, _RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } - if (_ROFstAssociations != null) _ROFstAssociations.Update(this); - if (_ROFstFigures != null) _ROFstFigures.Update(this); + _ROFstAssociations?.Update(this); + _ROFstFigures?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] @@ -1163,8 +1064,10 @@ namespace VEPROMS.CSLA.Library 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); cm.ExecuteNonQuery(); @@ -1250,16 +1153,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _ROFstID; + private readonly int _ROFstID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rOFstID) - { - _ROFstID = rOFstID; - } + public bool Exists => _exists; + public ExistsCommand(int rOFstID) => _ROFstID = rOFstID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Execute", GetHashCode()); @@ -1275,7 +1172,7 @@ namespace VEPROMS.CSLA.Library cm.CommandText = "existsROFst"; cm.Parameters.AddWithValue("@ROFstID", _ROFstID); int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); + _exists = count > 0; } } } @@ -1289,7 +1186,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - ROFstExtension _ROFstExtension = new ROFstExtension(); + readonly ROFstExtension _ROFstExtension = new ROFstExtension(); [Serializable()] partial class ROFstExtension : extensionBase { @@ -1298,14 +1195,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) { @@ -1334,57 +1225,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 ROFst) + if (destType == typeof(string) && value is ROFst fst) { // Return the ToString value - return ((ROFst)value).ToString(); + return fst.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create ROFstExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class ROFst -// { -// partial class ROFstExtension : 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/ROFstAssociation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.cs index 4f38fa08..ef1fadf6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.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 @@ -234,19 +228,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current ROFstAssociation - protected override object GetIdValue() - { - return MyROFstAssociationUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ROFstAssociation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstAssociation - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyROFstAssociationUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -261,18 +243,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyDocVersion != null && _MyDocVersion.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) && (_MyDocVersion == null ? true : _MyDocVersion.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocVersion == null || _MyDocVersion.IsValidList(list)); } #endregion #region ValidationRules @@ -302,8 +281,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() @@ -328,76 +307,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(AssociationID, ""); - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowWrite(VersionID, ""); - //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 _ROFstAssociationUnique = 0; - private static int ROFstAssociationUnique - { get { return ++_ROFstAssociationUnique; } } - private int _MyROFstAssociationUnique = ROFstAssociationUnique; - public int MyROFstAssociationUnique // Absolutely Unique ID - Editable FK - { get { return _MyROFstAssociationUnique; } } - internal static ROFstAssociation New(DocVersion myDocVersion) - { - return new ROFstAssociation(myDocVersion); - } - internal static ROFstAssociation Get(SafeDataReader dr) - { - return new ROFstAssociation(dr); - } + private static int ROFstAssociationUnique => ++_ROFstAssociationUnique; + private readonly int _MyROFstAssociationUnique = ROFstAssociationUnique; + // Absolutely Unique ID - Editable FK + public int MyROFstAssociationUnique => _MyROFstAssociationUnique; + internal static ROFstAssociation New(DocVersion myDocVersion) => new ROFstAssociation(myDocVersion); + internal static ROFstAssociation Get(SafeDataReader dr) => new ROFstAssociation(dr); public ROFstAssociation() { MarkAsChild(); @@ -425,15 +350,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; ~ROFstAssociation() { _CountFinalized++; @@ -477,33 +398,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(ROFst myROFst) { // 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); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Association.Add(cn, ref _AssociationID, _MyDocVersion, myROFst, _Config, _DTS, _UserID); + } + MarkOld(); } internal void Update(ROFst myROFst) { // 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, _VersionID, myROFst.ROFstID, _Config, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Association.Update(cn, ref _AssociationID, _VersionID, myROFst.ROFstID, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(ROFst myROFst) { // 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"]; - Association.Remove(cn, _AssociationID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Association.Remove(cn, _AssociationID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - ROFstAssociationExtension _ROFstAssociationExtension = new ROFstAssociationExtension(); + readonly ROFstAssociationExtension _ROFstAssociationExtension = new ROFstAssociationExtension(); [Serializable()] partial class ROFstAssociationExtension : extensionBase { @@ -512,14 +443,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) { @@ -548,57 +473,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 ROFstAssociation) + if (destType == typeof(string) && value is ROFstAssociation association) { // Return the ToString value - return ((ROFstAssociation)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 ROFstAssociationExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class ROFstAssociation -// { -// partial class ROFstAssociationExtension : 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/ROFstAssociations.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociations.cs index a2e0af4d..bdfacf79 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociations.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociations.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 ROFstAssociation this[Association myAssociation] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public ROFstAssociation 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 ROFstAssociation GetItem(Association myAssociation) + public new System.Collections.Generic.IList Items => base.Items; + public ROFstAssociation GetItem(Association myAssociation) { foreach (ROFstAssociation association in this) if (association.AssociationID == myAssociation.AssociationID) @@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library if (!Contains(myDocVersion)) { ROFstAssociation association = ROFstAssociation.New(myDocVersion); - this.Add(association); + Add(association); return association; } 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 (ROFstAssociation 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 (ROFstAssociation 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(DocVersion myDocVersion) { foreach (ROFstAssociation association in this) @@ -156,20 +145,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static ROFstAssociations New() - { - return new ROFstAssociations(); - } - internal static ROFstAssociations Get(SafeDataReader dr) - { - return new ROFstAssociations(dr); - } - public static ROFstAssociations GetByROFstID(int rOFstID) + #endregion + #region Factory Methods + internal static ROFstAssociations New() => new ROFstAssociations(); + internal static ROFstAssociations Get(SafeDataReader dr) => new ROFstAssociations(dr); + public static ROFstAssociations GetByROFstID(int rOFstID) { try { @@ -180,11 +163,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on ROFstAssociations.GetByROFstID", ex); } } - private ROFstAssociations() - { - MarkAsChild(); - } - internal ROFstAssociations(SafeDataReader dr) + private ROFstAssociations() => MarkAsChild(); + internal ROFstAssociations(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -193,16 +173,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~ROFstAssociations() + 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; + ~ROFstAssociations() { _CountFinalized++; } @@ -217,19 +193,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(ROFstAssociation.Get(dr)); - this.RaiseListChangedEvents = true; + Add(ROFstAssociation.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class ROFstIDCriteria { - public ROFstIDCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } - private int _ROFstID; + public ROFstIDCriteria(int rOFstID) => _ROFstID = rOFstID; + private int _ROFstID; public int ROFstID { get { return _ROFstID; } @@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(ROFstIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstAssociations.DataPortal_FetchROFstID", GetHashCode()); try { @@ -252,7 +225,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new ROFstAssociation(dr)); + while (dr.Read()) Add(new ROFstAssociation(dr)); } } } @@ -262,11 +235,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstAssociations.DataPortal_FetchROFstID", ex); throw new DbCslaException("ROFstAssociations.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(ROFst rOFst) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -285,49 +258,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// 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 ROFstAssociationsPropertyDescriptor pd = new ROFstAssociationsPropertyDescriptor(this, i); @@ -344,7 +306,6 @@ namespace VEPROMS.CSLA.Library /// public partial class ROFstAssociationsPropertyDescriptor : vlnListPropertyDescriptor { - private ROFstAssociation Item { get { return (ROFstAssociation)_Item; } } public ROFstAssociationsPropertyDescriptor(ROFstAssociations collection, int index) : base(collection, index) { ;} } #endregion @@ -353,10 +314,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is ROFstAssociations) + if (destType == typeof(string) && value is ROFstAssociations associations) { // Return department and department role separated by comma. - return ((ROFstAssociations)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/ROFstFigure.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.cs index 4f89775f..9df23c2a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.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 _FigureID; [System.ComponentModel.DataObjectField(true, true)] public int FigureID @@ -204,19 +198,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current ROFstFigure - protected override object GetIdValue() - { - return MyROFstFigureUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ROFstFigure.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstFigure - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyROFstFigureUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -231,18 +213,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyROImage == null ? false : _MyROImage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyROImage != null && _MyROImage.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) && (_MyROImage == null ? true : _MyROImage.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyROImage == null || _MyROImage.IsValidList(list)); } #endregion #region ValidationRules @@ -272,8 +251,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() @@ -298,76 +277,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(FigureID, ""); - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowWrite(ImageID, ""); - //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 _ROFstFigureUnique = 0; - private static int ROFstFigureUnique - { get { return ++_ROFstFigureUnique; } } - private int _MyROFstFigureUnique = ROFstFigureUnique; - public int MyROFstFigureUnique // Absolutely Unique ID - Editable FK - { get { return _MyROFstFigureUnique; } } - internal static ROFstFigure New(ROImage myROImage) - { - return new ROFstFigure(myROImage); - } - internal static ROFstFigure Get(SafeDataReader dr) - { - return new ROFstFigure(dr); - } + private static int ROFstFigureUnique => ++_ROFstFigureUnique; + private readonly int _MyROFstFigureUnique = ROFstFigureUnique; + // Absolutely Unique ID - Editable FK + public int MyROFstFigureUnique => _MyROFstFigureUnique; + internal static ROFstFigure New(ROImage myROImage) => new ROFstFigure(myROImage); + internal static ROFstFigure Get(SafeDataReader dr) => new ROFstFigure(dr); public ROFstFigure() { MarkAsChild(); @@ -395,15 +320,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; ~ROFstFigure() { _CountFinalized++; @@ -444,33 +365,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(ROFst myROFst) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Add(cn, ref _FigureID, myROFst, _MyROImage, _Config, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Figure.Add(cn, ref _FigureID, myROFst, _MyROImage, _Config, _DTS, _UserID); + } + MarkOld(); } internal void Update(ROFst myROFst) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Update(cn, ref _FigureID, myROFst.ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Figure.Update(cn, ref _FigureID, myROFst.ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(ROFst myROFst) { // 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"]; - Figure.Remove(cn, _FigureID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Figure.Remove(cn, _FigureID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - ROFstFigureExtension _ROFstFigureExtension = new ROFstFigureExtension(); + readonly ROFstFigureExtension _ROFstFigureExtension = new ROFstFigureExtension(); [Serializable()] partial class ROFstFigureExtension : extensionBase { @@ -479,14 +410,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) { @@ -515,57 +440,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 ROFstFigure) + if (destType == typeof(string) && value is ROFstFigure figure) { // Return the ToString value - return ((ROFstFigure)value).ToString(); + return figure.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create ROFstFigureExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class ROFstFigure -// { -// partial class ROFstFigureExtension : 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/ROFstFigures.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigures.cs index 13b990f8..e4610439 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigures.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigures.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 ROFstFigure this[Figure myFigure] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public ROFstFigure this[Figure myFigure] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public ROFstFigure GetItem(Figure myFigure) + public new System.Collections.Generic.IList Items => base.Items; + public ROFstFigure GetItem(Figure myFigure) { foreach (ROFstFigure figure in this) if (figure.FigureID == myFigure.FigureID) @@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library if (!Contains(myROImage)) { ROFstFigure figure = ROFstFigure.New(myROImage); - this.Add(figure); + Add(figure); return figure; } 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 (ROFstFigure 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 (ROFstFigure 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(ROImage myROImage) { foreach (ROFstFigure figure in this) @@ -156,20 +145,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static ROFstFigures New() - { - return new ROFstFigures(); - } - internal static ROFstFigures Get(SafeDataReader dr) - { - return new ROFstFigures(dr); - } - public static ROFstFigures GetByROFstID(int rOFstID) + #endregion + #region Factory Methods + internal static ROFstFigures New() => new ROFstFigures(); + internal static ROFstFigures Get(SafeDataReader dr) => new ROFstFigures(dr); + public static ROFstFigures GetByROFstID(int rOFstID) { try { @@ -180,11 +163,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on ROFstFigures.GetByROFstID", ex); } } - private ROFstFigures() - { - MarkAsChild(); - } - internal ROFstFigures(SafeDataReader dr) + private ROFstFigures() => MarkAsChild(); + internal ROFstFigures(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -193,16 +173,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~ROFstFigures() + 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; + ~ROFstFigures() { _CountFinalized++; } @@ -217,19 +193,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(ROFstFigure.Get(dr)); - this.RaiseListChangedEvents = true; + Add(ROFstFigure.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class ROFstIDCriteria { - public ROFstIDCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } - private int _ROFstID; + public ROFstIDCriteria(int rOFstID) => _ROFstID = rOFstID; + private int _ROFstID; public int ROFstID { get { return _ROFstID; } @@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(ROFstIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstFigures.DataPortal_FetchROFstID", GetHashCode()); try { @@ -252,7 +225,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new ROFstFigure(dr)); + while (dr.Read()) Add(new ROFstFigure(dr)); } } } @@ -262,11 +235,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstFigures.DataPortal_FetchROFstID", ex); throw new DbCslaException("ROFstFigures.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(ROFst rOFst) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -285,49 +258,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// 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 ROFstFiguresPropertyDescriptor pd = new ROFstFiguresPropertyDescriptor(this, i); @@ -344,7 +306,6 @@ namespace VEPROMS.CSLA.Library /// public partial class ROFstFiguresPropertyDescriptor : vlnListPropertyDescriptor { - private ROFstFigure Item { get { return (ROFstFigure)_Item; } } public ROFstFiguresPropertyDescriptor(ROFstFigures collection, int index) : base(collection, index) { ;} } #endregion @@ -353,10 +314,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is ROFstFigures) + if (destType == typeof(string) && value is ROFstFigures figures) { // Return department and department role separated by comma. - return ((ROFstFigures)value).Items.Count.ToString() + " Figures"; + return $"{figures.Items.Count} Figures"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs index ca54bb82..99591ca0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.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,20 +26,17 @@ namespace VEPROMS.CSLA.Library public partial class ROFstInfo : ReadOnlyBase, IDisposable { public event ROFstInfoEvent 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(ROFstInfo rOFstInfo) { if (!_CacheList.Contains(rOFstInfo)) { - rOFstInfo.ClearROLookupBytes(); // B2022-026 RO Memory reduction _CacheList.Add(rOFstInfo); // In AddToCache } } @@ -49,6 +44,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(rOFstInfo)) _CacheList.Remove(rOFstInfo); // 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() { @@ -60,7 +56,6 @@ namespace VEPROMS.CSLA.Library { _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey } - tmp.ClearROLookupBytes(); // B2022-026 RO Memory reduction _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list _CacheList.RemoveAt(0); // Remove the first ROFstInfo } @@ -79,21 +74,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 ROFst _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _ROFstID; [System.ComponentModel.DataObjectField(true, true)] public int ROFstID @@ -124,19 +106,6 @@ namespace VEPROMS.CSLA.Library return _MyRODb; } } - - private byte[] _ROLookup; - public byte[] ROLookup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - - // B2022-026 RO Memory reduction - return null; - } - } - private string _Config = string.Empty; public string Config { @@ -241,21 +210,17 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current ROFstInfo - protected override object GetIdValue() - { - return MyROFstInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyROFstInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _ROFstInfoUnique = 0; - private static int ROFstInfoUnique - { get { return ++_ROFstInfoUnique; } } - private int _MyROFstInfoUnique = ROFstInfoUnique; - public int MyROFstInfoUnique // Absolutely Unique ID - Info - { get { return _MyROFstInfoUnique; } } + private static int ROFstInfoUnique => ++_ROFstInfoUnique; + private readonly int _MyROFstInfoUnique = ROFstInfoUnique; + // Absolutely Unique ID - Info + public int MyROFstInfoUnique => _MyROFstInfoUnique; protected ROFstInfo() {/* require use of factory methods */ AddToCache(this); @@ -265,15 +230,11 @@ namespace VEPROMS.CSLA.Library 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; ~ROFstInfo() { _CountFinalized++; @@ -290,10 +251,7 @@ namespace VEPROMS.CSLA.Library if (listROFstInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list } - public virtual ROFst Get() - { - return _Editable = ROFst.Get(_ROFstID); - } + public virtual ROFst Get() => _Editable = ROFst.Get(_ROFstID); public static void Refresh(ROFst tmp) { string key = tmp.ROFstID.ToString(); @@ -302,23 +260,16 @@ namespace VEPROMS.CSLA.Library foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) tmpInfo.RefreshFields(tmp); } - // B2022-026 RO Memory reduction - public void ClearROLookupBytes() - { - _ROLookup = null; - } protected virtual void RefreshFields(ROFst tmp) { if (_RODbID != tmp.RODbID) { - if (MyRODb != null) MyRODb.RefreshRODbROFsts(); // Update List for old value + MyRODb?.RefreshRODbROFsts(); // 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.RefreshRODbROFsts(); // Update List for new value - //_ROLookup = tmp.ROLookup; - _ROLookup = null; // B2022-026 RO Memory reduction + MyRODb?.RefreshRODbROFsts(); // Update List for new value _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -335,8 +286,6 @@ namespace VEPROMS.CSLA.Library } protected virtual void RefreshFields(RODbROFst tmp) { - //_ROLookup = tmp.ROLookup; - _ROLookup = null; // B2022-026 RO Memory reduction _Config = tmp.Config; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -360,11 +309,6 @@ namespace VEPROMS.CSLA.Library tmp = null; } - if (tmp != null) - { - tmp.ClearROLookupBytes(); // B2022-026 RO Memory reduction - } - return tmp; } catch (Exception ex) @@ -394,13 +338,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } + private readonly int _ROFstID; + public int ROFstID => _ROFstID; + public PKCriteria(int rOFstID) => _ROFstID = rOFstID; } private void ReadData(SafeDataReader dr) @@ -410,8 +350,6 @@ namespace VEPROMS.CSLA.Library { _ROFstID = dr.GetInt32("ROFstID"); _RODbID = dr.GetInt32("RODbID"); - //_ROLookup = (byte[])dr.GetValue("ROLookup"); - _ROLookup = null; // B2022-026 RO Memory reduction _Config = dr.GetString("Config"); _DTS = dr.GetDateTime("DTS"); _UserID = dr.GetString("UserID"); @@ -467,7 +405,7 @@ namespace VEPROMS.CSLA.Library // Standard Refresh #region extension - ROFstInfoExtension _ROFstInfoExtension = new ROFstInfoExtension(); + readonly ROFstInfoExtension _ROFstInfoExtension = new ROFstInfoExtension(); [Serializable()] partial class ROFstInfoExtension : extensionBase { } [Serializable()] @@ -485,10 +423,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 ROFstInfo) + if (destType == typeof(string) && value is ROFstInfo info) { // Return the ToString value - return ((ROFstInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfoList.cs index 369beb4d..6e886f3e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfoList.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 (ROFstInfo 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; } } - ~ROFstInfoList() + 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; + ~ROFstInfoList() { _CountFinalized++; } @@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on ROFstInfoList.Get", ex); } } - /// - /// Reset the list of all ROFstInfo. - /// - public static void Reset() - { - _ROFstInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static ROFstInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on ROFstInfoList.Get", ex); - // } - //} - public static ROFstInfoList GetByRODbID(int rODbID) + /// + /// Reset the list of all ROFstInfo. + /// + public static void Reset() => _ROFstInfoList = null; + public static ROFstInfoList GetByRODbID(int rODbID) { try { @@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal private void DataPortal_Fetch() { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfoList.DataPortal_Fetch", GetHashCode()); try { @@ -150,7 +128,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new ROFstInfo(dr)); + while (dr.Read()) Add(new ROFstInfo(dr)); IsReadOnly = true; } } @@ -161,16 +139,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ROFstInfoList.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; } @@ -179,7 +154,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfoList.DataPortal_FetchRODbID", GetHashCode()); try { @@ -194,7 +169,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new ROFstInfo(dr)); + while (dr.Read()) Add(new ROFstInfo(dr)); IsReadOnly = true; } } @@ -205,48 +180,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfoList.DataPortal_FetchRODbID", ex); throw new DbCslaException("ROFstInfoList.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 ROFstInfoListPropertyDescriptor pd = new ROFstInfoListPropertyDescriptor(this, i); @@ -263,7 +227,6 @@ namespace VEPROMS.CSLA.Library /// public partial class ROFstInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private ROFstInfo Item { get { return (ROFstInfo)_Item; } } public ROFstInfoListPropertyDescriptor(ROFstInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -272,10 +235,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is ROFstInfoList) + if (destType == typeof(string) && value is ROFstInfoList list) { // Return department and department role separated by comma. - return ((ROFstInfoList)value).Items.Count.ToString() + " ROFsts"; + return $"{list.Items.Count} ROFsts"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs index 5b8f58f8..753635e6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.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; @@ -70,6 +68,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(ROImage rOImage) { @@ -79,7 +78,9 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(rOImage)) _CacheList.Remove(rOImage); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByRODbID_FileName_DTS = new Dictionary>(); private static void ConvertListToDictionary() { @@ -114,15 +115,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 _nextImageID = -1; - public static int NextImageID - { - get { return _nextImageID--; } - } + public static int NextImageID => _nextImageID--; private int _ImageID; [System.ComponentModel.DataObjectField(true, true)] public int ImageID @@ -288,10 +283,7 @@ namespace VEPROMS.CSLA.Library return _ROImageFigures; } } - public void Reset_ROImageFigures() - { - _ROImageFigureCount = -1; - } + public void Reset_ROImageFigures() => _ROImageFigureCount = -1; public override bool IsDirty { get @@ -306,37 +298,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_ROImageFigures == null ? false : _ROImageFigures.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_ROImageFigures != null && _ROImageFigures.IsDirtyList(list)) || (_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) && (_ROImageFigures == null ? true : _ROImageFigures.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_ROImageFigures == null || _ROImageFigures.IsValidList(list)) && (_MyRODb == null || _MyRODb.IsValidList(list)); } - // CSLATODO: Replace base ROImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImage - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check ROImage.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 ROImage - protected override object GetIdValue() - { - return MyROImageUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyROImageUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -366,8 +343,8 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + if (Equals(hasBrokenRules)) return BrokenRulesCollection; + return hasBrokenRules?.BrokenRules; } } protected override void AddBusinessRules() @@ -404,35 +381,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(ImageID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowRead(Content, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowWrite(Content, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); _ROImageExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -440,55 +393,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _ROImageExtension.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 += _ROImageFigureCount; - 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 _ROImageUnique = 0; - protected static int ROImageUnique - { get { return ++_ROImageUnique; } } - private int _MyROImageUnique = ROImageUnique; - public int MyROImageUnique // Absolutely Unique ID - Editable - { get { return _MyROImageUnique; } } + protected static int ROImageUnique => ++_ROImageUnique; + private readonly int _MyROImageUnique = ROImageUnique; + // Absolutely Unique ID - Editable + public int MyROImageUnique => _MyROImageUnique; protected ROImage() {/* require use of factory methods */ AddToCache(this); @@ -497,15 +409,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; ~ROImage() { _CountFinalized++; @@ -542,8 +450,6 @@ namespace VEPROMS.CSLA.Library } public static ROImage New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROImage"); try { return DataPortal.Create(); @@ -615,8 +521,6 @@ namespace VEPROMS.CSLA.Library } public static ROImage Get(int imageID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); try { ROImage tmp = GetCachedByPrimaryKey(imageID); @@ -639,8 +543,6 @@ namespace VEPROMS.CSLA.Library } public static ROImage GetJustROImage(int imageID)//Don't load figures or ROFST - Causing Memory Crash { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); try { ROImage tmp = GetCachedByPrimaryKey(imageID); @@ -663,8 +565,6 @@ namespace VEPROMS.CSLA.Library } public static ROImage GetByRODbID_FileName_DTS(int rODbID, string fileName, DateTime dts) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); try { ROImage tmp = GetCachedByRODbID_FileName_DTS(rODbID, fileName, dts); @@ -690,14 +590,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new ROImage(dr); return null; } - internal ROImage(SafeDataReader dr) - { - ReadData(dr); - } + internal ROImage(SafeDataReader dr) => ReadData(dr); public static void Delete(int imageID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROImage"); try { DataPortal.Delete(new PKCriteria(imageID)); @@ -709,12 +604,6 @@ namespace VEPROMS.CSLA.Library } public override ROImage Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROImage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROImage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROImage"); try { BuildRefreshList(); @@ -734,37 +623,26 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int imageID) - { - _ImageID = imageID; - } + private readonly int _ImageID; + public int ImageID => _ImageID; + public PKCriteria(int imageID) => _ImageID = imageID; } [Serializable()] protected class PKCriteriaJustROImage//Don't load figures or ROFST - Causing Memory Crash { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteriaJustROImage(int imageID) - { - _ImageID = imageID; - } + private readonly int _ImageID; + public int ImageID => _ImageID; + public PKCriteriaJustROImage(int imageID) => _ImageID = imageID; } [Serializable()] private class RODbID_FileName_DTSCriteria { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - private string _FileName; - public string FileName - { get { return _FileName; } } - private DateTime _DTS; - public DateTime DTS - { get { return _DTS; } } + private readonly int _RODbID; + public int RODbID => _RODbID; + private readonly string _FileName; + public string FileName => _FileName; + private readonly DateTime _DTS; + public DateTime DTS => _DTS; public RODbID_FileName_DTSCriteria(int rODbID, string fileName, DateTime dts) { _RODbID = rODbID; @@ -948,39 +826,46 @@ namespace VEPROMS.CSLA.Library [Transactional(TransactionalTypes.TransactionScope)] internal void SQLInsert() { - if (!this.IsDirty) return; + if (!IsDirty) return; try { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) + _MyRODb?.Update(); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@FileName", _FileName); - cm.Parameters.AddWithValue("@Content", _Content); - 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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); - param_ImageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ImageID); - 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 - _ImageID = (int)cm.Parameters["@newImageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Content", _Content); + 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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_ImageID); + 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 + _ImageID = (int)cm.Parameters["@newImageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects - if (_ROImageFigures != null) _ROImageFigures.Update(this); + _ROImageFigures?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -1009,11 +894,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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); - param_ImageID.Direction = ParameterDirection.Output; + SqlParameter param_ImageID = new SqlParameter("@newImageID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_ImageID); - 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(); @@ -1058,37 +947,42 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.SQLUpdate", GetHashCode()); try { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) + _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 = "updateROImage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ImageID", _ImageID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@FileName", _FileName); - cm.Parameters.AddWithValue("@Content", _Content); - 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 = "updateROImage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ImageID", _ImageID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Content", _Content); + 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 (_ROImageFigures != null) _ROImageFigures.Update(this); + _ROImageFigures?.Update(this); } catch (Exception ex) { @@ -1099,17 +993,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 = ROImage.Add(cn, ref _ImageID, _MyRODb, _FileName, _Content, _Config, _DTS, _UserID); - else - _LastChanged = ROImage.Update(cn, ref _ImageID, _RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = ROImage.Add(cn, ref _ImageID, _MyRODb, _FileName, _Content, _Config, _DTS, _UserID); + else + _LastChanged = ROImage.Update(cn, ref _ImageID, _RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } - if (_ROImageFigures != null) _ROImageFigures.Update(this); + _ROImageFigures?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] public static byte[] Update(SqlConnection cn, ref int imageID, int rODbID, string fileName, byte[] content, string config, DateTime dts, string userID, ref byte[] lastChanged) @@ -1132,8 +1029,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(); @@ -1218,16 +1117,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _ImageID; + private readonly int _ImageID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int imageID) - { - _ImageID = imageID; - } + public bool Exists => _exists; + public ExistsCommand(int imageID) => _ImageID = imageID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Execute", GetHashCode()); @@ -1243,7 +1136,7 @@ namespace VEPROMS.CSLA.Library cm.CommandText = "existsROImage"; cm.Parameters.AddWithValue("@ImageID", _ImageID); int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); + _exists = count > 0; } } } @@ -1257,7 +1150,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - ROImageExtension _ROImageExtension = new ROImageExtension(); + readonly ROImageExtension _ROImageExtension = new ROImageExtension(); [Serializable()] partial class ROImageExtension : extensionBase { @@ -1266,14 +1159,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) { @@ -1302,57 +1189,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 ROImage) + if (destType == typeof(string) && value is ROImage image) { // Return the ToString value - return ((ROImage)value).ToString(); + return image.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create ROImageExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class ROImage -// { -// partial class ROImageExtension : 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/ROImageFigure.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.cs index 45226ad6..13e1e1bd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.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 _FigureID; [System.ComponentModel.DataObjectField(true, true)] public int FigureID @@ -195,19 +189,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current ROImageFigure - protected override object GetIdValue() - { - return MyROImageFigureUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ROImageFigure.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImageFigure - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyROImageFigureUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -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 @@ -263,8 +242,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() @@ -289,76 +268,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(FigureID, ""); - //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 _ROImageFigureUnique = 0; - private static int ROImageFigureUnique - { get { return ++_ROImageFigureUnique; } } - private int _MyROImageFigureUnique = ROImageFigureUnique; - public int MyROImageFigureUnique // Absolutely Unique ID - Editable FK - { get { return _MyROImageFigureUnique; } } - internal static ROImageFigure New(ROFst myROFst) - { - return new ROImageFigure(myROFst); - } - internal static ROImageFigure Get(SafeDataReader dr) - { - return new ROImageFigure(dr); - } + private static int ROImageFigureUnique => ++_ROImageFigureUnique; + private readonly int _MyROImageFigureUnique = ROImageFigureUnique; + // Absolutely Unique ID - Editable FK + public int MyROImageFigureUnique => _MyROImageFigureUnique; + internal static ROImageFigure New(ROFst myROFst) => new ROImageFigure(myROFst); + internal static ROImageFigure Get(SafeDataReader dr) => new ROImageFigure(dr); public ROImageFigure() { MarkAsChild(); @@ -386,15 +311,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; ~ROImageFigure() { _CountFinalized++; @@ -434,33 +355,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(ROImage myROImage) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, myROImage, _Config, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, myROImage, _Config, _DTS, _UserID); + } + MarkOld(); } internal void Update(ROImage myROImage) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, myROImage.ImageID, _Config, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, myROImage.ImageID, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(ROImage myROImage) { // 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"]; - Figure.Remove(cn, _FigureID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Figure.Remove(cn, _FigureID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - ROImageFigureExtension _ROImageFigureExtension = new ROImageFigureExtension(); + readonly ROImageFigureExtension _ROImageFigureExtension = new ROImageFigureExtension(); [Serializable()] partial class ROImageFigureExtension : extensionBase { @@ -469,14 +400,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) { @@ -505,57 +430,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 ROImageFigure) + if (destType == typeof(string) && value is ROImageFigure figure) { // Return the ToString value - return ((ROImageFigure)value).ToString(); + return figure.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create ROImageFigureExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class ROImageFigure -// { -// partial class ROImageFigureExtension : 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/ROImageFigures.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigures.cs index 93aef621..18a88d1f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigures.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigures.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 ROImageFigure this[Figure myFigure] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public ROImageFigure this[Figure myFigure] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public ROImageFigure GetItem(Figure myFigure) + public new System.Collections.Generic.IList Items => base.Items; + public ROImageFigure GetItem(Figure myFigure) { foreach (ROImageFigure figure in this) if (figure.FigureID == myFigure.FigureID) @@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library if (!Contains(myROFst)) { ROImageFigure figure = ROImageFigure.New(myROFst); - this.Add(figure); + Add(figure); return figure; } 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 (ROImageFigure 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 (ROImageFigure 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 (ROImageFigure figure in this) @@ -156,20 +145,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static ROImageFigures New() - { - return new ROImageFigures(); - } - internal static ROImageFigures Get(SafeDataReader dr) - { - return new ROImageFigures(dr); - } - public static ROImageFigures GetByImageID(int imageID) + #endregion + #region Factory Methods + internal static ROImageFigures New() => new ROImageFigures(); + internal static ROImageFigures Get(SafeDataReader dr) => new ROImageFigures(dr); + public static ROImageFigures GetByImageID(int imageID) { try { @@ -180,11 +163,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on ROImageFigures.GetByImageID", ex); } } - private ROImageFigures() - { - MarkAsChild(); - } - internal ROImageFigures(SafeDataReader dr) + private ROImageFigures() => MarkAsChild(); + internal ROImageFigures(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -193,16 +173,12 @@ namespace VEPROMS.CSLA.Library private static int _CountCreated = 0; private static int _CountDisposed = 0; private static int _CountFinalized = 0; - private static int IncrementCountCreated - { get { return ++_CountCreated; } } - private int _CountWhenCreated = IncrementCountCreated; - public static int CountCreated - { get { return _CountCreated; } } - public static int CountNotDisposed - { get { return _CountCreated - _CountDisposed; } } - public static int CountNotFinalized - { get { return _CountCreated - _CountFinalized; } } - ~ROImageFigures() + 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; + ~ROImageFigures() { _CountFinalized++; } @@ -217,19 +193,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(ROImageFigure.Get(dr)); - this.RaiseListChangedEvents = true; + Add(ROImageFigure.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class ImageIDCriteria { - public ImageIDCriteria(int imageID) - { - _ImageID = imageID; - } - private int _ImageID; + public ImageIDCriteria(int imageID) => _ImageID = imageID; + private int _ImageID; public int ImageID { get { return _ImageID; } @@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(ImageIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageFigures.DataPortal_FetchImageID", GetHashCode()); try { @@ -252,7 +225,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new ROImageFigure(dr)); + while (dr.Read()) Add(new ROImageFigure(dr)); } } } @@ -262,11 +235,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageFigures.DataPortal_FetchImageID", ex); throw new DbCslaException("ROImageFigures.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(ROImage rOImage) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -285,49 +258,38 @@ namespace VEPROMS.CSLA.Library } finally { - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } } - #endregion - #region ICustomTypeDescriptor impl - public String GetClassName() - { return TypeDescriptor.GetClassName(this, true); } - public AttributeCollection GetAttributes() - { return TypeDescriptor.GetAttributes(this, true); } - public String GetComponentName() - { return TypeDescriptor.GetComponentName(this, true); } - public TypeConverter GetConverter() - { return TypeDescriptor.GetConverter(this, true); } - public EventDescriptor GetDefaultEvent() - { return TypeDescriptor.GetDefaultEvent(this, true); } - public PropertyDescriptor GetDefaultProperty() - { return TypeDescriptor.GetDefaultProperty(this, true); } - public object GetEditor(Type editorBaseType) - { return TypeDescriptor.GetEditor(this, editorBaseType, true); } - public EventDescriptorCollection GetEvents(Attribute[] attributes) - { return TypeDescriptor.GetEvents(this, attributes, true); } - public EventDescriptorCollection GetEvents() - { return TypeDescriptor.GetEvents(this, true); } - public object GetPropertyOwner(PropertyDescriptor pd) - { return this; } - /// - /// 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 ROImageFiguresPropertyDescriptor pd = new ROImageFiguresPropertyDescriptor(this, i); @@ -344,7 +306,6 @@ namespace VEPROMS.CSLA.Library /// public partial class ROImageFiguresPropertyDescriptor : vlnListPropertyDescriptor { - private ROImageFigure Item { get { return (ROImageFigure)_Item; } } public ROImageFiguresPropertyDescriptor(ROImageFigures collection, int index) : base(collection, index) { ;} } #endregion @@ -353,10 +314,10 @@ namespace VEPROMS.CSLA.Library { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { - if (destType == typeof(string) && value is ROImageFigures) + if (destType == typeof(string) && value is ROImageFigures figures) { // Return department and department role separated by comma. - return ((ROImageFigures)value).Items.Count.ToString() + " Figures"; + return $"{figures.Items.Count} Figures"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs index a1b5463b..f0817812 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.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 ROImageInfo : ReadOnlyBase, IDisposable { public event ROImageInfoEvent 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(ROImageInfo rOImageInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(rOImageInfo)) _CacheList.Remove(rOImageInfo); // 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 ROImage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _ImageID; [System.ComponentModel.DataObjectField(true, true)] public int ImageID @@ -200,32 +184,19 @@ namespace VEPROMS.CSLA.Library foreach (ROImageInfo tmp in _CacheByPrimaryKey[_ImageID.ToString()]) tmp._ROImageFigureCount = -1; // This will cause the data to be requeried } - // CSLATODO: Replace base ROImageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check ROImageInfo.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 ROImageInfo - protected override object GetIdValue() - { - return MyROImageInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyROImageInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _ROImageInfoUnique = 0; - private static int ROImageInfoUnique - { get { return ++_ROImageInfoUnique; } } - private int _MyROImageInfoUnique = ROImageInfoUnique; - public int MyROImageInfoUnique // Absolutely Unique ID - Info - { get { return _MyROImageInfoUnique; } } + private static int ROImageInfoUnique => ++_ROImageInfoUnique; + private readonly int _MyROImageInfoUnique = ROImageInfoUnique; + // Absolutely Unique ID - Info + public int MyROImageInfoUnique => _MyROImageInfoUnique; protected ROImageInfo() {/* require use of factory methods */ AddToCache(this); @@ -234,15 +205,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; ~ROImageInfo() { _CountFinalized++; @@ -261,10 +228,7 @@ namespace VEPROMS.CSLA.Library if (listROImageInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list } - public virtual ROImage Get() - { - return _Editable = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash - } + public virtual ROImage Get() => _Editable = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash public static void Refresh(ROImage tmp) { string key = tmp.ImageID.ToString(); @@ -277,11 +241,11 @@ namespace VEPROMS.CSLA.Library { if (_RODbID != tmp.RODbID) { - if (MyRODb != null) MyRODb.RefreshRODbROImages(); // Update List for old value + MyRODb?.RefreshRODbROImages(); // 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.RefreshRODbROImages(); // Update List for new value + MyRODb?.RefreshRODbROImages(); // Update List for new value _FileName = tmp.FileName; _Content = tmp.Content; _Config = tmp.Config; @@ -310,8 +274,6 @@ namespace VEPROMS.CSLA.Library } public static ROImageInfo Get(int imageID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ROImage"); try { ROImageInfo tmp = GetCachedByPrimaryKey(imageID); @@ -350,13 +312,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int imageID) - { - _ImageID = imageID; - } + private readonly int _ImageID; + public int ImageID => _ImageID; + public PKCriteria(int imageID) => _ImageID = imageID; } private void ReadData(SafeDataReader dr) { @@ -418,7 +376,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - ROImageInfoExtension _ROImageInfoExtension = new ROImageInfoExtension(); + readonly ROImageInfoExtension _ROImageInfoExtension = new ROImageInfoExtension(); [Serializable()] partial class ROImageInfoExtension : extensionBase { } [Serializable()] @@ -434,10 +392,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 ROImageInfo) + if (destType == typeof(string) && value is ROImageInfo info) { // Return the ToString value - return ((ROImageInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfoList.cs index b6c455fb..f743e5ad 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfoList.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 (ROImageInfo 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; } } - ~ROImageInfoList() + 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; + ~ROImageInfoList() { _CountFinalized++; } @@ -98,26 +91,11 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on ROImageInfoList.Get", ex); } } - /// - /// Reset the list of all ROImageInfo. - /// - public static void Reset() - { - _ROImageInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static ROImageInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on ROImageInfoList.Get", ex); - // } - //} - public static ROImageInfoList GetByRODbID(int rODbID) + /// + /// Reset the list of all ROImageInfo. + /// + public static void Reset() => _ROImageInfoList = null; + public static ROImageInfoList GetByRODbID(int rODbID) { try { @@ -137,7 +115,7 @@ namespace VEPROMS.CSLA.Library #region Data Access Portal private void DataPortal_Fetch() { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfoList.DataPortal_Fetch", GetHashCode()); try { @@ -151,7 +129,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new ROImageInfo(dr)); + while (dr.Read()) Add(new ROImageInfo(dr)); IsReadOnly = true; } } @@ -162,16 +140,13 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ROImageInfoList.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; } @@ -180,7 +155,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RODbIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfoList.DataPortal_FetchRODbID", GetHashCode()); try { @@ -195,7 +170,7 @@ namespace VEPROMS.CSLA.Library using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { IsReadOnly = false; - while (dr.Read()) this.Add(new ROImageInfo(dr)); + while (dr.Read()) Add(new ROImageInfo(dr)); IsReadOnly = true; } } @@ -206,48 +181,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfoList.DataPortal_FetchRODbID", ex); throw new DbCslaException("ROImageInfoList.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 ROImageInfoListPropertyDescriptor pd = new ROImageInfoListPropertyDescriptor(this, i); @@ -264,7 +228,6 @@ namespace VEPROMS.CSLA.Library /// public partial class ROImageInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private ROImageInfo Item { get { return (ROImageInfo)_Item; } } public ROImageInfoListPropertyDescriptor(ROImageInfoList collection, int index) : base(collection, index) { ;} } #endregion @@ -273,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 ROImageInfoList) + if (destType == typeof(string) && value is ROImageInfoList list) { // Return department and department role separated by comma. - return ((ROImageInfoList)value).Items.Count.ToString() + " ROImages"; + return $"{list.Items.Count} ROImages"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs index 72df59b0..873a72f2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Revision.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; @@ -82,6 +80,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(Revision revision) { @@ -91,6 +90,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(revision)) _CacheList.Remove(revision); // 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() { @@ -116,15 +116,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 _nextRevisionID = -1; - public static int NextRevisionID - { - get { return _nextRevisionID--; } - } + public static int NextRevisionID => _nextRevisionID--; private int _RevisionID; [System.ComponentModel.DataObjectField(true, true)] public int RevisionID @@ -315,10 +309,7 @@ namespace VEPROMS.CSLA.Library return _RevisionChecks; } } - public void Reset_RevisionChecks() - { - _RevisionCheckCount = -1; - } + public void Reset_RevisionChecks() => _RevisionCheckCount = -1; private int _RevisionVersionCount = 0; /// /// Count of RevisionVersions for this Revision @@ -350,10 +341,7 @@ namespace VEPROMS.CSLA.Library return _RevisionVersions; } } - public void Reset_RevisionVersions() - { - _RevisionVersionCount = -1; - } + public void Reset_RevisionVersions() => _RevisionVersionCount = -1; public override bool IsDirty { get @@ -368,37 +356,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_RevisionChecks == null ? false : _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions == null ? false : _RevisionVersions.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_RevisionChecks != null && _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions != null && _RevisionVersions.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) && (_RevisionChecks == null ? true : _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null ? true : _RevisionVersions.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_RevisionChecks == null || _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null || _RevisionVersions.IsValidList(list)); } - // CSLATODO: Replace base Revision.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Revision - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check Revision.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 Revision - protected override object GetIdValue() - { - return MyRevisionUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyRevisionUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -428,8 +401,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() @@ -457,39 +430,11 @@ namespace VEPROMS.CSLA.Library _RevisionExtension.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(RevisionID, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowRead(RevisionNumber, ""); - //AuthorizationRules.AllowRead(RevisionDate, ""); - //AuthorizationRules.AllowRead(Notes, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(TypeID, ""); - //AuthorizationRules.AllowWrite(RevisionNumber, ""); - //AuthorizationRules.AllowWrite(RevisionDate, ""); - //AuthorizationRules.AllowWrite(Notes, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); _RevisionExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -497,56 +442,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _RevisionExtension.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 += _RevisionCheckCount; - usedByCount += _RevisionVersionCount; - 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 _RevisionUnique = 0; - protected static int RevisionUnique - { get { return ++_RevisionUnique; } } - private int _MyRevisionUnique = RevisionUnique; - public int MyRevisionUnique // Absolutely Unique ID - Editable - { get { return _MyRevisionUnique; } } + protected static int RevisionUnique => ++_RevisionUnique; + private readonly int _MyRevisionUnique = RevisionUnique; + // Absolutely Unique ID - Editable + public int MyRevisionUnique => _MyRevisionUnique; protected Revision() {/* require use of factory methods */ AddToCache(this); @@ -555,15 +458,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; ~Revision() { _CountFinalized++; @@ -588,8 +487,6 @@ namespace VEPROMS.CSLA.Library } public static Revision New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Revision"); try { return DataPortal.Create(); @@ -662,8 +559,6 @@ namespace VEPROMS.CSLA.Library } public static Revision Get(int revisionID) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Revision"); try { Revision tmp = GetCachedByPrimaryKey(revisionID); @@ -689,14 +584,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new Revision(dr); return null; } - internal Revision(SafeDataReader dr) - { - ReadData(dr); - } + internal Revision(SafeDataReader dr) => ReadData(dr); public static void Delete(int revisionID) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Revision"); try { DataPortal.Delete(new PKCriteria(revisionID)); @@ -708,12 +598,6 @@ namespace VEPROMS.CSLA.Library } public override Revision Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Revision"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Revision"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Revision"); try { BuildRefreshList(); @@ -733,13 +617,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _RevisionID; - public int RevisionID - { get { return _RevisionID; } } - public PKCriteria(int revisionID) - { - _RevisionID = revisionID; - } + private readonly int _RevisionID; + public int RevisionID => _RevisionID; + public PKCriteria(int revisionID) => _RevisionID = revisionID; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -849,41 +729,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 = "addRevision"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ItemID", _ItemID); - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); - if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); - cm.Parameters.AddWithValue("@Notes", _Notes); - 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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int); - param_RevisionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RevisionID); - 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 - _RevisionID = (int)cm.Parameters["@newRevisionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRevision"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); + if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); + cm.Parameters.AddWithValue("@Notes", _Notes); + 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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_RevisionID); + 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 + _RevisionID = (int)cm.Parameters["@newRevisionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects - if (_RevisionChecks != null) _RevisionChecks.Update(this); - if (_RevisionVersions != null) _RevisionVersions.Update(this); + _RevisionChecks?.Update(this); + _RevisionVersions?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -914,11 +801,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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int); - param_RevisionID.Direction = ParameterDirection.Output; + SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_RevisionID); - 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(); @@ -963,39 +854,44 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.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 = "updateRevision"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RevisionID", _RevisionID); - cm.Parameters.AddWithValue("@ItemID", _ItemID); - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); - if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); - cm.Parameters.AddWithValue("@Notes", _Notes); - 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 = "updateRevision"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RevisionID", _RevisionID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); + if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); + cm.Parameters.AddWithValue("@Notes", _Notes); + 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 (_RevisionChecks != null) _RevisionChecks.Update(this); - if (_RevisionVersions != null) _RevisionVersions.Update(this); + _RevisionChecks?.Update(this); + _RevisionVersions?.Update(this); } catch (Exception ex) { @@ -1006,18 +902,21 @@ 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 = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID); - else - _LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID); + else + _LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } - if (_RevisionChecks != null) _RevisionChecks.Update(this); - if (_RevisionVersions != null) _RevisionVersions.Update(this); + _RevisionChecks?.Update(this); + _RevisionVersions?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] public static byte[] Update(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID, ref byte[] lastChanged) @@ -1042,8 +941,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(); @@ -1128,16 +1029,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _RevisionID; + private readonly int _RevisionID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int revisionID) - { - _RevisionID = revisionID; - } + public bool Exists => _exists; + public ExistsCommand(int revisionID) => _RevisionID = revisionID; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Execute", GetHashCode()); @@ -1167,7 +1062,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - RevisionExtension _RevisionExtension = new RevisionExtension(); + readonly RevisionExtension _RevisionExtension = new RevisionExtension(); [Serializable()] partial class RevisionExtension : extensionBase { @@ -1176,18 +1071,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual int DefaultTypeID - { - get { return 1; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual int DefaultTypeID => 1; + 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) { @@ -1216,61 +1102,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 Revision) + if (destType == typeof(string) && value is Revision revision) { // Return the ToString value - return ((Revision)value).ToString(); + return revision.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RevisionExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class Revision -// { -// partial class RevisionExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual int DefaultTypeID -// { -// get { return 1; } -// } -// 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/RevisionCheck.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs index 3f229c9b..756c10bd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.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 _CheckID; [System.ComponentModel.DataObjectField(true, true)] public int CheckID @@ -195,19 +189,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RevisionCheck - protected override object GetIdValue() - { - return MyRevisionCheckUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RevisionCheck.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RevisionCheck - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyRevisionCheckUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -222,18 +204,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyStage != null && _MyStage.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) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyStage == null || _MyStage.IsValidList(list)); } #endregion #region ValidationRules @@ -263,8 +242,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() @@ -289,76 +268,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(CheckID, ""); - //AuthorizationRules.AllowRead(StageID, ""); - //AuthorizationRules.AllowWrite(StageID, ""); - //AuthorizationRules.AllowRead(ConsistencyChecks, ""); - //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); - //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 _RevisionCheckUnique = 0; - private static int RevisionCheckUnique - { get { return ++_RevisionCheckUnique; } } - private int _MyRevisionCheckUnique = RevisionCheckUnique; - public int MyRevisionCheckUnique // Absolutely Unique ID - Editable FK - { get { return _MyRevisionCheckUnique; } } - internal static RevisionCheck New(Stage myStage) - { - return new RevisionCheck(myStage); - } - internal static RevisionCheck Get(SafeDataReader dr) - { - return new RevisionCheck(dr); - } + private static int RevisionCheckUnique => ++_RevisionCheckUnique; + private readonly int _MyRevisionCheckUnique = RevisionCheckUnique; + // Absolutely Unique ID - Editable FK + public int MyRevisionCheckUnique => _MyRevisionCheckUnique; + internal static RevisionCheck New(Stage myStage) => new RevisionCheck(myStage); + internal static RevisionCheck Get(SafeDataReader dr) => new RevisionCheck(dr); public RevisionCheck() { MarkAsChild(); @@ -386,15 +311,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; ~RevisionCheck() { _CountFinalized++; @@ -434,33 +355,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(Revision myRevision) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Check.Add(cn, ref _CheckID, myRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Check.Add(cn, ref _CheckID, myRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); + } + MarkOld(); } internal void Update(Revision myRevision) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Check.Update(cn, ref _CheckID, myRevision.RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Check.Update(cn, ref _CheckID, myRevision.RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(Revision myRevision) { // 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"]; - Check.Remove(cn, _CheckID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Check.Remove(cn, _CheckID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - RevisionCheckExtension _RevisionCheckExtension = new RevisionCheckExtension(); + readonly RevisionCheckExtension _RevisionCheckExtension = new RevisionCheckExtension(); [Serializable()] partial class RevisionCheckExtension : extensionBase { @@ -469,14 +400,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) { @@ -505,57 +430,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 RevisionCheck) + if (destType == typeof(string) && value is RevisionCheck check) { // Return the ToString value - return ((RevisionCheck)value).ToString(); + return check.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RevisionCheckExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RevisionCheck -// { -// partial class RevisionCheckExtension : 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/RevisionChecks.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.cs index ea6126fd..d24c82c4 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.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 RevisionCheck this[Check myCheck] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RevisionCheck this[Check myCheck] { get { @@ -61,7 +56,7 @@ namespace VEPROMS.CSLA.Library public RevisionCheck Add(Stage myStage) // One to Many { RevisionCheck check = RevisionCheck.New(myStage); - this.Add(check); + Add(check); return check; } public void Remove(Check myCheck) @@ -103,23 +98,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 (RevisionCheck 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 (RevisionCheck 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 +129,14 @@ namespace VEPROMS.CSLA.Library get { IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + return hasBrokenRules?.BrokenRules; } } - #endregion - #region Factory Methods - internal static RevisionChecks New() - { - return new RevisionChecks(); - } - internal static RevisionChecks Get(SafeDataReader dr) - { - return new RevisionChecks(dr); - } - public static RevisionChecks GetByRevisionID(int revisionID) + #endregion + #region Factory Methods + internal static RevisionChecks New() => new RevisionChecks(); + internal static RevisionChecks Get(SafeDataReader dr) => new RevisionChecks(dr); + public static RevisionChecks GetByRevisionID(int revisionID) { try { @@ -161,11 +147,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RevisionChecks.GetByRevisionID", ex); } } - private RevisionChecks() - { - MarkAsChild(); - } - internal RevisionChecks(SafeDataReader dr) + private RevisionChecks() => MarkAsChild(); + internal RevisionChecks(SafeDataReader dr) { MarkAsChild(); Fetch(dr); @@ -174,16 +157,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; } } - ~RevisionChecks() + 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; + ~RevisionChecks() { _CountFinalized++; } @@ -198,19 +177,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(RevisionCheck.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RevisionCheck.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class RevisionIDCriteria { - public RevisionIDCriteria(int revisionID) - { - _RevisionID = revisionID; - } - private int _RevisionID; + public RevisionIDCriteria(int revisionID) => _RevisionID = revisionID; + private int _RevisionID; public int RevisionID { get { return _RevisionID; } @@ -219,7 +195,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RevisionIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionChecks.DataPortal_FetchRevisionID", GetHashCode()); try { @@ -233,7 +209,7 @@ namespace VEPROMS.CSLA.Library cm.CommandTimeout = Database.DefaultTimeout; using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) { - while (dr.Read()) this.Add(new RevisionCheck(dr)); + while (dr.Read()) Add(new RevisionCheck(dr)); } } } @@ -243,11 +219,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionChecks.DataPortal_FetchRevisionID", ex); throw new DbCslaException("RevisionChecks.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(Revision revision) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects @@ -266,49 +242,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 RevisionChecksPropertyDescriptor pd = new RevisionChecksPropertyDescriptor(this, i); @@ -325,7 +290,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RevisionChecksPropertyDescriptor : vlnListPropertyDescriptor { - private RevisionCheck Item { get { return (RevisionCheck)_Item; } } public RevisionChecksPropertyDescriptor(RevisionChecks collection, int index) : base(collection, index) { ;} } #endregion @@ -334,10 +298,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 RevisionChecks) + if (destType == typeof(string) && value is RevisionChecks checks) { // Return department and department role separated by comma. - return ((RevisionChecks)value).Items.Count.ToString() + " Checks"; + return $"{checks.Items.Count} Checks"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs index 02632fb9..328dcb1b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.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 RevisionInfo : ReadOnlyBase, IDisposable { public event RevisionInfoEvent 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(RevisionInfo revisionInfo) { @@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(revisionInfo)) _CacheList.Remove(revisionInfo); // 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 Revision _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } private int _RevisionID; [System.ComponentModel.DataObjectField(true, true)] public int RevisionID @@ -261,32 +245,19 @@ namespace VEPROMS.CSLA.Library foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) tmp._RevisionVersionCount = -1; // This will cause the data to be requeried } - // CSLATODO: Replace base RevisionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RevisionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check RevisionInfo.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 RevisionInfo - protected override object GetIdValue() - { - return MyRevisionInfoUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyRevisionInfoUnique; // Absolutely Unique ID #endregion #region Factory Methods private static int _RevisionInfoUnique = 0; - private static int RevisionInfoUnique - { get { return ++_RevisionInfoUnique; } } - private int _MyRevisionInfoUnique = RevisionInfoUnique; - public int MyRevisionInfoUnique // Absolutely Unique ID - Info - { get { return _MyRevisionInfoUnique; } } + private static int RevisionInfoUnique => ++_RevisionInfoUnique; + private readonly int _MyRevisionInfoUnique = RevisionInfoUnique; + // Absolutely Unique ID - Info + public int MyRevisionInfoUnique => _MyRevisionInfoUnique; protected RevisionInfo() {/* require use of factory methods */ AddToCache(this); @@ -295,15 +266,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; ~RevisionInfo() { _CountFinalized++; @@ -320,10 +287,7 @@ namespace VEPROMS.CSLA.Library if (listRevisionInfo.Count == 0) // If there are no items left in the list _CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list } - public virtual Revision Get() - { - return _Editable = Revision.Get(_RevisionID); - } + public virtual Revision Get() => _Editable = Revision.Get(_RevisionID); public static void Refresh(Revision tmp) { string key = tmp.RevisionID.ToString(); @@ -347,8 +311,6 @@ namespace VEPROMS.CSLA.Library } public static RevisionInfo Get(int revisionID) { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Revision"); try { RevisionInfo tmp = GetCachedByPrimaryKey(revisionID); @@ -387,13 +349,9 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _RevisionID; - public int RevisionID - { get { return _RevisionID; } } - public PKCriteria(int revisionID) - { - _RevisionID = revisionID; - } + private readonly int _RevisionID; + public int RevisionID => _RevisionID; + public PKCriteria(int revisionID) => _RevisionID = revisionID; } private void ReadData(SafeDataReader dr) { @@ -458,7 +416,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Refresh #region extension - RevisionInfoExtension _RevisionInfoExtension = new RevisionInfoExtension(); + readonly RevisionInfoExtension _RevisionInfoExtension = new RevisionInfoExtension(); [Serializable()] partial class RevisionInfoExtension : extensionBase { } [Serializable()] @@ -474,10 +432,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 RevisionInfo) + if (destType == typeof(string) && value is RevisionInfo info) { // Return the ToString value - return ((RevisionInfo)value).ToString(); + return info.ToString(); } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs index bcd78a09..7fd9627a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.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 (RevisionInfo 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; } } - ~RevisionInfoList() + 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; + ~RevisionInfoList() { _CountFinalized++; } @@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RevisionInfoList.Get", ex); } } - /// - /// Reset the list of all RevisionInfo. - /// - public static void Reset() - { - _RevisionInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static RevisionInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on RevisionInfoList.Get", ex); - // } - //} - private RevisionInfoList() + /// + /// Reset the list of all RevisionInfo. + /// + public static void Reset() => _RevisionInfoList = null; + private RevisionInfoList() { /* 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}] RevisionInfoList.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 RevisionInfo(dr)); + while (dr.Read()) Add(new RevisionInfo(dr)); IsReadOnly = true; } } @@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfoList.DataPortal_Fetch", ex); throw new DbCslaException("RevisionInfoList.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 RevisionInfoListPropertyDescriptor pd = new RevisionInfoListPropertyDescriptor(this, i); @@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RevisionInfoListPropertyDescriptor : vlnListPropertyDescriptor { - private RevisionInfo Item { get { return (RevisionInfo)_Item; } } public RevisionInfoListPropertyDescriptor(RevisionInfoList 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 RevisionInfoList) + if (destType == typeof(string) && value is RevisionInfoList list) { // Return department and department role separated by comma. - return ((RevisionInfoList)value).Items.Count.ToString() + " Revisions"; + return $"{list.Items.Count} Revisions"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs index 898f2c29..844b65b3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.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 _VersionID; [System.ComponentModel.DataObjectField(true, true)] public int VersionID @@ -230,19 +224,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RevisionVersion - protected override object GetIdValue() - { - return MyRevisionVersionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RevisionVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RevisionVersion - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyRevisionVersionUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -257,18 +239,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyStage != null && _MyStage.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) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyStage == null || _MyStage.IsValidList(list)); } #endregion #region ValidationRules @@ -298,8 +277,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() @@ -321,78 +300,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(VersionID, ""); - //AuthorizationRules.AllowRead(StageID, ""); - //AuthorizationRules.AllowWrite(StageID, ""); - //AuthorizationRules.AllowRead(PDF, ""); - //AuthorizationRules.AllowWrite(PDF, ""); - //AuthorizationRules.AllowRead(SummaryPDF, ""); - //AuthorizationRules.AllowWrite(SummaryPDF, ""); - //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 _RevisionVersionUnique = 0; - private static int RevisionVersionUnique - { get { return ++_RevisionVersionUnique; } } - private int _MyRevisionVersionUnique = RevisionVersionUnique; - public int MyRevisionVersionUnique // Absolutely Unique ID - Editable FK - { get { return _MyRevisionVersionUnique; } } - internal static RevisionVersion New(Stage myStage, DateTime dts, string userID) - { - return new RevisionVersion(myStage, dts, userID); - } - internal static RevisionVersion Get(SafeDataReader dr) - { - return new RevisionVersion(dr); - } + private static int RevisionVersionUnique => ++_RevisionVersionUnique; + private readonly int _MyRevisionVersionUnique = RevisionVersionUnique; + // Absolutely Unique ID - Editable FK + public int MyRevisionVersionUnique => _MyRevisionVersionUnique; + internal static RevisionVersion New(Stage myStage, DateTime dts, string userID) => new RevisionVersion(myStage, dts, userID); + internal static RevisionVersion Get(SafeDataReader dr) => new RevisionVersion(dr); public RevisionVersion() { MarkAsChild(); @@ -420,15 +343,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; ~RevisionVersion() { _CountFinalized++; @@ -469,33 +388,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(Revision myRevision) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Version.Add(cn, ref _VersionID, myRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Version.Add(cn, ref _VersionID, myRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); + } + MarkOld(); } internal void Update(Revision myRevision) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Version.Update(cn, ref _VersionID, myRevision.RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Version.Update(cn, ref _VersionID, myRevision.RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(Revision myRevision) { // 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"]; - Version.Remove(cn, _VersionID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Version.Remove(cn, _VersionID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - RevisionVersionExtension _RevisionVersionExtension = new RevisionVersionExtension(); + readonly RevisionVersionExtension _RevisionVersionExtension = new RevisionVersionExtension(); [Serializable()] partial class RevisionVersionExtension : extensionBase { @@ -532,49 +461,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 RevisionVersion) + if (destType == typeof(string) && value is RevisionVersion version) { // Return the ToString value - return ((RevisionVersion)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 RevisionVersionExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RevisionVersion -// { -// partial class RevisionVersionExtension : 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/RevisionVersions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.cs index 8f3b9433..388b3e74 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.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 RevisionVersion this[Version myVersion] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RevisionVersion this[Version myVersion] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public RevisionVersion GetItem(Version myVersion) + public new System.Collections.Generic.IList Items => base.Items; + public RevisionVersion GetItem(Version myVersion) { foreach (RevisionVersion version in this) if (version.VersionID == myVersion.VersionID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public RevisionVersion Add(Stage myStage, DateTime dts, string userID) // One to Many { RevisionVersion version = RevisionVersion.New(myStage, dts, userID); - this.Add(version); + Add(version); return version; } public void Remove(Version myVersion) @@ -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 (RevisionVersion 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 (RevisionVersion 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 RevisionVersions New() - { - return new RevisionVersions(); - } - internal static RevisionVersions Get(SafeDataReader dr) - { - return new RevisionVersions(dr); - } - public static RevisionVersions GetByRevisionID(int revisionID) + #endregion + #region Factory Methods + internal static RevisionVersions New() => new RevisionVersions(); + internal static RevisionVersions Get(SafeDataReader dr) => new RevisionVersions(dr); + public static RevisionVersions GetByRevisionID(int revisionID) { try { @@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RevisionVersions.GetByRevisionID", ex); } } - private RevisionVersions() - { - MarkAsChild(); - } - internal RevisionVersions(SafeDataReader dr) + private RevisionVersions() => MarkAsChild(); + internal RevisionVersions(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; } } - ~RevisionVersions() + 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; + ~RevisionVersions() { _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(RevisionVersion.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RevisionVersion.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class RevisionIDCriteria { - public RevisionIDCriteria(int revisionID) - { - _RevisionID = revisionID; - } - private int _RevisionID; + public RevisionIDCriteria(int revisionID) => _RevisionID = revisionID; + private int _RevisionID; public int RevisionID { get { return _RevisionID; } @@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RevisionIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionVersions.DataPortal_FetchRevisionID", 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 RevisionVersion(dr)); + while (dr.Read()) Add(new RevisionVersion(dr)); } } } @@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionVersions.DataPortal_FetchRevisionID", ex); throw new DbCslaException("RevisionVersions.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(Revision revision) { - 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 RevisionVersionsPropertyDescriptor pd = new RevisionVersionsPropertyDescriptor(this, i); @@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RevisionVersionsPropertyDescriptor : vlnListPropertyDescriptor { - private RevisionVersion Item { get { return (RevisionVersion)_Item; } } public RevisionVersionsPropertyDescriptor(RevisionVersions 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 RevisionVersions) + if (destType == typeof(string) && value is RevisionVersions versions) { // Return department and department role separated by comma. - return ((RevisionVersions)value).Items.Count.ToString() + " Versions"; + return $"{versions.Items.Count} Versions"; } return base.ConvertTo(context, culture, value, destType); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs index 1e497a4c..7927a87d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Role.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; @@ -82,6 +80,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(Role role) { @@ -91,7 +90,9 @@ namespace VEPROMS.CSLA.Library { while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private static Dictionary> _CacheByName = new Dictionary>(); private static void ConvertListToDictionary() { @@ -126,15 +127,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 _nextRID = -1; - public static int NextRID - { - get { return _nextRID--; } - } + public static int NextRID => _nextRID--; private int _RID; [System.ComponentModel.DataObjectField(true, true)] public int RID @@ -252,10 +247,7 @@ namespace VEPROMS.CSLA.Library return _RoleAssignments; } } - public void Reset_RoleAssignments() - { - _RoleAssignmentCount = -1; - } + public void Reset_RoleAssignments() => _RoleAssignmentCount = -1; private int _RolePermissionCount = 0; /// /// Count of RolePermissions for this Role @@ -287,10 +279,7 @@ namespace VEPROMS.CSLA.Library return _RolePermissions; } } - public void Reset_RolePermissions() - { - _RolePermissionCount = -1; - } + public void Reset_RolePermissions() => _RolePermissionCount = -1; public override bool IsDirty { get @@ -305,37 +294,22 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_RoleAssignments == null ? false : _RoleAssignments.IsDirtyList(list)) || (_RolePermissions == null ? false : _RolePermissions.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_RoleAssignments != null && _RoleAssignments.IsDirtyList(list)) || (_RolePermissions != null && _RolePermissions.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) && (_RoleAssignments == null ? true : _RoleAssignments.IsValidList(list)) && (_RolePermissions == null ? true : _RolePermissions.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_RoleAssignments == null || _RoleAssignments.IsValidList(list)) && (_RolePermissions == null || _RolePermissions.IsValidList(list)); } - // CSLATODO: Replace base Role.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Role - //public override string ToString() - //{ - // return base.ToString(); - //} // CSLATODO: Check Role.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 Role - protected override object GetIdValue() - { - return MyRoleUnique; // Absolutely Unique ID - } + protected override object GetIdValue() => MyRoleUnique; // Absolutely Unique ID #endregion #region ValidationRules [NonSerialized] @@ -365,8 +339,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() @@ -395,31 +369,11 @@ namespace VEPROMS.CSLA.Library _RoleExtension.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(RID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); _RoleExtension.AddAuthorizationRules(AuthorizationRules); } protected override void AddInstanceAuthorizationRules() @@ -427,56 +381,14 @@ namespace VEPROMS.CSLA.Library //CSLATODO: Who can read/write which fields _RoleExtension.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 += _RoleAssignmentCount; - usedByCount += _RolePermissionCount; - 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 _RoleUnique = 0; - protected static int RoleUnique - { get { return ++_RoleUnique; } } - private int _MyRoleUnique = RoleUnique; - public int MyRoleUnique // Absolutely Unique ID - Editable - { get { return _MyRoleUnique; } } + protected static int RoleUnique => ++_RoleUnique; + private readonly int _MyRoleUnique = RoleUnique; + // Absolutely Unique ID - Editable + public int MyRoleUnique => _MyRoleUnique; protected Role() {/* require use of factory methods */ AddToCache(this); @@ -485,15 +397,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; ~Role() { _CountFinalized++; @@ -530,8 +438,6 @@ namespace VEPROMS.CSLA.Library } public static Role New() { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); try { return DataPortal.Create(); @@ -591,8 +497,6 @@ namespace VEPROMS.CSLA.Library } public static Role Get(int rid) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); try { Role tmp = GetCachedByPrimaryKey(rid); @@ -615,8 +519,6 @@ namespace VEPROMS.CSLA.Library } public static Role GetByName(string name) { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); try { Role tmp = GetCachedByName(name); @@ -642,14 +544,9 @@ namespace VEPROMS.CSLA.Library if (dr.Read()) return new Role(dr); return null; } - internal Role(SafeDataReader dr) - { - ReadData(dr); - } + internal Role(SafeDataReader dr) => ReadData(dr); public static void Delete(int rid) { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); try { DataPortal.Delete(new PKCriteria(rid)); @@ -661,12 +558,6 @@ namespace VEPROMS.CSLA.Library } public override Role Save() { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Role"); try { BuildRefreshList(); @@ -686,24 +577,16 @@ namespace VEPROMS.CSLA.Library [Serializable()] protected class PKCriteria { - private int _RID; - public int RID - { get { return _RID; } } - public PKCriteria(int rid) - { - _RID = rid; - } + private readonly int _RID; + public int RID => _RID; + public PKCriteria(int rid) => _RID = rid; } [Serializable()] private class NameCriteria { - private string _Name; - public string Name - { get { return _Name; } } - public NameCriteria(string name) - { - _Name = name; - } + private readonly string _Name; + public string Name => _Name; + public NameCriteria(string name) => _Name = name; } // CSLATODO: If Create needs to access DB - It should not be marked RunLocal [RunLocal()] @@ -844,37 +727,44 @@ 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 = "addRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UsrID", _UsrID); - // Output Calculated Columns - SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); - param_RID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RID); - 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 - _RID = (int)cm.Parameters["@newRID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UsrID", _UsrID); + // Output Calculated Columns + SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_RID); + 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 + _RID = (int)cm.Parameters["@newRID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } + MarkOld(); // update child objects - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); + _RoleAssignments?.Update(this); + _RolePermissions?.Update(this); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.SQLInsert", GetHashCode()); } catch (Exception ex) @@ -901,11 +791,15 @@ namespace VEPROMS.CSLA.Library if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UsrID", usrID); // Output Calculated Columns - SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); - param_RID.Direction = ParameterDirection.Output; + SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_RID); - 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(); @@ -950,35 +844,40 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.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 = "updateRole"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RID", _RID); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UsrID", _UsrID); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRole"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RID", _RID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UsrID", _UsrID); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; + cm.Parameters.Add(param_LastChanged); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } } } + MarkOld(); // use the open connection to update child objects - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); + _RoleAssignments?.Update(this); + _RolePermissions?.Update(this); } catch (Exception ex) { @@ -989,18 +888,21 @@ 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 = Role.Add(cn, ref _RID, _Name, _Title, _DTS, _UsrID); - else - _LastChanged = Role.Update(cn, ref _RID, _Name, _Title, _DTS, _UsrID, ref _LastChanged); + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + if (IsNew) + _LastChanged = Role.Add(cn, ref _RID, _Name, _Title, _DTS, _UsrID); + else + _LastChanged = Role.Update(cn, ref _RID, _Name, _Title, _DTS, _UsrID, ref _LastChanged); + } + MarkOld(); } - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); + _RoleAssignments?.Update(this); + _RolePermissions?.Update(this); } [Transactional(TransactionalTypes.TransactionScope)] public static byte[] Update(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID, ref byte[] lastChanged) @@ -1021,8 +923,10 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@UsrID", usrID); cm.Parameters.AddWithValue("@LastChanged", lastChanged); // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp) + { + Direction = ParameterDirection.Output + }; cm.Parameters.Add(param_LastChanged); // CSLATODO: Define any additional output parameters cm.ExecuteNonQuery(); @@ -1107,16 +1011,10 @@ namespace VEPROMS.CSLA.Library [Serializable()] private class ExistsCommand : CommandBase { - private int _RID; + private readonly int _RID; private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rid) - { - _RID = rid; - } + public bool Exists => _exists; + public ExistsCommand(int rid) => _RID = rid; protected override void DataPortal_Execute() { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Execute", GetHashCode()); @@ -1146,7 +1044,7 @@ namespace VEPROMS.CSLA.Library #endregion // Standard Default Code #region extension - RoleExtension _RoleExtension = new RoleExtension(); + readonly RoleExtension _RoleExtension = new RoleExtension(); [Serializable()] partial class RoleExtension : extensionBase { @@ -1155,14 +1053,8 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -1191,57 +1083,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 Role) + if (destType == typeof(string) && value is Role role) { // Return the ToString value - return ((Role)value).ToString(); + return role.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RoleExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class Role -// { -// partial class RoleExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual DateTime DefaultDTS -// { -// get { return DateTime.Now; } -// } -// public virtual string DefaultUsrID -// { -// get { return Environment.UserName.ToUpper(); } -// } -// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowRead(Dbid, ""); -// } -// 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/RoleAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs index e1d072f9..9a81bb7c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.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 _AID; [System.ComponentModel.DataObjectField(true, true)] public int AID @@ -352,19 +346,7 @@ namespace VEPROMS.CSLA.Library /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RoleAssignment - protected override object GetIdValue() - { - return MyRoleAssignmentUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RoleAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} + protected override object GetIdValue() => MyRoleAssignmentUnique; // Absolutely Unique ID public override bool IsDirty { get @@ -379,18 +361,15 @@ namespace VEPROMS.CSLA.Library if (base.IsDirty || list.Contains(this)) return base.IsDirty; list.Add(this); - return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } + return base.IsDirty || (_MyGroup != null && _MyGroup.IsDirtyList(list)) || (_MyFolder != null && _MyFolder.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) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); + return ((IsNew && !IsDirty) || base.IsValid) && (_MyGroup == null || _MyGroup.IsValidList(list)) && (_MyFolder == null || _MyFolder.IsValidList(list)); } #endregion #region ValidationRules @@ -421,8 +400,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() @@ -484,80 +463,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(AID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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 _RoleAssignmentUnique = 0; - private static int RoleAssignmentUnique - { get { return ++_RoleAssignmentUnique; } } - private int _MyRoleAssignmentUnique = RoleAssignmentUnique; - public int MyRoleAssignmentUnique // Absolutely Unique ID - Editable FK - { get { return _MyRoleAssignmentUnique; } } - internal static RoleAssignment New(Group myGroup, Folder myFolder) - { - return new RoleAssignment(myGroup, myFolder); - } - internal static RoleAssignment Get(SafeDataReader dr) - { - return new RoleAssignment(dr); - } + private static int RoleAssignmentUnique => ++_RoleAssignmentUnique; + private readonly int _MyRoleAssignmentUnique = RoleAssignmentUnique; + // Absolutely Unique ID - Editable FK + public int MyRoleAssignmentUnique => _MyRoleAssignmentUnique; + internal static RoleAssignment New(Group myGroup, Folder myFolder) => new RoleAssignment(myGroup, myFolder); + internal static RoleAssignment Get(SafeDataReader dr) => new RoleAssignment(dr); public RoleAssignment() { MarkAsChild(); @@ -588,15 +509,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; ~RoleAssignment() { _CountFinalized++; @@ -648,33 +565,43 @@ namespace VEPROMS.CSLA.Library internal void Insert(Role myRole) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, myRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, myRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID); + } + MarkOld(); } internal void Update(Role myRole) { // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Assignment.Update(cn, ref _AID, _GID, myRole.RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + if (!IsDirty) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + _LastChanged = Assignment.Update(cn, ref _AID, _GID, myRole.RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + } + MarkOld(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(Role myRole) { // 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"]; - Assignment.Remove(cn, _AID); + if (IsNew) return; + using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) + { + Assignment.Remove(cn, _AID); + } + MarkNew(); } #endregion // Standard Default Code #region extension - RoleAssignmentExtension _RoleAssignmentExtension = new RoleAssignmentExtension(); + readonly RoleAssignmentExtension _RoleAssignmentExtension = new RoleAssignmentExtension(); [Serializable()] partial class RoleAssignmentExtension : extensionBase { @@ -683,18 +610,9 @@ namespace VEPROMS.CSLA.Library class extensionBase { // Default Values - public virtual string DefaultStartDate - { - get { return DateTime.Now.ToShortDateString(); } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } + public virtual string DefaultStartDate => DateTime.Now.ToShortDateString(); + public virtual DateTime DefaultDTS => DateTime.Now; + public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID; // Authorization Rules public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) { @@ -723,61 +641,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 RoleAssignment) + if (destType == typeof(string) && value is RoleAssignment assignment) { // Return the ToString value - return ((RoleAssignment)value).ToString(); + return assignment.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace - - -//// The following is a sample Extension File. You can use it to create RoleAssignmentExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; - -//namespace VEPROMS.CSLA.Library -//{ -// public partial class RoleAssignment -// { -// partial class RoleAssignmentExtension : extensionBase -// { -// // CSLATODO: Override automatic defaults -// public virtual SmartDate DefaultStartDate -// { -// get { return DateTime.Now.ToShortDateString(); } -// } -// public virtual DateTime DefaultDTS -// { -// get { return DateTime.Now; } -// } -// public virtual string DefaultUsrID -// { -// get { return Environment.UserName.ToUpper(); } -// } -// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) -// { -// //rules.AllowRead(Dbid, ""); -// } -// 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/RoleAssignments.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignments.cs index e03ec266..8a875c4f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignments.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignments.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 RoleAssignment this[Assignment myAssignment] + private readonly string _ErrorMessage = string.Empty; + public string ErrorMessage => _ErrorMessage; + // One To Many + public RoleAssignment this[Assignment myAssignment] { get { @@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library return null; } } - public new System.Collections.Generic.IList Items - { - get { return base.Items; } - } - public RoleAssignment GetItem(Assignment myAssignment) + public new System.Collections.Generic.IList Items => base.Items; + public RoleAssignment GetItem(Assignment myAssignment) { foreach (RoleAssignment assignment in this) if (assignment.AID == myAssignment.AID) @@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library public RoleAssignment Add(Group myGroup, Folder myFolder) // One to Many { RoleAssignment assignment = RoleAssignment.New(myGroup, myFolder); - this.Add(assignment); + Add(assignment); return assignment; } public void Remove(Assignment myAssignment) @@ -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 (RoleAssignment 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 (RoleAssignment 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 RoleAssignments New() - { - return new RoleAssignments(); - } - internal static RoleAssignments Get(SafeDataReader dr) - { - return new RoleAssignments(dr); - } - public static RoleAssignments GetByRID(int rid) + #endregion + #region Factory Methods + internal static RoleAssignments New() => new RoleAssignments(); + internal static RoleAssignments Get(SafeDataReader dr) => new RoleAssignments(dr); + public static RoleAssignments GetByRID(int rid) { try { @@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RoleAssignments.GetByRID", ex); } } - private RoleAssignments() - { - MarkAsChild(); - } - internal RoleAssignments(SafeDataReader dr) + private RoleAssignments() => MarkAsChild(); + internal RoleAssignments(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; } } - ~RoleAssignments() + 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; + ~RoleAssignments() { _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(RoleAssignment.Get(dr)); - this.RaiseListChangedEvents = true; + Add(RoleAssignment.Get(dr)); + RaiseListChangedEvents = true; } [Serializable()] private class RIDCriteria { - public RIDCriteria(int rid) - { - _RID = rid; - } - private int _RID; + public RIDCriteria(int rid) => _RID = rid; + private int _RID; public int RID { get { return _RID; } @@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library } private void DataPortal_Fetch(RIDCriteria criteria) { - this.RaiseListChangedEvents = false; + RaiseListChangedEvents = false; if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleAssignments.DataPortal_FetchRID", 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 RoleAssignment(dr)); + while (dr.Read()) Add(new RoleAssignment(dr)); } } } @@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleAssignments.DataPortal_FetchRID", ex); throw new DbCslaException("RoleAssignments.DataPortal_Fetch", ex); } - this.RaiseListChangedEvents = true; + RaiseListChangedEvents = true; } internal void Update(Role role) { - 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 RoleAssignmentsPropertyDescriptor pd = new RoleAssignmentsPropertyDescriptor(this, i); @@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library /// public partial class RoleAssignmentsPropertyDescriptor : vlnListPropertyDescriptor { - private RoleAssignment Item { get { return (RoleAssignment)_Item; } } public RoleAssignmentsPropertyDescriptor(RoleAssignments 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 RoleAssignments) + if (destType == typeof(string) && value is RoleAssignments assignments) { // Return department and department role separated by comma. - return ((RoleAssignments)value).Items.Count.ToString() + " Assignments"; + return $"{assignments.Items.Count} Assignments"; } return base.ConvertTo(context, culture, value, destType); }