CSLA - M through P

This commit is contained in:
2026-09-11 09:50:40 -04:00
parent e41a4ea65d
commit d9f8f6cb37
20 changed files with 1196 additions and 2757 deletions
+121 -261
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshMemberships.Add(this);
}
private void ClearRefreshList()
{
_RefreshMemberships = new List<Membership>();
}
private void ClearRefreshList() => _RefreshMemberships = new List<Membership>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -58,6 +53,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Membership> _CacheList = new List<Membership>();
protected static void AddToCache(Membership membership)
{
@@ -67,6 +63,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Membership>> _CacheByPrimaryKey = new Dictionary<string, List<Membership>>();
private static void ConvertListToDictionary()
{
@@ -92,15 +89,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextUGID = -1;
public static int NextUGID
{
get { return _nextUGID--; }
}
public static int NextUGID => _nextUGID--;
private int _UGID;
[System.ComponentModel.DataObjectField(true, true)]
public int UGID
@@ -298,7 +289,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyUser == null ? false : _MyUser.IsDirtyList(list));
return base.IsDirty || (_MyGroup != null && _MyGroup.IsDirtyList(list)) || (_MyUser != null && _MyUser.IsDirtyList(list));
}
public override bool IsValid
{
@@ -307,28 +298,16 @@ namespace VEPROMS.CSLA.Library
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyUser == null ? true : _MyUser.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyGroup == null || _MyGroup.IsValidList(list)) && (_MyUser == null || _MyUser.IsValidList(list));
}
// CSLATODO: Replace base Membership.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Membership</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Membership.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Membership</returns>
protected override object GetIdValue()
{
return MyMembershipUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyMembershipUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -358,8 +337,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -431,37 +410,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(UGID, "<Role(s)>");
//AuthorizationRules.AllowRead(UID, "<Role(s)>");
//AuthorizationRules.AllowRead(GID, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UID, "<Role(s)>");
//AuthorizationRules.AllowWrite(GID, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_MembershipExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -469,42 +422,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_MembershipExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _MembershipUnique = 0;
protected static int MembershipUnique
{ get { return ++_MembershipUnique; } }
private int _MyMembershipUnique = MembershipUnique;
public int MyMembershipUnique // Absolutely Unique ID - Editable
{ get { return _MyMembershipUnique; } }
protected static int MembershipUnique => ++_MembershipUnique;
private readonly int _MyMembershipUnique = MembershipUnique;
// Absolutely Unique ID - Editable
public int MyMembershipUnique => _MyMembershipUnique;
protected Membership()
{/* require use of factory methods */
AddToCache(this);
@@ -513,15 +438,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Membership()
{
_CountFinalized++;
@@ -546,8 +467,6 @@ namespace VEPROMS.CSLA.Library
}
public static Membership New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Membership");
try
{
return DataPortal.Create<Membership>();
@@ -619,8 +538,6 @@ namespace VEPROMS.CSLA.Library
}
public static Membership Get(int ugid)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Membership");
try
{
Membership tmp = GetCachedByPrimaryKey(ugid);
@@ -646,14 +563,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Membership(dr);
return null;
}
internal Membership(SafeDataReader dr)
{
ReadData(dr);
}
internal Membership(SafeDataReader dr) => ReadData(dr);
public static void Delete(int ugid)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Membership");
try
{
DataPortal.Delete(new PKCriteria(ugid));
@@ -665,12 +577,6 @@ namespace VEPROMS.CSLA.Library
}
public override Membership Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Membership");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Membership");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Membership");
try
{
BuildRefreshList();
@@ -690,13 +596,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _UGID;
public int UGID
{ get { return _UGID; } }
public PKCriteria(int ugid)
{
_UGID = ugid;
}
private readonly int _UGID;
public int UGID => _UGID;
public PKCriteria(int ugid) => _UGID = ugid;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -797,38 +699,45 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyGroup != null) _MyGroup.Update();
if (_MyUser != null) _MyUser.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyGroup?.Update();
_MyUser?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addMembership";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@UID", UID);
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_UGID = new SqlParameter("@newUGID", SqlDbType.Int);
param_UGID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_UGID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_UGID = (int)cm.Parameters["@newUGID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addMembership";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@UID", UID);
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_UGID = new SqlParameter("@newUGID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_UGID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_UGID = (int)cm.Parameters["@newUGID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode());
@@ -860,11 +769,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
// Output Calculated Columns
SqlParameter param_UGID = new SqlParameter("@newUGID", SqlDbType.Int);
param_UGID.Direction = ParameterDirection.Output;
SqlParameter param_UGID = new SqlParameter("@newUGID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_UGID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -909,36 +822,41 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLUpdate", GetHashCode());
try
{
if (_MyGroup != null) _MyGroup.Update();
if (_MyUser != null) _MyUser.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyGroup?.Update();
_MyUser?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateMembership";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@UGID", _UGID);
cm.Parameters.AddWithValue("@UID", UID);
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateMembership";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@UGID", _UGID);
cm.Parameters.AddWithValue("@UID", UID);
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -951,14 +869,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Membership.Add(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID);
else
_LastChanged = Membership.Update(cn, ref _UGID, _UID, _GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Membership.Add(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID);
else
_LastChanged = Membership.Update(cn, ref _UGID, _UID, _GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
}
@@ -984,8 +905,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1070,16 +993,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _UGID;
private readonly int _UGID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int ugid)
{
_UGID = ugid;
}
public bool Exists => _exists;
public ExistsCommand(int ugid) => _UGID = ugid;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode());
@@ -1109,7 +1026,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
MembershipExtension _MembershipExtension = new MembershipExtension();
readonly MembershipExtension _MembershipExtension = new MembershipExtension();
[Serializable()]
partial class MembershipExtension : extensionBase
{
@@ -1118,18 +1035,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1158,61 +1066,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Membership)
if (destType == typeof(string) && value is Membership membership)
{
// Return the ToString value
return ((Membership)value).ToString();
return membership.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create MembershipExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Membership
// {
// partial class MembershipExtension : 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 Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class MembershipInfo : ReadOnlyBase<MembershipInfo>, IDisposable
{
public event MembershipInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<MembershipInfo> _CacheList = new List<MembershipInfo>();
protected static void AddToCache(MembershipInfo membershipInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<MembershipInfo>> _CacheByPrimaryKey = new Dictionary<string, List<MembershipInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Membership _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _UGID;
[System.ComponentModel.DataObjectField(true, true)]
public int UGID
@@ -202,32 +186,19 @@ namespace VEPROMS.CSLA.Library
return _UsrID;
}
}
// CSLATODO: Replace base MembershipInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current MembershipInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current MembershipInfo</returns>
protected override object GetIdValue()
{
return MyMembershipInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyMembershipInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _MembershipInfoUnique = 0;
private static int MembershipInfoUnique
{ get { return ++_MembershipInfoUnique; } }
private int _MyMembershipInfoUnique = MembershipInfoUnique;
public int MyMembershipInfoUnique // Absolutely Unique ID - Info
{ get { return _MyMembershipInfoUnique; } }
private static int MembershipInfoUnique => ++_MembershipInfoUnique;
private readonly int _MyMembershipInfoUnique = MembershipInfoUnique;
// Absolutely Unique ID - Info
public int MyMembershipInfoUnique => _MyMembershipInfoUnique;
protected MembershipInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -236,15 +207,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~MembershipInfo()
{
_CountFinalized++;
@@ -261,10 +228,7 @@ namespace VEPROMS.CSLA.Library
if (listMembershipInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list
}
public virtual Membership Get()
{
return _Editable = Membership.Get(_UGID);
}
public virtual Membership Get() => _Editable = Membership.Get(_UGID);
public static void Refresh(Membership tmp)
{
string key = tmp.UGID.ToString();
@@ -277,18 +241,18 @@ namespace VEPROMS.CSLA.Library
{
if (_UID != tmp.UID)
{
if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value
MyUser?.RefreshUserMemberships(); // Update List for old value
_UID = tmp.UID; // Update the value
}
_MyUser = null; // Reset list so that the next line gets a new list
if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value
MyUser?.RefreshUserMemberships(); // Update List for new value
if (_GID != tmp.GID)
{
if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value
MyGroup?.RefreshGroupMemberships(); // Update List for old value
_GID = tmp.GID; // Update the value
}
_MyGroup = null; // Reset list so that the next line gets a new list
if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value
MyGroup?.RefreshGroupMemberships(); // Update List for new value
_StartDate = tmp.StartDate;
_EndDate = tmp.EndDate;
_Config = tmp.Config;
@@ -309,11 +273,11 @@ namespace VEPROMS.CSLA.Library
{
if (_UID != tmp.UID)
{
if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value
MyUser?.RefreshUserMemberships(); // Update List for old value
_UID = tmp.UID; // Update the value
}
_MyUser = null; // Reset list so that the next line gets a new list
if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value
MyUser?.RefreshUserMemberships(); // Update List for new value
_StartDate = tmp.StartDate;
_EndDate = tmp.EndDate;
_Config = tmp.Config;
@@ -334,11 +298,11 @@ namespace VEPROMS.CSLA.Library
{
if (_GID != tmp.GID)
{
if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value
MyGroup?.RefreshGroupMemberships(); // Update List for old value
_GID = tmp.GID; // Update the value
}
_MyGroup = null; // Reset list so that the next line gets a new list
if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value
MyGroup?.RefreshGroupMemberships(); // Update List for new value
_StartDate = tmp.StartDate;
_EndDate = tmp.EndDate;
_Config = tmp.Config;
@@ -349,8 +313,6 @@ namespace VEPROMS.CSLA.Library
}
public static MembershipInfo Get(int ugid)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Membership");
try
{
MembershipInfo tmp = GetCachedByPrimaryKey(ugid);
@@ -389,13 +351,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _UGID;
public int UGID
{ get { return _UGID; } }
public PKCriteria(int ugid)
{
_UGID = ugid;
}
private readonly int _UGID;
public int UGID => _UGID;
public PKCriteria(int ugid) => _UGID = ugid;
}
private void ReadData(SafeDataReader dr)
{
@@ -457,7 +415,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
MembershipInfoExtension _MembershipInfoExtension = new MembershipInfoExtension();
readonly MembershipInfoExtension _MembershipInfoExtension = new MembershipInfoExtension();
[Serializable()]
partial class MembershipInfoExtension : extensionBase { }
[Serializable()]
@@ -473,10 +431,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is MembershipInfo)
if (destType == typeof(string) && value is MembershipInfo info)
{
// Return the ToString value
return ((MembershipInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<MembershipInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<MembershipInfo> Items => base.Items;
public void AddEvents()
{
foreach (MembershipInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~MembershipInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~MembershipInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on MembershipInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all MembershipInfo.
/// </summary>
public static void Reset()
{
_MembershipInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static MembershipInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<MembershipInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on MembershipInfoList.Get", ex);
// }
//}
public static MembershipInfoList GetByGID(int gid)
/// <summary>
/// Reset the list of all MembershipInfo.
/// </summary>
public static void Reset() => _MembershipInfoList = null;
public static MembershipInfoList GetByGID(int gid)
{
try
{
@@ -150,7 +128,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -164,7 +142,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new MembershipInfo(dr));
while (dr.Read()) Add(new MembershipInfo(dr));
IsReadOnly = true;
}
}
@@ -175,16 +153,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("MembershipInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class GIDCriteria
{
public GIDCriteria(int gid)
{
_GID = gid;
}
private int _GID;
public GIDCriteria(int gid) => _GID = gid;
private int _GID;
public int GID
{
get { return _GID; }
@@ -193,7 +168,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(GIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfoList.DataPortal_FetchGID", GetHashCode());
try
{
@@ -208,7 +183,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new MembershipInfo(dr));
while (dr.Read()) Add(new MembershipInfo(dr));
IsReadOnly = true;
}
}
@@ -219,16 +194,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfoList.DataPortal_FetchGID", ex);
throw new DbCslaException("MembershipInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class UIDCriteria
{
public UIDCriteria(int uid)
{
_UID = uid;
}
private int _UID;
public UIDCriteria(int uid) => _UID = uid;
private int _UID;
public int UID
{
get { return _UID; }
@@ -237,7 +209,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(UIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfoList.DataPortal_FetchUID", GetHashCode());
try
{
@@ -252,7 +224,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new MembershipInfo(dr));
while (dr.Read()) Add(new MembershipInfo(dr));
IsReadOnly = true;
}
}
@@ -263,48 +235,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfoList.DataPortal_FetchUID", ex);
throw new DbCslaException("MembershipInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
MembershipInfoListPropertyDescriptor pd = new MembershipInfoListPropertyDescriptor(this, i);
@@ -321,7 +282,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class MembershipInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private MembershipInfo Item { get { return (MembershipInfo)_Item; } }
public MembershipInfoListPropertyDescriptor(MembershipInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +290,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is MembershipInfoList)
if (destType == typeof(string) && value is MembershipInfoList list)
{
// Return department and department role separated by comma.
return ((MembershipInfoList)value).Items.Count.ToString() + " Memberships";
return $"{list.Items.Count} Memberships";
}
return base.ConvertTo(context, culture, value, destType);
}
+71 -110
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public new Item this[int itemID]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public new Item this[int itemID]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<Item> Items
{
get { return base.Items; }
}
public Item GetItem(int itemID)
public new System.Collections.Generic.IList<Item> Items => base.Items;
public Item GetItem(int itemID)
{
foreach (Item item in this)
if (item.ItemID == itemID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public Item Add(Content myContent) // One to Many
{
Item item = Item.New(myContent);
this.Add(item);
Add(item);
return item;
}
public void Remove(int itemID)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (Item child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (Item child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static NextItems New()
{
return new NextItems();
}
internal static NextItems Get(SafeDataReader dr, Item parent)
{
return new NextItems(dr, parent);
}
public static NextItems GetByPreviousID(int previousID)
#endregion
#region Factory Methods
internal static NextItems New() => new NextItems();
internal static NextItems Get(SafeDataReader dr, Item parent) => new NextItems(dr, parent);
public static NextItems GetByPreviousID(int previousID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on NextItems.GetByPreviousID", ex);
}
}
private NextItems()
{
MarkAsChild();
}
internal NextItems(SafeDataReader dr, Item parent)
private NextItems() => MarkAsChild();
internal NextItems(SafeDataReader dr, Item parent)
{
MarkAsChild();
Fetch(dr, parent);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~NextItems()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~NextItems()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr, Item parent)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(Item.Get(dr, parent));
this.RaiseListChangedEvents = true;
Add(Item.Get(dr, parent));
RaiseListChangedEvents = true;
}
[Serializable()]
private class PreviousIDCriteria
{
public PreviousIDCriteria(int previousID)
{
_PreviousID = previousID;
}
private int _PreviousID;
public PreviousIDCriteria(int previousID) => _PreviousID = previousID;
private int _PreviousID;
public int PreviousID
{
get { return _PreviousID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(PreviousIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] NextItems.DataPortal_FetchPreviousID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new Item(dr, criteria.PreviousID));
while (dr.Read()) Add(new Item(dr, criteria.PreviousID));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("NextItems.DataPortal_FetchPreviousID", ex);
throw new DbCslaException("NextItems.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Item item)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
NextItemsPropertyDescriptor pd = new NextItemsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class NextItemsPropertyDescriptor : vlnListPropertyDescriptor
{
private Item Item { get { return (Item)_Item; } }
public NextItemsPropertyDescriptor(NextItems collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is NextItems)
if (destType == typeof(string) && value is NextItems items)
{
// Return department and department role separated by comma.
return ((NextItems)value).Items.Count.ToString() + " Items";
return $"{items.Items.Count} Items";
}
return base.ConvertTo(context, culture, value, destType);
}
+111 -266
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshOwners.Add(this);
}
private void ClearRefreshList()
{
_RefreshOwners = new List<Owner>();
}
private void ClearRefreshList() => _RefreshOwners = new List<Owner>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Owner> _CacheList = new List<Owner>();
protected static void AddToCache(Owner owner)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(owner)) _CacheList.Remove(owner); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Owner>> _CacheByPrimaryKey = new Dictionary<string, List<Owner>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextOwnerID = -1;
public static int NextOwnerID
{
get { return _nextOwnerID--; }
}
public static int NextOwnerID => _nextOwnerID--;
private int _OwnerID;
[System.ComponentModel.DataObjectField(true, true)]
public int OwnerID
@@ -182,40 +173,14 @@ namespace VEPROMS.CSLA.Library
}
}
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base Owner.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Owner</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check Owner.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Owner</returns>
protected override object GetIdValue()
{
return MyOwnerUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyOwnerUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -243,8 +208,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -258,31 +223,11 @@ namespace VEPROMS.CSLA.Library
_OwnerExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(OwnerID, "<Role(s)>");
//AuthorizationRules.AllowRead(SessionID, "<Role(s)>");
//AuthorizationRules.AllowRead(OwnerType, "<Role(s)>");
//AuthorizationRules.AllowRead(OwnerItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTSStart, "<Role(s)>");
//AuthorizationRules.AllowWrite(SessionID, "<Role(s)>");
//AuthorizationRules.AllowWrite(OwnerType, "<Role(s)>");
//AuthorizationRules.AllowWrite(OwnerItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTSStart, "<Role(s)>");
_OwnerExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -290,42 +235,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_OwnerExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _OwnerUnique = 0;
protected static int OwnerUnique
{ get { return ++_OwnerUnique; } }
private int _MyOwnerUnique = OwnerUnique;
public int MyOwnerUnique // Absolutely Unique ID - Editable
{ get { return _MyOwnerUnique; } }
protected static int OwnerUnique => ++_OwnerUnique;
private readonly int _MyOwnerUnique = OwnerUnique;
// Absolutely Unique ID - Editable
public int MyOwnerUnique => _MyOwnerUnique;
protected Owner()
{/* require use of factory methods */
AddToCache(this);
@@ -334,15 +251,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Owner()
{
_CountFinalized++;
@@ -367,8 +280,6 @@ namespace VEPROMS.CSLA.Library
}
public static Owner New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Owner");
try
{
return DataPortal.Create<Owner>();
@@ -405,8 +316,6 @@ namespace VEPROMS.CSLA.Library
}
public static Owner Get(int ownerID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Owner");
try
{
Owner tmp = GetCachedByPrimaryKey(ownerID);
@@ -432,14 +341,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Owner(dr);
return null;
}
internal Owner(SafeDataReader dr)
{
ReadData(dr);
}
internal Owner(SafeDataReader dr) => ReadData(dr);
public static void Delete(int ownerID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Owner");
try
{
DataPortal.Delete(new PKCriteria(ownerID));
@@ -451,12 +355,6 @@ namespace VEPROMS.CSLA.Library
}
public override Owner Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Owner");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Owner");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Owner");
try
{
BuildRefreshList();
@@ -476,13 +374,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _OwnerID;
public int OwnerID
{ get { return _OwnerID; } }
public PKCriteria(int ownerID)
{
_OwnerID = ownerID;
}
private readonly int _OwnerID;
public int OwnerID => _OwnerID;
public PKCriteria(int ownerID) => _OwnerID = ownerID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -581,33 +475,40 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addOwner";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@SessionID", _SessionID);
cm.Parameters.AddWithValue("@OwnerType", _OwnerType);
cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID);
if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart);
// Output Calculated Columns
SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int);
param_OwnerID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_OwnerID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_OwnerID = (int)cm.Parameters["@newOwnerID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addOwner";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@SessionID", _SessionID);
cm.Parameters.AddWithValue("@OwnerType", _OwnerType);
cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID);
if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart);
// Output Calculated Columns
SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_OwnerID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_OwnerID = (int)cm.Parameters["@newOwnerID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.SQLInsert", GetHashCode());
@@ -636,11 +537,15 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID);
if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart);
// Output Calculated Columns
SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int);
param_OwnerID.Direction = ParameterDirection.Output;
SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_OwnerID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -685,31 +590,36 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateOwner";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@OwnerID", _OwnerID);
cm.Parameters.AddWithValue("@SessionID", _SessionID);
cm.Parameters.AddWithValue("@OwnerType", _OwnerType);
cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID);
if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateOwner";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@OwnerID", _OwnerID);
cm.Parameters.AddWithValue("@SessionID", _SessionID);
cm.Parameters.AddWithValue("@OwnerType", _OwnerType);
cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID);
if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -722,14 +632,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Owner.Add(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart);
else
_LastChanged = Owner.Update(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Owner.Add(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart);
else
_LastChanged = Owner.Update(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart, ref _LastChanged);
}
MarkOld();
}
}
@@ -752,8 +665,10 @@ namespace VEPROMS.CSLA.Library
if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -838,16 +753,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _OwnerID;
private readonly int _OwnerID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int ownerID)
{
_OwnerID = ownerID;
}
public bool Exists => _exists;
public ExistsCommand(int ownerID) => _OwnerID = ownerID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Execute", GetHashCode());
@@ -877,7 +786,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
OwnerExtension _OwnerExtension = new OwnerExtension();
readonly OwnerExtension _OwnerExtension = new OwnerExtension();
[Serializable()]
partial class OwnerExtension : extensionBase
{
@@ -886,22 +795,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultSessionID
{
get { return 0; }
}
public virtual byte DefaultOwnerType
{
get { return 0; }
}
public virtual int DefaultOwnerItemID
{
get { return 0; }
}
public virtual DateTime DefaultDTSStart
{
get { return DateTime.Now; }
}
public virtual int DefaultSessionID => 0;
public virtual byte DefaultOwnerType => 0;
public virtual int DefaultOwnerItemID => 0;
public virtual DateTime DefaultDTSStart => DateTime.Now;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -930,65 +827,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Owner)
if (destType == typeof(string) && value is Owner owner)
{
// Return the ToString value
return ((Owner)value).ToString();
return owner.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create OwnerExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Owner
// {
// partial class OwnerExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultSessionID
// {
// get { return 0; }
// }
// public virtual byte DefaultOwnerType
// {
// get { return 0; }
// }
// public virtual int DefaultOwnerItemID
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTSStart
// {
// get { return DateTime.Now; }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class OwnerInfo : ReadOnlyBase<OwnerInfo>, IDisposable
{
public event OwnerInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<OwnerInfo> _CacheList = new List<OwnerInfo>();
protected static void AddToCache(OwnerInfo ownerInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(ownerInfo)) _CacheList.Remove(ownerInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<OwnerInfo>> _CacheByPrimaryKey = new Dictionary<string, List<OwnerInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Owner _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _OwnerID;
[System.ComponentModel.DataObjectField(true, true)]
public int OwnerID
@@ -135,32 +119,19 @@ namespace VEPROMS.CSLA.Library
return _DTSStart;
}
}
// CSLATODO: Replace base OwnerInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current OwnerInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check OwnerInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current OwnerInfo</returns>
protected override object GetIdValue()
{
return MyOwnerInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyOwnerInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _OwnerInfoUnique = 0;
private static int OwnerInfoUnique
{ get { return ++_OwnerInfoUnique; } }
private int _MyOwnerInfoUnique = OwnerInfoUnique;
public int MyOwnerInfoUnique // Absolutely Unique ID - Info
{ get { return _MyOwnerInfoUnique; } }
private static int OwnerInfoUnique => ++_OwnerInfoUnique;
private readonly int _MyOwnerInfoUnique = OwnerInfoUnique;
// Absolutely Unique ID - Info
public int MyOwnerInfoUnique => _MyOwnerInfoUnique;
protected OwnerInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -169,15 +140,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~OwnerInfo()
{
_CountFinalized++;
@@ -194,10 +161,7 @@ namespace VEPROMS.CSLA.Library
if (listOwnerInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list
}
public virtual Owner Get()
{
return _Editable = Owner.Get(_OwnerID);
}
public virtual Owner Get() => _Editable = Owner.Get(_OwnerID);
public static void Refresh(Owner tmp)
{
string key = tmp.OwnerID.ToString();
@@ -217,8 +181,6 @@ namespace VEPROMS.CSLA.Library
}
public static OwnerInfo Get(int ownerID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Owner");
try
{
OwnerInfo tmp = GetCachedByPrimaryKey(ownerID);
@@ -257,13 +219,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _OwnerID;
public int OwnerID
{ get { return _OwnerID; } }
public PKCriteria(int ownerID)
{
_OwnerID = ownerID;
}
private readonly int _OwnerID;
public int OwnerID => _OwnerID;
public PKCriteria(int ownerID) => _OwnerID = ownerID;
}
private void ReadData(SafeDataReader dr)
{
@@ -322,7 +280,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
OwnerInfoExtension _OwnerInfoExtension = new OwnerInfoExtension();
readonly OwnerInfoExtension _OwnerInfoExtension = new OwnerInfoExtension();
[Serializable()]
partial class OwnerInfoExtension : extensionBase { }
[Serializable()]
@@ -338,10 +296,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is OwnerInfo)
if (destType == typeof(string) && value is OwnerInfo info)
{
// Return the ToString value
return ((OwnerInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -51,16 +49,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~OwnerInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~OwnerInfoList()
{
_CountFinalized++;
}
@@ -97,26 +91,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on OwnerInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all OwnerInfo.
/// </summary>
public static void Reset()
{
_OwnerInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static OwnerInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<OwnerInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on OwnerInfoList.Get", ex);
// }
//}
private OwnerInfoList()
/// <summary>
/// Reset the list of all OwnerInfo.
/// </summary>
public static void Reset() => _OwnerInfoList = null;
private OwnerInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +128,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +173,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class OwnerInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private OwnerInfo Item { get { return (OwnerInfo)_Item; } }
public OwnerInfoListPropertyDescriptor(OwnerInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +181,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is OwnerInfoList)
if (destType == typeof(string) && value is OwnerInfoList list)
{
// Return department and department role separated by comma.
return ((OwnerInfoList)value).Items.Count.ToString() + " Owners";
return $"{list.Items.Count} Owners";
}
return base.ConvertTo(context, culture, value, destType);
}
+106 -231
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshParts.Add(this);
}
private void ClearRefreshList()
{
_RefreshParts = new List<Part>();
}
private void ClearRefreshList() => _RefreshParts = new List<Part>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -58,6 +53,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Part> _CacheList = new List<Part>();
protected static void AddToCache(Part part)
{
@@ -67,6 +63,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Part>> _CacheByPrimaryKey = new Dictionary<string, List<Part>>();
private static void ConvertListToDictionary()
{
@@ -92,10 +89,7 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -210,37 +204,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyItem == null ? false : _MyItem.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyContent != null && _MyContent.IsDirtyList(list)) || (_MyItem != null && _MyItem.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyItem == null ? true : _MyItem.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyContent == null || _MyContent.IsValidList(list)) && (_MyItem == null || _MyItem.IsValidList(list));
}
// CSLATODO: Replace base Part.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Part</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Part.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Part</returns>
protected override object GetIdValue()
{
return MyPartUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPartUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -269,8 +248,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -299,30 +278,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(FromType, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_PartExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -330,42 +290,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_PartExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _PartUnique = 0;
protected static int PartUnique
{ get { return ++_PartUnique; } }
private int _MyPartUnique = PartUnique;
public int MyPartUnique // Absolutely Unique ID - Editable
{ get { return _MyPartUnique; } }
protected static int PartUnique => ++_PartUnique;
private readonly int _MyPartUnique = PartUnique;
// Absolutely Unique ID - Editable
public int MyPartUnique => _MyPartUnique;
protected Part()
{/* require use of factory methods */
AddToCache(this);
@@ -374,15 +306,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Part()
{
_CountFinalized++;
@@ -407,8 +335,6 @@ namespace VEPROMS.CSLA.Library
}
public static Part New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Part");
try
{
return DataPortal.Create<Part>();
@@ -470,8 +396,6 @@ namespace VEPROMS.CSLA.Library
}
public static Part Get(int contentID, int fromType)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Part");
try
{
Part tmp = GetCachedByPrimaryKey(contentID, fromType);
@@ -497,14 +421,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Part(dr);
return null;
}
internal Part(SafeDataReader dr)
{
ReadData(dr);
}
internal Part(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID, int fromType)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Part");
try
{
DataPortal.Delete(new PKCriteria(contentID, fromType));
@@ -516,12 +435,6 @@ namespace VEPROMS.CSLA.Library
}
public override Part Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Part");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Part");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Part");
try
{
BuildRefreshList();
@@ -541,12 +454,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
private int _FromType;
public int FromType
{ get { return _FromType; } }
private readonly int _ContentID;
public int ContentID => _ContentID;
private readonly int _FromType;
public int FromType => _FromType;
public PKCriteria(int contentID, int fromType)
{
_ContentID = contentID;
@@ -649,32 +560,37 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyContent != null) _MyContent.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyContent?.Update();
_MyItem?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPart";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPart";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.SQLInsert", GetHashCode());
@@ -704,8 +620,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -749,33 +667,38 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.SQLUpdate", GetHashCode());
try
{
if (_MyContent != null) _MyContent.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyContent?.Update();
_MyItem?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePart";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePart";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -788,14 +711,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Part.Add(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID);
else
_LastChanged = Part.Update(cn, _ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Part.Add(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID);
else
_LastChanged = Part.Update(cn, _ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
@@ -818,8 +744,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -906,13 +834,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private int _FromType;
private readonly int _ContentID;
private readonly int _FromType;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public bool Exists => _exists;
public ExistsCommand(int contentID, int fromType)
{
_ContentID = contentID;
@@ -948,7 +873,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
PartExtension _PartExtension = new PartExtension();
readonly PartExtension _PartExtension = new PartExtension();
[Serializable()]
partial class PartExtension : extensionBase
{
@@ -957,14 +882,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -993,57 +912,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Part)
if (destType == typeof(string) && value is Part part)
{
// Return the ToString value
return ((Part)value).ToString();
return part.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create PartExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Part
// {
// partial class PartExtension : 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 */);
// }
// }
// }
//}
+86 -216
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -56,6 +54,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<PartAudit> _CacheList = new List<PartAudit>();
protected static void AddToCache(PartAudit partAudit)
{
@@ -65,6 +64,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(partAudit)) _CacheList.Remove(partAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<PartAudit>> _CacheByPrimaryKey = new Dictionary<string, List<PartAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +90,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -218,40 +212,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base PartAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current PartAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check PartAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current PartAudit</returns>
protected override object GetIdValue()
{
return MyPartAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPartAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -279,8 +247,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -299,35 +267,11 @@ namespace VEPROMS.CSLA.Library
_PartAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(FromType, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FromType, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_PartAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -335,42 +279,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_PartAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _PartAuditUnique = 0;
protected static int PartAuditUnique
{ get { return ++_PartAuditUnique; } }
private int _MyPartAuditUnique = PartAuditUnique;
public int MyPartAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyPartAuditUnique; } }
protected static int PartAuditUnique => ++_PartAuditUnique;
private readonly int _MyPartAuditUnique = PartAuditUnique;
// Absolutely Unique ID - Editable
public int MyPartAuditUnique => _MyPartAuditUnique;
protected PartAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -379,15 +295,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PartAudit()
{
_CountFinalized++;
@@ -412,8 +324,6 @@ namespace VEPROMS.CSLA.Library
}
public static PartAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a PartAudit");
try
{
return DataPortal.Create<PartAudit>();
@@ -452,8 +362,6 @@ namespace VEPROMS.CSLA.Library
}
public static PartAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a PartAudit");
try
{
PartAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -479,14 +387,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new PartAudit(dr);
return null;
}
internal PartAudit(SafeDataReader dr)
{
ReadData(dr);
}
internal PartAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a PartAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -498,12 +401,6 @@ namespace VEPROMS.CSLA.Library
}
public override PartAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a PartAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a PartAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a PartAudit");
try
{
BuildRefreshList();
@@ -523,13 +420,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -626,31 +519,36 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPartAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPartAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.SQLInsert", GetHashCode());
@@ -681,8 +579,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -727,28 +627,31 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePartAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePartAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@FromType", _FromType);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -761,14 +664,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
PartAudit.Add(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus);
else
PartAudit.Update(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
PartAudit.Add(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus);
else
PartAudit.Update(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus);
}
MarkOld();
}
}
@@ -860,7 +766,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
PartAuditExtension _PartAuditExtension = new PartAuditExtension();
readonly PartAuditExtension _PartAuditExtension = new PartAuditExtension();
[Serializable()]
partial class PartAuditExtension : extensionBase
{
@@ -897,49 +803,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PartAudit)
if (destType == typeof(string) && value is PartAudit audit)
{
// Return the ToString value
return ((PartAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create PartAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class PartAudit
// {
// partial class PartAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class PartAuditInfo : ReadOnlyBase<PartAuditInfo>, IDisposable
{
public event PartAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<PartAuditInfo> _CacheList = new List<PartAuditInfo>();
protected static void AddToCache(PartAuditInfo partAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(partAuditInfo)) _CacheList.Remove(partAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<PartAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PartAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected PartAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -153,32 +137,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base PartAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current PartAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check PartAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current PartAuditInfo</returns>
protected override object GetIdValue()
{
return MyPartAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPartAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _PartAuditInfoUnique = 0;
private static int PartAuditInfoUnique
{ get { return ++_PartAuditInfoUnique; } }
private int _MyPartAuditInfoUnique = PartAuditInfoUnique;
public int MyPartAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyPartAuditInfoUnique; } }
private static int PartAuditInfoUnique => ++_PartAuditInfoUnique;
private readonly int _MyPartAuditInfoUnique = PartAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyPartAuditInfoUnique => _MyPartAuditInfoUnique;
protected PartAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -187,15 +158,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PartAuditInfo()
{
_CountFinalized++;
@@ -212,10 +179,7 @@ namespace VEPROMS.CSLA.Library
if (listPartAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual PartAudit Get()
{
return _Editable = PartAudit.Get(_AuditID);
}
public virtual PartAudit Get() => _Editable = PartAudit.Get(_AuditID);
public static void Refresh(PartAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -237,8 +201,6 @@ namespace VEPROMS.CSLA.Library
}
public static PartAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a PartAudit");
try
{
PartAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -277,13 +239,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -344,7 +302,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
PartAuditInfoExtension _PartAuditInfoExtension = new PartAuditInfoExtension();
readonly PartAuditInfoExtension _PartAuditInfoExtension = new PartAuditInfoExtension();
[Serializable()]
partial class PartAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -360,10 +318,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PartAuditInfo)
if (destType == typeof(string) && value is PartAuditInfo info)
{
// Return the ToString value
return ((PartAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<PartAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<PartAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (PartAuditInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~PartAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PartAuditInfoList()
{
_CountFinalized++;
}
@@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on PartAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all PartAuditInfo.
/// </summary>
public static void Reset()
{
_PartAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static PartAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<PartAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on PartAuditInfoList.Get", ex);
// }
//}
private PartAuditInfoList()
/// <summary>
/// Reset the list of all PartAuditInfo.
/// </summary>
public static void Reset() => _PartAuditInfoList = null;
private PartAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PartAuditInfo(dr));
while (dr.Read()) Add(new PartAuditInfo(dr));
IsReadOnly = true;
}
}
@@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("PartAuditInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
PartAuditInfoListPropertyDescriptor pd = new PartAuditInfoListPropertyDescriptor(this, i);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class PartAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private PartAuditInfo Item { get { return (PartAuditInfo)_Item; } }
public PartAuditInfoListPropertyDescriptor(PartAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PartAuditInfoList)
if (destType == typeof(string) && value is PartAuditInfoList list)
{
// Return department and department role separated by comma.
return ((PartAuditInfoList)value).Items.Count.ToString() + " PartAudits";
return $"{list.Items.Count} PartAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class PartInfo : ReadOnlyBase<PartInfo>, IDisposable
{
public event PartInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<PartInfo> _CacheList = new List<PartInfo>();
protected static void AddToCache(PartInfo partInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<PartInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PartInfo>>();
private static void ConvertListToDictionary()
{
@@ -81,21 +78,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Part _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -166,32 +150,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base PartInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current PartInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check PartInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current PartInfo</returns>
protected override object GetIdValue()
{
return MyPartInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPartInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _PartInfoUnique = 0;
private static int PartInfoUnique
{ get { return ++_PartInfoUnique; } }
private int _MyPartInfoUnique = PartInfoUnique;
public int MyPartInfoUnique // Absolutely Unique ID - Info
{ get { return _MyPartInfoUnique; } }
private static int PartInfoUnique => ++_PartInfoUnique;
private readonly int _MyPartInfoUnique = PartInfoUnique;
// Absolutely Unique ID - Info
public int MyPartInfoUnique => _MyPartInfoUnique;
protected PartInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -200,15 +171,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PartInfo()
{
_CountFinalized++;
@@ -227,10 +194,7 @@ namespace VEPROMS.CSLA.Library
if (listPartInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list
}
public virtual Part Get()
{
return _Editable = Part.Get(_ContentID, _FromType);
}
public virtual Part Get() => _Editable = Part.Get(_ContentID, _FromType);
public static void Refresh(Part tmp)
{
string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString();
@@ -243,11 +207,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ItemID != tmp.ItemID)
{
if (MyItem != null) MyItem.RefreshItemParts(); // Update List for old value
MyItem?.RefreshItemParts(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemParts(); // Update List for new value
MyItem?.RefreshItemParts(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_PartInfoExtension.Refresh(this);
@@ -265,11 +229,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ItemID != tmp.ItemID)
{
if (MyItem != null) MyItem.RefreshItemParts(); // Update List for old value
MyItem?.RefreshItemParts(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemParts(); // Update List for new value
MyItem?.RefreshItemParts(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_PartInfoExtension.Refresh(this);
@@ -292,8 +256,6 @@ namespace VEPROMS.CSLA.Library
}
public static PartInfo Get(int contentID, int fromType)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Part");
try
{
PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType);
@@ -332,12 +294,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
private int _FromType;
public int FromType
{ get { return _FromType; } }
private readonly int _ContentID;
public int ContentID => _ContentID;
private readonly int _FromType;
public int FromType => _FromType;
public PKCriteria(int contentID, int fromType)
{
_ContentID = contentID;
@@ -402,7 +362,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
PartInfoExtension _PartInfoExtension = new PartInfoExtension();
readonly PartInfoExtension _PartInfoExtension = new PartInfoExtension();
[Serializable()]
partial class PartInfoExtension : extensionBase { }
[Serializable()]
@@ -418,10 +378,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PartInfo)
if (destType == typeof(string) && value is PartInfo info)
{
// Return the ToString value
return ((PartInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -30,8 +28,7 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<PartInfo> Items
{ get { return base.Items; } }
internal new IList<PartInfo> Items => base.Items;
public void AddEvents()
{
foreach (PartInfo tmp in this)
@@ -44,22 +41,18 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PartInfoList()
{
_CountFinalized++;
@@ -100,22 +93,7 @@ namespace VEPROMS.CSLA.Library
/// <summary>
/// Reset the list of all PartInfo.
/// </summary>
public static void Reset()
{
_PartInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static PartInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<PartInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on PartInfoList.Get", ex);
// }
//}
public static void Reset() => _PartInfoList = null;
public static PartInfoList GetByContentID(int contentID)
{
try
@@ -150,7 +128,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -164,7 +142,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PartInfo(dr));
while (dr.Read()) Add(new PartInfo(dr));
IsReadOnly = true;
}
}
@@ -175,15 +153,12 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
@@ -193,7 +168,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ContentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_FetchContentID", GetHashCode());
try
{
@@ -208,7 +183,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PartInfo(dr));
while (dr.Read()) Add(new PartInfo(dr));
IsReadOnly = true;
}
}
@@ -219,15 +194,12 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_FetchContentID", ex);
throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class ItemIDCriteria
{
public ItemIDCriteria(int itemID)
{
_ItemID = itemID;
}
public ItemIDCriteria(int itemID) => _ItemID = itemID;
private int _ItemID;
public int ItemID
{
@@ -237,7 +209,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ItemIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_FetchItemID", GetHashCode());
try
{
@@ -252,7 +224,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PartInfo(dr));
while (dr.Read()) Add(new PartInfo(dr));
IsReadOnly = true;
}
}
@@ -263,38 +235,27 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_FetchItemID", ex);
throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
@@ -304,7 +265,7 @@ namespace VEPROMS.CSLA.Library
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
PartInfoListPropertyDescriptor pd = new PartInfoListPropertyDescriptor(this, i);
@@ -321,7 +282,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class PartInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private PartInfo Item { get { return (PartInfo)_Item; } }
public PartInfoListPropertyDescriptor(PartInfoList collection, int index) : base(collection, index) {; }
}
#endregion
@@ -330,10 +290,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PartInfoList)
if (destType == typeof(string) && value is PartInfoList list)
{
// Return department and department role separated by comma.
return ((PartInfoList)value).Items.Count.ToString() + " Parts";
return $"{list.Items.Count} Parts";
}
return base.ConvertTo(context, culture, value, destType);
}
+128 -263
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshPdfs.Add(this);
}
private void ClearRefreshList()
{
_RefreshPdfs = new List<Pdf>();
}
private void ClearRefreshList() => _RefreshPdfs = new List<Pdf>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -57,6 +52,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Pdf> _CacheList = new List<Pdf>();
protected static void AddToCache(Pdf pdf)
{
@@ -66,13 +62,14 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(pdf)) _CacheList.Remove(pdf); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Pdf>> _CacheByPrimaryKey = new Dictionary<string, List<Pdf>>();
private static void ConvertListToDictionary()
{
while (_CacheList.Count > 0) // Move Pdf(s) from temporary _CacheList to _CacheByPrimaryKey
{
Pdf tmp = _CacheList[0]; // Get the first Pdf
string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
string pKey = $"{tmp.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
if (!_CacheByPrimaryKey.ContainsKey(pKey))
{
_CacheByPrimaryKey[pKey] = new List<Pdf>(); // Add new list for PrimaryKey
@@ -84,17 +81,14 @@ namespace VEPROMS.CSLA.Library
protected static Pdf GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
ConvertListToDictionary();
string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString();
string key = $"{docID}_{debugStatus}_{topRow}_{pageLength}_{leftMargin}_{pageWidth}";
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private int _DocID;
[System.ComponentModel.DataObjectField(true, true)]
public int DocID
@@ -261,37 +255,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyDocument != null && _MyDocument.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocument == null || _MyDocument.IsValidList(list));
}
// CSLATODO: Replace base Pdf.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Pdf</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Pdf.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Pdf</returns>
protected override object GetIdValue()
{
return MyPdfUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPdfUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -319,8 +298,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -339,36 +318,11 @@ namespace VEPROMS.CSLA.Library
_PdfExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(DebugStatus, "<Role(s)>");
//AuthorizationRules.AllowRead(TopRow, "<Role(s)>");
//AuthorizationRules.AllowRead(PageLength, "<Role(s)>");
//AuthorizationRules.AllowRead(LeftMargin, "<Role(s)>");
//AuthorizationRules.AllowRead(PageWidth, "<Role(s)>");
//AuthorizationRules.AllowRead(PageCount, "<Role(s)>");
//AuthorizationRules.AllowRead(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PageCount, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_PdfExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -376,42 +330,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_PdfExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _PdfUnique = 0;
protected static int PdfUnique
{ get { return ++_PdfUnique; } }
private int _MyPdfUnique = PdfUnique;
public int MyPdfUnique // Absolutely Unique ID - Editable
{ get { return _MyPdfUnique; } }
protected static int PdfUnique => ++_PdfUnique;
private readonly int _MyPdfUnique = PdfUnique;
// Absolutely Unique ID - Editable
public int MyPdfUnique => _MyPdfUnique;
protected Pdf()
{/* require use of factory methods */
AddToCache(this);
@@ -420,15 +346,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Pdf()
{
_CountFinalized++;
@@ -453,8 +375,6 @@ namespace VEPROMS.CSLA.Library
}
public static Pdf New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Pdf");
try
{
return DataPortal.Create<Pdf>();
@@ -541,8 +461,6 @@ namespace VEPROMS.CSLA.Library
}
public static Pdf Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Pdf");
try
{
Pdf tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth);
@@ -568,14 +486,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Pdf(dr);
return null;
}
internal Pdf(SafeDataReader dr)
{
ReadData(dr);
}
internal Pdf(SafeDataReader dr) => ReadData(dr);
public static void Delete(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Pdf");
try
{
DataPortal.Delete(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth));
@@ -587,12 +500,6 @@ namespace VEPROMS.CSLA.Library
}
public override Pdf Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Pdf");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Pdf");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Pdf");
try
{
BuildRefreshList();
@@ -619,24 +526,18 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DocID;
public int DocID
{ get { return _DocID; } }
private int _DebugStatus;
public int DebugStatus
{ get { return _DebugStatus; } }
private int _TopRow;
public int TopRow
{ get { return _TopRow; } }
private int _PageLength;
public int PageLength
{ get { return _PageLength; } }
private int _LeftMargin;
public int LeftMargin
{ get { return _LeftMargin; } }
private int _PageWidth;
public int PageWidth
{ get { return _PageWidth; } }
private readonly int _DocID;
public int DocID => _DocID;
private readonly int _DebugStatus;
public int DebugStatus => _DebugStatus;
private readonly int _TopRow;
public int TopRow => _TopRow;
private readonly int _PageLength;
public int PageLength => _PageLength;
private readonly int _LeftMargin;
public int LeftMargin => _LeftMargin;
private readonly int _PageWidth;
public int PageWidth => _PageWidth;
public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
_DocID = docID;
@@ -752,36 +653,41 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyDocument != null) _MyDocument.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyDocument?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPdf";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus);
cm.Parameters.AddWithValue("@TopRow", _TopRow);
cm.Parameters.AddWithValue("@PageLength", _PageLength);
cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin);
cm.Parameters.AddWithValue("@PageWidth", _PageWidth);
cm.Parameters.AddWithValue("@PageCount", _PageCount);
cm.Parameters.AddWithValue("@DocPdf", _DocPdf);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPdf";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus);
cm.Parameters.AddWithValue("@TopRow", _TopRow);
cm.Parameters.AddWithValue("@PageLength", _PageLength);
cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin);
cm.Parameters.AddWithValue("@PageWidth", _PageWidth);
cm.Parameters.AddWithValue("@PageCount", _PageCount);
cm.Parameters.AddWithValue("@DocPdf", _DocPdf);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.SQLInsert", GetHashCode());
@@ -816,8 +722,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -861,37 +769,42 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.SQLUpdate", GetHashCode());
try
{
if (_MyDocument != null) _MyDocument.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyDocument?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePdf";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus);
cm.Parameters.AddWithValue("@TopRow", _TopRow);
cm.Parameters.AddWithValue("@PageLength", _PageLength);
cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin);
cm.Parameters.AddWithValue("@PageWidth", _PageWidth);
cm.Parameters.AddWithValue("@PageCount", _PageCount);
cm.Parameters.AddWithValue("@DocPdf", _DocPdf);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePdf";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus);
cm.Parameters.AddWithValue("@TopRow", _TopRow);
cm.Parameters.AddWithValue("@PageLength", _PageLength);
cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin);
cm.Parameters.AddWithValue("@PageWidth", _PageWidth);
cm.Parameters.AddWithValue("@PageCount", _PageCount);
cm.Parameters.AddWithValue("@DocPdf", _DocPdf);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -904,14 +817,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Pdf.Add(cn, _MyDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID);
else
_LastChanged = Pdf.Update(cn, _DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Pdf.Add(cn, _MyDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID);
else
_LastChanged = Pdf.Update(cn, _DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
@@ -939,8 +855,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1035,17 +953,14 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _DocID;
private int _DebugStatus;
private int _TopRow;
private int _PageLength;
private int _LeftMargin;
private int _PageWidth;
private readonly int _DocID;
private readonly int _DebugStatus;
private readonly int _TopRow;
private readonly int _PageLength;
private readonly int _LeftMargin;
private readonly int _PageWidth;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public bool Exists => _exists;
public ExistsCommand(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
_DocID = docID;
@@ -1089,7 +1004,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
PdfExtension _PdfExtension = new PdfExtension();
readonly PdfExtension _PdfExtension = new PdfExtension();
[Serializable()]
partial class PdfExtension : extensionBase
{
@@ -1098,14 +1013,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1134,57 +1043,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Pdf)
if (destType == typeof(string) && value is Pdf mypdf)
{
// Return the ToString value
return ((Pdf)value).ToString();
return mypdf.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create PdfExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Pdf
// {
// partial class PdfExtension : 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 */);
// }
// }
// }
//}
+38 -82
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class PdfInfo : ReadOnlyBase<PdfInfo>, IDisposable
{
public event PdfInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<PdfInfo> _CacheList = new List<PdfInfo>();
protected static void AddToCache(PdfInfo pdfInfo)
{
@@ -45,13 +41,14 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(pdfInfo)) _CacheList.Remove(pdfInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<PdfInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PdfInfo>>();
private static void ConvertListToDictionary()
{
while (_CacheList.Count > 0) // Move PdfInfo(s) from temporary _CacheList to _CacheByPrimaryKey
{
PdfInfo tmp = _CacheList[0]; // Get the first PdfInfo
string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
string pKey = $"{tmp.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
if (!_CacheByPrimaryKey.ContainsKey(pKey))
{
_CacheByPrimaryKey[pKey] = new List<PdfInfo>(); // Add new list for PrimaryKey
@@ -67,7 +64,7 @@ namespace VEPROMS.CSLA.Library
protected static PdfInfo GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
ConvertListToDictionary();
string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString();
string key = $"{docID}_{debugStatus}_{topRow}_{pageLength}_{leftMargin}_{pageWidth}";
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
@@ -77,7 +74,7 @@ namespace VEPROMS.CSLA.Library
protected static void RemoveFromCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
ConvertListToDictionary();
string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString();
string key = $"{docID}_{debugStatus}_{topRow}_{pageLength}_{leftMargin}_{pageWidth}";
if (_CacheByPrimaryKey.ContainsKey(key))
{
_CacheByPrimaryKey.Remove(key);
@@ -87,21 +84,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Pdf _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _DocID;
[System.ComponentModel.DataObjectField(true, true)]
public int DocID
@@ -216,32 +200,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base PdfInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current PdfInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check PdfInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current PdfInfo</returns>
protected override object GetIdValue()
{
return MyPdfInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPdfInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _PdfInfoUnique = 0;
private static int PdfInfoUnique
{ get { return ++_PdfInfoUnique; } }
private int _MyPdfInfoUnique = PdfInfoUnique;
public int MyPdfInfoUnique // Absolutely Unique ID - Info
{ get { return _MyPdfInfoUnique; } }
private static int PdfInfoUnique => ++_PdfInfoUnique;
private readonly int _MyPdfInfoUnique = PdfInfoUnique;
// Absolutely Unique ID - Info
public int MyPdfInfoUnique => _MyPdfInfoUnique;
protected PdfInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -250,15 +221,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PdfInfo()
{
_CountFinalized++;
@@ -269,19 +236,16 @@ namespace VEPROMS.CSLA.Library
_CountDisposed++;
_Disposed = true;
RemoveFromCache(this);
if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString())) return;
List<PdfInfo> listPdfInfo = _CacheByPrimaryKey[DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()]; // Get the list of items
if (!_CacheByPrimaryKey.ContainsKey($"{DocID}_{DebugStatus}_{TopRow}_{PageLength}_{LeftMargin}_{PageWidth}")) return;
List<PdfInfo> listPdfInfo = _CacheByPrimaryKey[$"{DocID}_{DebugStatus}_{TopRow}_{PageLength}_{LeftMargin}_{PageWidth}"]; // Get the list of items
while (listPdfInfo.Contains(this)) listPdfInfo.Remove(this); // Remove the item from the list
if (listPdfInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()); // remove the list
}
public virtual Pdf Get()
{
return _Editable = Pdf.Get(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth);
_CacheByPrimaryKey.Remove($"{DocID}_{DebugStatus}_{TopRow}_{PageLength}_{LeftMargin}_{PageWidth}"); // remove the list
}
public virtual Pdf Get() => _Editable = Pdf.Get(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth);
public static void Refresh(Pdf tmp)
{
string key = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
string key = $"{tmp.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key])
@@ -298,7 +262,7 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Document myDocument, DocumentPdf tmp)
{
string key = myDocument.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
string key = $"{myDocument.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key])
@@ -315,8 +279,6 @@ namespace VEPROMS.CSLA.Library
}
public static PdfInfo Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Pdf");
try
{
PdfInfo tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth);
@@ -355,24 +317,18 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DocID;
public int DocID
{ get { return _DocID; } }
private int _DebugStatus;
public int DebugStatus
{ get { return _DebugStatus; } }
private int _TopRow;
public int TopRow
{ get { return _TopRow; } }
private int _PageLength;
public int PageLength
{ get { return _PageLength; } }
private int _LeftMargin;
public int LeftMargin
{ get { return _LeftMargin; } }
private int _PageWidth;
public int PageWidth
{ get { return _PageWidth; } }
private readonly int _DocID;
public int DocID => _DocID;
private readonly int _DebugStatus;
public int DebugStatus => _DebugStatus;
private readonly int _TopRow;
public int TopRow => _TopRow;
private readonly int _PageLength;
public int PageLength => _PageLength;
private readonly int _LeftMargin;
public int LeftMargin => _LeftMargin;
private readonly int _PageWidth;
public int PageWidth => _PageWidth;
public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
_DocID = docID;
@@ -450,7 +406,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
PdfInfoExtension _PdfInfoExtension = new PdfInfoExtension();
readonly PdfInfoExtension _PdfInfoExtension = new PdfInfoExtension();
[Serializable()]
partial class PdfInfoExtension : extensionBase { }
[Serializable()]
@@ -466,10 +422,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PdfInfo)
if (destType == typeof(string) && value is PdfInfo info)
{
// Return the ToString value
return ((PdfInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<PdfInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<PdfInfo> Items => base.Items;
public void AddEvents()
{
foreach (PdfInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~PdfInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PdfInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on PdfInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all PdfInfo.
/// </summary>
public static void Reset()
{
_PdfInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static PdfInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<PdfInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on PdfInfoList.Get", ex);
// }
//}
public static PdfInfoList GetByDocID(int docID)
/// <summary>
/// Reset the list of all PdfInfo.
/// </summary>
public static void Reset() => _PdfInfoList = null;
public static PdfInfoList GetByDocID(int docID)
{
try
{
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -150,7 +128,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PdfInfo(dr));
while (dr.Read()) Add(new PdfInfo(dr));
IsReadOnly = true;
}
}
@@ -161,16 +139,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("PdfInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -179,7 +154,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(DocIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfoList.DataPortal_FetchDocID", GetHashCode());
try
{
@@ -194,7 +169,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PdfInfo(dr));
while (dr.Read()) Add(new PdfInfo(dr));
IsReadOnly = true;
}
}
@@ -205,48 +180,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfoList.DataPortal_FetchDocID", ex);
throw new DbCslaException("PdfInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
PdfInfoListPropertyDescriptor pd = new PdfInfoListPropertyDescriptor(this, i);
@@ -263,7 +227,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class PdfInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private PdfInfo Item { get { return (PdfInfo)_Item; } }
public PdfInfoListPropertyDescriptor(PdfInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -272,10 +235,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PdfInfoList)
if (destType == typeof(string) && value is PdfInfoList list)
{
// Return department and department role separated by comma.
return ((PdfInfoList)value).Items.Count.ToString() + " Pdfs";
return $"{list.Items.Count} Pdfs";
}
return base.ConvertTo(context, culture, value, destType);
}
+129 -285
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshPermissions.Add(this);
}
private void ClearRefreshList()
{
_RefreshPermissions = new List<Permission>();
}
private void ClearRefreshList() => _RefreshPermissions = new List<Permission>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -57,6 +52,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Permission> _CacheList = new List<Permission>();
protected static void AddToCache(Permission permission)
{
@@ -66,6 +62,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Permission>> _CacheByPrimaryKey = new Dictionary<string, List<Permission>>();
private static void ConvertListToDictionary()
{
@@ -91,15 +88,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextPID = -1;
public static int NextPID
{
get { return _nextPID--; }
}
public static int NextPID => _nextPID--;
private int _PID;
[System.ComponentModel.DataObjectField(true, true)]
public int PID
@@ -351,37 +342,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyRole != null && _MyRole.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyRole == null || _MyRole.IsValidList(list));
}
// CSLATODO: Replace base Permission.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Permission</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Permission.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Permission</returns>
protected override object GetIdValue()
{
return MyPermissionUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPermissionUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -410,8 +386,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -473,43 +449,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(PID, "<Role(s)>");
//AuthorizationRules.AllowRead(RID, "<Role(s)>");
//AuthorizationRules.AllowRead(PermLevel, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(PermValue, "<Role(s)>");
//AuthorizationRules.AllowRead(PermAD, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PermLevel, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(PermValue, "<Role(s)>");
//AuthorizationRules.AllowWrite(PermAD, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_PermissionExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -517,42 +461,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_PermissionExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _PermissionUnique = 0;
protected static int PermissionUnique
{ get { return ++_PermissionUnique; } }
private int _MyPermissionUnique = PermissionUnique;
public int MyPermissionUnique // Absolutely Unique ID - Editable
{ get { return _MyPermissionUnique; } }
protected static int PermissionUnique => ++_PermissionUnique;
private readonly int _MyPermissionUnique = PermissionUnique;
// Absolutely Unique ID - Editable
public int MyPermissionUnique => _MyPermissionUnique;
protected Permission()
{/* require use of factory methods */
AddToCache(this);
@@ -561,15 +477,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Permission()
{
_CountFinalized++;
@@ -594,8 +506,6 @@ namespace VEPROMS.CSLA.Library
}
public static Permission New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Permission");
try
{
return DataPortal.Create<Permission>();
@@ -640,7 +550,7 @@ namespace VEPROMS.CSLA.Library
tmp._ErrorMessage = "Failed Validation:";
foreach (Csla.Validation.BrokenRule br in brc)
{
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
tmp._ErrorMessage += $"\r\n\tFailure: {br.RuleName}";
}
}
return tmp;
@@ -667,15 +577,13 @@ namespace VEPROMS.CSLA.Library
tmp._ErrorMessage = "Failed Validation:";
foreach (Csla.Validation.BrokenRule br in brc)
{
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
tmp._ErrorMessage += $"\r\n\tFailure: {br.RuleName}";
}
}
return tmp;
}
public static Permission Get(int pid)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Permission");
try
{
Permission tmp = GetCachedByPrimaryKey(pid);
@@ -701,14 +609,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Permission(dr);
return null;
}
internal Permission(SafeDataReader dr)
{
ReadData(dr);
}
internal Permission(SafeDataReader dr) => ReadData(dr);
public static void Delete(int pid)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Permission");
try
{
DataPortal.Delete(new PKCriteria(pid));
@@ -720,12 +623,6 @@ namespace VEPROMS.CSLA.Library
}
public override Permission Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Permission");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Permission");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Permission");
try
{
BuildRefreshList();
@@ -745,13 +642,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _PID;
public int PID
{ get { return _PID; } }
public PKCriteria(int pid)
{
_PID = pid;
}
private readonly int _PID;
public int PID => _PID;
public PKCriteria(int pid) => _PID = pid;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -856,40 +749,47 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyRole != null) _MyRole.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyRole?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPermission";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@PermLevel", _PermLevel);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@PermValue", _PermValue);
cm.Parameters.AddWithValue("@PermAD", _PermAD);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_PID = new SqlParameter("@newPID", SqlDbType.Int);
param_PID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_PID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_PID = (int)cm.Parameters["@newPID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addPermission";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@PermLevel", _PermLevel);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@PermValue", _PermValue);
cm.Parameters.AddWithValue("@PermAD", _PermAD);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_PID = new SqlParameter("@newPID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_PID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_PID = (int)cm.Parameters["@newPID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode());
@@ -924,11 +824,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
// Output Calculated Columns
SqlParameter param_PID = new SqlParameter("@newPID", SqlDbType.Int);
param_PID.Direction = ParameterDirection.Output;
SqlParameter param_PID = new SqlParameter("@newPID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_PID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -973,38 +877,43 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLUpdate", GetHashCode());
try
{
if (_MyRole != null) _MyRole.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyRole?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePermission";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@PID", _PID);
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@PermLevel", _PermLevel);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@PermValue", _PermValue);
cm.Parameters.AddWithValue("@PermAD", _PermAD);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updatePermission";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@PID", _PID);
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@PermLevel", _PermLevel);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@PermValue", _PermValue);
cm.Parameters.AddWithValue("@PermAD", _PermAD);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -1017,14 +926,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Permission.Add(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID);
else
_LastChanged = Permission.Update(cn, ref _PID, _RID, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Permission.Add(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID);
else
_LastChanged = Permission.Update(cn, ref _PID, _RID, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
}
@@ -1053,8 +965,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1139,16 +1053,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _PID;
private readonly int _PID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int pid)
{
_PID = pid;
}
public bool Exists => _exists;
public ExistsCommand(int pid) => _PID = pid;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode());
@@ -1178,7 +1086,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
PermissionExtension _PermissionExtension = new PermissionExtension();
readonly PermissionExtension _PermissionExtension = new PermissionExtension();
[Serializable()]
partial class PermissionExtension : extensionBase
{
@@ -1187,22 +1095,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultPermAD
{
get { return 0; }
}
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultPermAD => 0;
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1231,65 +1127,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Permission)
if (destType == typeof(string) && value is Permission perm)
{
// Return the ToString value
return ((Permission)value).ToString();
return perm.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create PermissionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Permission
// {
// partial class PermissionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultPermAD
// {
// get { return 0; }
// }
// 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 Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class PermissionInfo : ReadOnlyBase<PermissionInfo>, IDisposable
{
public event PermissionInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<PermissionInfo> _CacheList = new List<PermissionInfo>();
protected static void AddToCache(PermissionInfo permissionInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<PermissionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PermissionInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Permission _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _PID;
[System.ComponentModel.DataObjectField(true, true)]
public int PID
@@ -212,32 +196,19 @@ namespace VEPROMS.CSLA.Library
return _UsrID;
}
}
// CSLATODO: Replace base PermissionInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current PermissionInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current PermissionInfo</returns>
protected override object GetIdValue()
{
return MyPermissionInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyPermissionInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _PermissionInfoUnique = 0;
private static int PermissionInfoUnique
{ get { return ++_PermissionInfoUnique; } }
private int _MyPermissionInfoUnique = PermissionInfoUnique;
public int MyPermissionInfoUnique // Absolutely Unique ID - Info
{ get { return _MyPermissionInfoUnique; } }
private static int PermissionInfoUnique => ++_PermissionInfoUnique;
private readonly int _MyPermissionInfoUnique = PermissionInfoUnique;
// Absolutely Unique ID - Info
public int MyPermissionInfoUnique => _MyPermissionInfoUnique;
protected PermissionInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -246,15 +217,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PermissionInfo()
{
_CountFinalized++;
@@ -271,10 +238,7 @@ namespace VEPROMS.CSLA.Library
if (listPermissionInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(PID.ToString()); // remove the list
}
public virtual Permission Get()
{
return _Editable = Permission.Get(_PID);
}
public virtual Permission Get() => _Editable = Permission.Get(_PID);
public static void Refresh(Permission tmp)
{
string key = tmp.PID.ToString();
@@ -287,11 +251,11 @@ namespace VEPROMS.CSLA.Library
{
if (_RID != tmp.RID)
{
if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value
MyRole?.RefreshRolePermissions(); // Update List for old value
_RID = tmp.RID; // Update the value
}
_MyRole = null; // Reset list so that the next line gets a new list
if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for new value
MyRole?.RefreshRolePermissions(); // Update List for new value
_PermLevel = tmp.PermLevel;
_VersionType = tmp.VersionType;
_PermValue = tmp.PermValue;
@@ -328,8 +292,6 @@ namespace VEPROMS.CSLA.Library
}
public static PermissionInfo Get(int pid)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Permission");
try
{
PermissionInfo tmp = GetCachedByPrimaryKey(pid);
@@ -368,13 +330,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _PID;
public int PID
{ get { return _PID; } }
public PKCriteria(int pid)
{
_PID = pid;
}
private readonly int _PID;
public int PID => _PID;
public PKCriteria(int pid) => _PID = pid;
}
private void ReadData(SafeDataReader dr)
{
@@ -439,7 +397,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension();
readonly PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension();
[Serializable()]
partial class PermissionInfoExtension : extensionBase { }
[Serializable()]
@@ -455,10 +413,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PermissionInfo)
if (destType == typeof(string) && value is PermissionInfo info)
{
// Return the ToString value
return ((PermissionInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<PermissionInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<PermissionInfo> Items => base.Items;
public void AddEvents()
{
foreach (PermissionInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~PermissionInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~PermissionInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on PermissionInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all PermissionInfo.
/// </summary>
public static void Reset()
{
_PermissionInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static PermissionInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<PermissionInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on PermissionInfoList.Get", ex);
// }
//}
public static PermissionInfoList GetByRID(int rid)
/// <summary>
/// Reset the list of all PermissionInfo.
/// </summary>
public static void Reset() => _PermissionInfoList = null;
public static PermissionInfoList GetByRID(int rid)
{
try
{
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -150,7 +128,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PermissionInfo(dr));
while (dr.Read()) Add(new PermissionInfo(dr));
IsReadOnly = true;
}
}
@@ -161,16 +139,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("PermissionInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class RIDCriteria
{
public RIDCriteria(int rid)
{
_RID = rid;
}
private int _RID;
public RIDCriteria(int rid) => _RID = rid;
private int _RID;
public int RID
{
get { return _RID; }
@@ -179,7 +154,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(RIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfoList.DataPortal_FetchRID", GetHashCode());
try
{
@@ -194,7 +169,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new PermissionInfo(dr));
while (dr.Read()) Add(new PermissionInfo(dr));
IsReadOnly = true;
}
}
@@ -205,48 +180,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfoList.DataPortal_FetchRID", ex);
throw new DbCslaException("PermissionInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
PermissionInfoListPropertyDescriptor pd = new PermissionInfoListPropertyDescriptor(this, i);
@@ -263,7 +227,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class PermissionInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private PermissionInfo Item { get { return (PermissionInfo)_Item; } }
public PermissionInfoListPropertyDescriptor(PermissionInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -272,10 +235,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is PermissionInfoList)
if (destType == typeof(string) && value is PermissionInfoList list)
{
// Return department and department role separated by comma.
return ((PermissionInfoList)value).Items.Count.ToString() + " Permissions";
return $"{list.Items.Count} Permissions";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,6 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using Csla.Validation;
namespace VEPROMS.CSLA.Library
@@ -29,225 +23,23 @@ namespace VEPROMS.CSLA.Library
public vlnListPropertyDescriptor(System.Collections.IList collection, int index)
: base("#" + index.ToString(), null)
{ _Item = collection[index]; }
public override bool CanResetValue(object component)
{ return true; }
public override Type ComponentType
{ get { return _Item.GetType(); } }
public override object GetValue(object component)
{ return _Item; }
public override bool IsReadOnly
{ get { return false; } }
public override Type PropertyType
{ get { return _Item.GetType(); } }
public override void ResetValue(object component)
public override bool CanResetValue(object component) => true;
public override Type ComponentType => _Item.GetType();
public override object GetValue(object component) => _Item;
public override bool IsReadOnly => false;
public override Type PropertyType => _Item.GetType();
public override void ResetValue(object component)
{ ;}
public override bool ShouldSerializeValue(object component)
{ return true; }
public override void SetValue(object component, object value)
public override bool ShouldSerializeValue(object component) => true;
public override void SetValue(object component, object value)
{ /*_Item = value*/;}
//public override AttributeCollection Attributes
//{ get { return new AttributeCollection(null); } }
public override string DisplayName
{ get { return _Item.ToString(); } }
public override string Description
{ get { return _Item.ToString(); } }
public override string Name
{ get { return _Item.ToString(); } }
} // Class
public override string DisplayName => _Item.ToString();
public override string Description => _Item.ToString();
public override string Name => _Item.ToString();
} // Class
public interface IVEHasBrokenRules
{
IVEHasBrokenRules HasBrokenRules { get; }
BrokenRulesCollection BrokenRules { get; }
}
} // Namespace
// The following are samples of ToString overrides
// public partial class Annotation
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class AnnotationInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class AnnotationType
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class AnnotationTypeAnnotation
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class AnnotationTypeInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Assignment
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class AssignmentInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Association
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class AssociationInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Connection
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ConnectionFolder
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ConnectionInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Content
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ContentDetail
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ContentItem
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ContentPart
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ContentRoUsage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ContentTransition
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ContentInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Detail
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DetailInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Document
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentDROUsage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentEntry
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentPdf
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocVersion
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocVersionAssociation
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocVersionInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DROUsage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DROUsageInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Entry
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class EntryInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Figure
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FigureInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Folder
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FolderAssignment
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FolderDocVersion
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FolderInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Format
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FormatContent
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FormatDocVersion
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FormatFolder
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class FormatInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Grid
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class GridInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Group
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class GroupAssignment
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class GroupMembership
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class GroupInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Image
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ImageInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Item
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ItemAnnotation
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ItemDocVersion
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ItemPart
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ItemTransition_RangeID
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ItemTransition_ToID
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ItemInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Membership
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class MembershipInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Part
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class PartInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Pdf
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class PdfInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Permission
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class PermissionInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RODb
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RODbDROUsage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RODbROFst
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RODbROImage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RODbRoUsage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RODbInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROFst
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROFstAssociation
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROFstFigure
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROFstInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROImage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROImageFigure
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ROImageInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Role
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RoleAssignment
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RolePermission
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RoleInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RoUsage
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class RoUsageInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Transition
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class TransitionInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class User
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class UserMembership
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class UserInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ZContent
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ZContentInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ZTransition
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class ZTransitionInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }