CSLA - R - Group 1

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