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