CSLA - Generated - Batch - As

This commit is contained in:
2026-09-03 08:05:32 -04:00
parent dc5d547449
commit 222371302f
17 changed files with 1368 additions and 2751 deletions
@@ -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)
refreshAnnotations.Add(this); refreshAnnotations.Add(this);
} }
private void ClearRefreshList() private void ClearRefreshList() => _RefreshAnnotations = new List<Annotation>();
{
_RefreshAnnotations = new List<Annotation>();
}
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<Annotation> _CacheList = new List<Annotation>(); private static List<Annotation> _CacheList = new List<Annotation>();
protected static void AddToCache(Annotation annotation) protected static void AddToCache(Annotation annotation)
{ {
@@ -67,6 +63,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(annotation)) _CacheList.Remove(annotation); // In RemoveFromCache while (_CacheList.Contains(annotation)) _CacheList.Remove(annotation); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Annotation>> _CacheByPrimaryKey = new Dictionary<string, List<Annotation>>(); private static Dictionary<string, List<Annotation>> _CacheByPrimaryKey = new Dictionary<string, List<Annotation>>();
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 _nextAnnotationID = -1; private static int _nextAnnotationID = -1;
public static int NextAnnotationID public static int NextAnnotationID => _nextAnnotationID--;
{
get { return _nextAnnotationID--; }
}
private int _AnnotationID; private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID public int AnnotationID
@@ -280,37 +271,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 || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirtyList(list)) || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); return base.IsDirty || (_MyAnnotationType != null && _MyAnnotationType.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) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValidList(list)) && (_MyItem == null ? true : _MyItem.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_MyAnnotationType == null || _MyAnnotationType.IsValidList(list)) && (_MyItem == null || _MyItem.IsValidList(list));
} }
// CSLATODO: Replace base Annotation.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Annotation</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Annotation.GetIdValue to assure that the ID returned is unique // CSLATODO: Check Annotation.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 Annotation</returns> /// <returns>A Unique ID for the current Annotation</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationUnique; // Absolutely Unique ID
{
return MyAnnotationUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -340,8 +316,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()
@@ -362,15 +338,9 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule( ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength, Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
//ValidationRules.AddDependantProperty("x", "y");
_AnnotationExtension.AddValidationRules(ValidationRules); _AnnotationExtension.AddValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
protected override void AddInstanceBusinessRules()
{
_AnnotationExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
} }
protected override void AddInstanceBusinessRules() => _AnnotationExtension.AddInstanceValidationRules(ValidationRules);
private static bool MyItemRequired(Annotation target, Csla.Validation.RuleArgs e) private static bool MyItemRequired(Annotation target, Csla.Validation.RuleArgs e)
{ {
if (target._ItemID == 0 && target._MyItem == null) // Required field missing if (target._ItemID == 0 && target._MyItem == null) // Required field missing
@@ -389,97 +359,25 @@ 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
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AnnotationID, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
//AuthorizationRules.AllowRead(RtfText, "<Role(s)>");
//AuthorizationRules.AllowRead(SearchText, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(TypeID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RtfText, "<Role(s)>");
//AuthorizationRules.AllowWrite(SearchText, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_AnnotationExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_AnnotationExtension.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
{ get { return EditLevel; } }
private static int _AnnotationUnique = 0; private static int _AnnotationUnique = 0;
protected static int AnnotationUnique protected static int AnnotationUnique => ++_AnnotationUnique;
{ get { return ++_AnnotationUnique; } } private readonly int _MyAnnotationUnique = AnnotationUnique;
private int _MyAnnotationUnique = AnnotationUnique; // Absolutely Unique ID - Editable
public int MyAnnotationUnique // Absolutely Unique ID - Editable public int MyAnnotationUnique => _MyAnnotationUnique;
{ get { return _MyAnnotationUnique; } }
protected Annotation() protected Annotation()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
} }
private bool _Disposed = false; private bool _Disposed = false;
private static int _CountCreated = 0; private static readonly 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 public static int CountCreated => _CountCreated;
{ get { return ++_CountCreated; } } public static int CountNotDisposed => _CountCreated - _CountDisposed;
private int _CountWhenCreated = IncrementCountCreated; public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~Annotation() ~Annotation()
{ {
_CountFinalized++; _CountFinalized++;
@@ -504,8 +402,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Annotation New() public static Annotation New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Annotation");
try try
{ {
return DataPortal.Create<Annotation>(); return DataPortal.Create<Annotation>();
@@ -578,8 +474,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Annotation Get(int annotationID) public static Annotation Get(int annotationID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Annotation");
try try
{ {
Annotation tmp = GetCachedByPrimaryKey(annotationID); Annotation tmp = GetCachedByPrimaryKey(annotationID);
@@ -611,8 +505,6 @@ namespace VEPROMS.CSLA.Library
} }
public static void Delete(int annotationID) public static void Delete(int annotationID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Annotation");
try try
{ {
DataPortal.Delete(new PKCriteria(annotationID)); DataPortal.Delete(new PKCriteria(annotationID));
@@ -624,12 +516,6 @@ namespace VEPROMS.CSLA.Library
} }
public override Annotation Save() public override Annotation Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Annotation");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Annotation");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Annotation");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -650,13 +536,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _AnnotationID; private readonly int _AnnotationID;
public int AnnotationID public int AnnotationID => _AnnotationID;
{ get { return _AnnotationID; } } public PKCriteria(int annotationID) => _AnnotationID = annotationID;
public PKCriteria(int annotationID)
{
_AnnotationID = annotationID;
}
} }
// 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()]
@@ -756,12 +638,13 @@ 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 (_MyAnnotationType != null) _MyAnnotationType.Update(); _MyAnnotationType?.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()) using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; cm.CommandType = CommandType.StoredProcedure;
@@ -776,11 +659,15 @@ namespace VEPROMS.CSLA.Library
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int); SqlParameter param_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int)
param_AnnotationID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AnnotationID); cm.Parameters.Add(param_AnnotationID);
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();
@@ -788,6 +675,8 @@ namespace VEPROMS.CSLA.Library
_AnnotationID = (int)cm.Parameters["@newAnnotationID"].Value; _AnnotationID = (int)cm.Parameters["@newAnnotationID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
}
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLInsert", GetHashCode());
@@ -819,11 +708,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int); SqlParameter param_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int)
param_AnnotationID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AnnotationID); cm.Parameters.Add(param_AnnotationID);
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();
@@ -868,9 +761,10 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLUpdate", GetHashCode());
try try
{ {
if (_MyAnnotationType != null) _MyAnnotationType.Update(); _MyAnnotationType?.Update();
if (_MyItem != null) _MyItem.Update(); _MyItem?.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty) if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
@@ -889,8 +783,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();
@@ -898,6 +794,8 @@ namespace VEPROMS.CSLA.Library
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
} }
}
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
} }
@@ -910,14 +808,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) if (IsNew)
_LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID); _LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
else else
_LastChanged = Annotation.Update(cn, ref _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); _LastChanged = Annotation.Update(cn, ref _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
} }
@@ -943,8 +844,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();
@@ -1029,16 +932,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private int _AnnotationID; private readonly int _AnnotationID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(int annotationID) => _AnnotationID = annotationID;
get { return _exists; }
}
public ExistsCommand(int annotationID)
{
_AnnotationID = annotationID;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Execute", GetHashCode());
@@ -1068,7 +965,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
AnnotationExtension _AnnotationExtension = new AnnotationExtension(); readonly AnnotationExtension _AnnotationExtension = new AnnotationExtension();
[Serializable()] [Serializable()]
partial class AnnotationExtension : extensionBase partial class AnnotationExtension : extensionBase
{ {
@@ -1077,14 +974,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)
{ {
@@ -1113,57 +1004,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 Annotation) if (destType == typeof(string) && value is Annotation ann)
{ {
// Return the ToString value // Return the ToString value
return ((Annotation)value).ToString(); return ann.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 AnnotationExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Annotation
// {
// partial class AnnotationExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -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<AnnotationAudit> _CacheList = new List<AnnotationAudit>(); private static List<AnnotationAudit> _CacheList = new List<AnnotationAudit>();
protected static void AddToCache(AnnotationAudit annotationAudit) protected static void AddToCache(AnnotationAudit annotationAudit)
{ {
@@ -65,6 +64,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(annotationAudit)) _CacheList.Remove(annotationAudit); // In RemoveFromCache while (_CacheList.Contains(annotationAudit)) _CacheList.Remove(annotationAudit); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AnnotationAudit>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationAudit>>(); private static Dictionary<string, List<AnnotationAudit>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationAudit>>();
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
@@ -275,40 +269,15 @@ 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 AnnotationAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AnnotationAudit.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AnnotationAudit.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 AnnotationAudit</returns> /// <returns>A Unique ID for the current AnnotationAudit</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationAuditUnique; // Absolutely Unique ID
{
return MyAnnotationAuditUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -336,8 +305,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()
@@ -356,93 +325,15 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule( ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength, Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200));
//ValidationRules.AddDependantProperty("x", "y");
_AnnotationAuditExtension.AddValidationRules(ValidationRules); _AnnotationAuditExtension.AddValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
protected override void AddInstanceBusinessRules()
{
_AnnotationAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(AnnotationID, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
//AuthorizationRules.AllowRead(RtfText, "<Role(s)>");
//AuthorizationRules.AllowRead(SearchText, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(AnnotationID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(TypeID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RtfText, "<Role(s)>");
//AuthorizationRules.AllowWrite(SearchText, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_AnnotationAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_AnnotationAuditExtension.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
{ get { return EditLevel; } }
private static int _AnnotationAuditUnique = 0; private static int _AnnotationAuditUnique = 0;
protected static int AnnotationAuditUnique protected static int AnnotationAuditUnique => ++_AnnotationAuditUnique;
{ get { return ++_AnnotationAuditUnique; } } private readonly int _MyAnnotationAuditUnique = AnnotationAuditUnique;
private int _MyAnnotationAuditUnique = AnnotationAuditUnique; // Absolutely Unique ID - Editable
public int MyAnnotationAuditUnique // Absolutely Unique ID - Editable public int MyAnnotationAuditUnique => _MyAnnotationAuditUnique;
{ get { return _MyAnnotationAuditUnique; } }
protected AnnotationAudit() protected AnnotationAudit()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -451,15 +342,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; } }
~AnnotationAudit() ~AnnotationAudit()
{ {
_CountFinalized++; _CountFinalized++;
@@ -484,8 +371,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationAudit New() public static AnnotationAudit New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit");
try try
{ {
return DataPortal.Create<AnnotationAudit>(); return DataPortal.Create<AnnotationAudit>();
@@ -531,15 +416,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 AnnotationAudit Get(long auditID) public static AnnotationAudit Get(long auditID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit");
try try
{ {
AnnotationAudit tmp = GetCachedByPrimaryKey(auditID); AnnotationAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -565,14 +448,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new AnnotationAudit(dr); if (dr.Read()) return new AnnotationAudit(dr);
return null; return null;
} }
internal AnnotationAudit(SafeDataReader dr) internal AnnotationAudit(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 AnnotationAudit");
try try
{ {
DataPortal.Delete(new PKCriteria(auditID)); DataPortal.Delete(new PKCriteria(auditID));
@@ -584,12 +462,6 @@ namespace VEPROMS.CSLA.Library
} }
public override AnnotationAudit Save() public override AnnotationAudit Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a AnnotationAudit");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -609,13 +481,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()]
@@ -715,10 +583,11 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert() internal void SQLInsert()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; cm.CommandType = CommandType.StoredProcedure;
@@ -735,14 +604,18 @@ 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();
// Save all values being returned from the Procedure // Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value; _AuditID = (long)cm.Parameters["@newAuditID"].Value;
} }
}
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode());
@@ -776,8 +649,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();
@@ -822,7 +697,8 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLUpdate", GetHashCode());
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty) if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
@@ -847,6 +723,8 @@ namespace VEPROMS.CSLA.Library
// Save all values being returned from the Procedure // 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
} }
@@ -859,14 +737,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) if (IsNew)
AnnotationAudit.Add(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); AnnotationAudit.Add(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus);
else else
AnnotationAudit.Update(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); AnnotationAudit.Update(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus);
}
MarkOld(); MarkOld();
} }
} }
@@ -976,16 +857,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private long _AuditID; private readonly long _AuditID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(long auditID) => _AuditID = auditID;
get { return _exists; }
}
public ExistsCommand(long auditID)
{
_AuditID = auditID;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Execute", GetHashCode());
@@ -1015,7 +890,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
AnnotationAuditExtension _AnnotationAuditExtension = new AnnotationAuditExtension(); readonly AnnotationAuditExtension _AnnotationAuditExtension = new AnnotationAuditExtension();
[Serializable()] [Serializable()]
partial class AnnotationAuditExtension : extensionBase partial class AnnotationAuditExtension : extensionBase
{ {
@@ -1052,49 +927,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 AnnotationAudit) if (destType == typeof(string) && value is AnnotationAudit audit)
{ {
// Return the ToString value // Return the ToString value
return ((AnnotationAudit)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 AnnotationAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class AnnotationAudit
// {
// partial class AnnotationAuditExtension : 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 AnnotationAuditInfo : ReadOnlyBase<AnnotationAuditInfo>, IDisposable public partial class AnnotationAuditInfo : ReadOnlyBase<AnnotationAuditInfo>, IDisposable
{ {
public event AnnotationAuditInfoEvent Changed; public event AnnotationAuditInfoEvent 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<AnnotationAuditInfo> _CacheList = new List<AnnotationAuditInfo>(); private static List<AnnotationAuditInfo> _CacheList = new List<AnnotationAuditInfo>();
protected static void AddToCache(AnnotationAuditInfo annotationAuditInfo) protected static void AddToCache(AnnotationAuditInfo annotationAuditInfo)
{ {
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(annotationAuditInfo)) _CacheList.Remove(annotationAuditInfo); // In RemoveFromCache while (_CacheList.Contains(annotationAuditInfo)) _CacheList.Remove(annotationAuditInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AnnotationAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationAuditInfo>>(); private static Dictionary<string, List<AnnotationAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationAuditInfo>>();
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 AnnotationAudit _Editable; protected AnnotationAudit _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
@@ -180,32 +164,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus; return _DeleteStatus;
} }
} }
// CSLATODO: Replace base AnnotationAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AnnotationAuditInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AnnotationAuditInfo.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 AnnotationAuditInfo</returns> /// <returns>A Unique ID for the current AnnotationAuditInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationAuditInfoUnique; // Absolutely Unique ID
{
return MyAnnotationAuditInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _AnnotationAuditInfoUnique = 0; private static int _AnnotationAuditInfoUnique = 0;
private static int AnnotationAuditInfoUnique private static int AnnotationAuditInfoUnique => ++_AnnotationAuditInfoUnique;
{ get { return ++_AnnotationAuditInfoUnique; } } private readonly int _MyAnnotationAuditInfoUnique = AnnotationAuditInfoUnique;
private int _MyAnnotationAuditInfoUnique = AnnotationAuditInfoUnique; // Absolutely Unique ID - Info
public int MyAnnotationAuditInfoUnique // Absolutely Unique ID - Info public int MyAnnotationAuditInfoUnique => _MyAnnotationAuditInfoUnique;
{ get { return _MyAnnotationAuditInfoUnique; } }
protected AnnotationAuditInfo() protected AnnotationAuditInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -214,15 +185,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; } }
~AnnotationAuditInfo() ~AnnotationAuditInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -267,8 +234,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationAuditInfo Get(long auditID) public static AnnotationAuditInfo Get(long auditID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit");
try try
{ {
AnnotationAuditInfo tmp = GetCachedByPrimaryKey(auditID); AnnotationAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -307,13 +272,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)
{ {
@@ -377,7 +338,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
AnnotationAuditInfoExtension _AnnotationAuditInfoExtension = new AnnotationAuditInfoExtension(); readonly AnnotationAuditInfoExtension _AnnotationAuditInfoExtension = new AnnotationAuditInfoExtension();
[Serializable()] [Serializable()]
partial class AnnotationAuditInfoExtension : extensionBase { } partial class AnnotationAuditInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -393,10 +354,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 AnnotationAuditInfo) if (destType == typeof(string) && value is AnnotationAuditInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((AnnotationAuditInfo)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<AnnotationAuditInfo> Items internal new IList<AnnotationAuditInfo> Items => base.Items;
{ get { return base.Items; } }
public void AddEvents() public void AddEvents()
{ {
foreach (AnnotationAuditInfo tmp in this) foreach (AnnotationAuditInfo tmp in this)
@@ -51,15 +48,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; } }
~AnnotationAuditInfoList() ~AnnotationAuditInfoList()
{ {
_CountFinalized++; _CountFinalized++;
@@ -97,25 +90,6 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AnnotationAuditInfoList.Get", ex); throw new DbCslaException("Error on AnnotationAuditInfoList.Get", ex);
} }
} }
/// <summary>
/// Reset the list of all AnnotationAuditInfo.
/// </summary>
public static void Reset()
{
_AnnotationAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static AnnotationAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<AnnotationAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on AnnotationAuditInfoList.Get", ex);
// }
//}
private AnnotationAuditInfoList() private AnnotationAuditInfoList()
{ /* require use of factory methods */ } { /* require use of factory methods */ }
#endregion #endregion
@@ -151,34 +125,23 @@ namespace VEPROMS.CSLA.Library
} }
#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>
@@ -205,7 +168,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class AnnotationAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class AnnotationAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private AnnotationAuditInfo Item { get { return (AnnotationAuditInfo)_Item; } }
public AnnotationAuditInfoListPropertyDescriptor(AnnotationAuditInfoList collection, int index) : base(collection, index) { ;} public AnnotationAuditInfoListPropertyDescriptor(AnnotationAuditInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -214,10 +176,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 AnnotationAuditInfoList) if (destType == typeof(string) && value is AnnotationAuditInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((AnnotationAuditInfoList)value).Items.Count.ToString() + " AnnotationAudits"; return $"{list.Items.Count} AnnotationAudits";
} }
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,27 +26,20 @@ namespace VEPROMS.CSLA.Library
public partial class AnnotationInfo : ReadOnlyBase<AnnotationInfo>, IDisposable public partial class AnnotationInfo : ReadOnlyBase<AnnotationInfo>, IDisposable
{ {
public static event AnnotationInfoEvent InfoChanged; public static event AnnotationInfoEvent InfoChanged;
internal void OnInfoChanged(AnnotationInfo annotationInfo) [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping paramater for CSLA support")]
{ internal void OnInfoChanged(AnnotationInfo annotationInfo) => InfoChanged?.Invoke(this);
if (InfoChanged != null) internal static void StaticOnInfoChanged() => InfoChanged?.Invoke(null);
InfoChanged(this);
}
internal static void StaticOnInfoChanged()
{
if (InfoChanged != null)
InfoChanged(null);
}
public event AnnotationInfoEvent Changed; public event AnnotationInfoEvent Changed;
private void OnChange() private void OnChange()
{ {
if (Changed != null) Changed?.Invoke(this);
Changed(this);
OnInfoChanged(this); OnInfoChanged(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<AnnotationInfo> _CacheList = new List<AnnotationInfo>(); private static List<AnnotationInfo> _CacheList = new List<AnnotationInfo>();
protected static void AddToCache(AnnotationInfo annotationInfo) protected static void AddToCache(AnnotationInfo annotationInfo)
{ {
@@ -58,6 +49,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(annotationInfo)) _CacheList.Remove(annotationInfo); // In RemoveFromCache while (_CacheList.Contains(annotationInfo)) _CacheList.Remove(annotationInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AnnotationInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationInfo>>(); private static Dictionary<string, List<AnnotationInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -87,21 +79,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 Annotation _Editable; protected Annotation _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _AnnotationID; private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID public int AnnotationID
@@ -197,32 +176,19 @@ namespace VEPROMS.CSLA.Library
return _UserID; return _UserID;
} }
} }
// CSLATODO: Replace base AnnotationInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AnnotationInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AnnotationInfo.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 AnnotationInfo</returns> /// <returns>A Unique ID for the current AnnotationInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationInfoUnique; // Absolutely Unique ID
{
return MyAnnotationInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _AnnotationInfoUnique = 0; private static int _AnnotationInfoUnique = 0;
private static int AnnotationInfoUnique private static int AnnotationInfoUnique => ++_AnnotationInfoUnique;
{ get { return ++_AnnotationInfoUnique; } } private readonly int _MyAnnotationInfoUnique = AnnotationInfoUnique;
private int _MyAnnotationInfoUnique = AnnotationInfoUnique; // Absolutely Unique ID - Info
public int MyAnnotationInfoUnique // Absolutely Unique ID - Info public int MyAnnotationInfoUnique => _MyAnnotationInfoUnique;
{ get { return _MyAnnotationInfoUnique; } }
protected AnnotationInfo() protected AnnotationInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -231,15 +197,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; } }
~AnnotationInfo() ~AnnotationInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -256,10 +218,7 @@ namespace VEPROMS.CSLA.Library
if (listAnnotationInfo.Count == 0) // If there are no items left in the list if (listAnnotationInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list _CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list
} }
public virtual Annotation Get() public virtual Annotation Get() => _Editable = Annotation.Get(_AnnotationID);
{
return _Editable = Annotation.Get(_AnnotationID);
}
public static void Refresh(Annotation tmp) public static void Refresh(Annotation tmp)
{ {
string key = tmp.AnnotationID.ToString(); string key = tmp.AnnotationID.ToString();
@@ -272,18 +231,18 @@ namespace VEPROMS.CSLA.Library
{ {
if (_ItemID != tmp.ItemID) if (_ItemID != tmp.ItemID)
{ {
if (MyItem != null) MyItem.RefreshItemAnnotations(); // Update List for old value MyItem?.RefreshItemAnnotations(); // 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.RefreshItemAnnotations(); // Update List for new value MyItem?.RefreshItemAnnotations(); // Update List for new value
if (_TypeID != tmp.TypeID) if (_TypeID != tmp.TypeID)
{ {
if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value MyAnnotationType?.RefreshAnnotationTypeAnnotations(); // Update List for old value
_TypeID = tmp.TypeID; // Update the value _TypeID = tmp.TypeID; // Update the value
} }
_MyAnnotationType = null; // Reset list so that the next line gets a new list _MyAnnotationType = null; // Reset list so that the next line gets a new list
if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for new value MyAnnotationType?.RefreshAnnotationTypeAnnotations(); // Update List for new value
_RtfText = tmp.RtfText; _RtfText = tmp.RtfText;
_SearchText = tmp.SearchText; _SearchText = tmp.SearchText;
_Config = tmp.Config; _Config = tmp.Config;
@@ -304,11 +263,11 @@ namespace VEPROMS.CSLA.Library
{ {
if (_ItemID != tmp.ItemID) if (_ItemID != tmp.ItemID)
{ {
if (MyItem != null) MyItem.RefreshItemAnnotations(); // Update List for old value MyItem?.RefreshItemAnnotations(); // 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.RefreshItemAnnotations(); // Update List for new value MyItem?.RefreshItemAnnotations(); // Update List for new value
_RtfText = tmp.RtfText; _RtfText = tmp.RtfText;
_SearchText = tmp.SearchText; _SearchText = tmp.SearchText;
_Config = tmp.Config; _Config = tmp.Config;
@@ -329,11 +288,11 @@ namespace VEPROMS.CSLA.Library
{ {
if (_TypeID != tmp.TypeID) if (_TypeID != tmp.TypeID)
{ {
if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value MyAnnotationType?.RefreshAnnotationTypeAnnotations(); // Update List for old value
_TypeID = tmp.TypeID; // Update the value _TypeID = tmp.TypeID; // Update the value
} }
_MyAnnotationType = null; // Reset list so that the next line gets a new list _MyAnnotationType = null; // Reset list so that the next line gets a new list
if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for new value MyAnnotationType?.RefreshAnnotationTypeAnnotations(); // Update List for new value
_RtfText = tmp.RtfText; _RtfText = tmp.RtfText;
_SearchText = tmp.SearchText; _SearchText = tmp.SearchText;
_Config = tmp.Config; _Config = tmp.Config;
@@ -344,8 +303,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationInfo Get(int annotationID) public static AnnotationInfo Get(int annotationID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Annotation");
try try
{ {
AnnotationInfo tmp = GetCachedByPrimaryKey(annotationID); AnnotationInfo tmp = GetCachedByPrimaryKey(annotationID);
@@ -384,13 +341,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _AnnotationID; private readonly int _AnnotationID;
public int AnnotationID public int AnnotationID => _AnnotationID;
{ get { return _AnnotationID; } } public PKCriteria(int annotationID) => _AnnotationID = annotationID;
public PKCriteria(int annotationID)
{
_AnnotationID = annotationID;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -452,7 +405,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
AnnotationInfoExtension _AnnotationInfoExtension = new AnnotationInfoExtension(); readonly AnnotationInfoExtension _AnnotationInfoExtension = new AnnotationInfoExtension();
[Serializable()] [Serializable()]
partial class AnnotationInfoExtension : extensionBase { } partial class AnnotationInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -468,10 +421,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 AnnotationInfo) if (destType == typeof(string) && value is AnnotationInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((AnnotationInfo)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<AnnotationInfo> Items internal new IList<AnnotationInfo> Items => base.Items;
{ get { return base.Items; } }
public void AddEvents() public void AddEvents()
{ {
foreach (AnnotationInfo tmp in this) foreach (AnnotationInfo tmp in this)
@@ -51,15 +48,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; } }
~AnnotationInfoList() ~AnnotationInfoList()
{ {
_CountFinalized++; _CountFinalized++;
@@ -97,25 +90,6 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AnnotationInfoList.Get", ex); throw new DbCslaException("Error on AnnotationInfoList.Get", ex);
} }
} }
/// <summary>
/// Reset the list of all AnnotationInfo.
/// </summary>
public static void Reset()
{
_AnnotationInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static AnnotationInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<AnnotationInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on AnnotationInfoList.Get", ex);
// }
//}
public static AnnotationInfoList GetByTypeID(int typeID) public static AnnotationInfoList GetByTypeID(int typeID)
{ {
try try
@@ -139,7 +113,7 @@ namespace VEPROMS.CSLA.Library
tmp.AddEvents(); tmp.AddEvents();
return tmp; return tmp;
} }
catch (Exception ex) catch (Exception)
{ {
return new AnnotationInfoList();// B2017-246 If an exception return an empty list return new AnnotationInfoList();// B2017-246 If an exception return an empty list
} }
@@ -180,10 +154,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class TypeIDCriteria private class TypeIDCriteria
{ {
public TypeIDCriteria(int typeID) public TypeIDCriteria(int typeID) => _TypeID = typeID;
{
_TypeID = typeID;
}
private int _TypeID; private int _TypeID;
public int TypeID public int TypeID
{ {
@@ -224,10 +195,7 @@ namespace VEPROMS.CSLA.Library
[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
{ {
@@ -267,34 +235,23 @@ namespace VEPROMS.CSLA.Library
} }
#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>
@@ -321,7 +278,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class AnnotationInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class AnnotationInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private AnnotationInfo Item { get { return (AnnotationInfo)_Item; } }
public AnnotationInfoListPropertyDescriptor(AnnotationInfoList collection, int index) : base(collection, index) { ;} public AnnotationInfoListPropertyDescriptor(AnnotationInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -330,10 +286,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 AnnotationInfoList) if (destType == typeof(string) && value is AnnotationInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((AnnotationInfoList)value).Items.Count.ToString() + " Annotations"; return $"{list.Items.Count} Annotations";
} }
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;
using Csla.Validation; using Csla.Validation;
@@ -71,6 +69,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<AnnotationType> _CacheList = new List<AnnotationType>(); private static List<AnnotationType> _CacheList = new List<AnnotationType>();
protected static void AddToCache(AnnotationType annotationType) protected static void AddToCache(AnnotationType annotationType)
{ {
@@ -80,7 +79,9 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(annotationType)) _CacheList.Remove(annotationType); // In RemoveFromCache while (_CacheList.Contains(annotationType)) _CacheList.Remove(annotationType); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AnnotationType>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationType>>(); private static Dictionary<string, List<AnnotationType>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationType>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AnnotationType>> _CacheByName = new Dictionary<string, List<AnnotationType>>(); private static Dictionary<string, List<AnnotationType>> _CacheByName = new Dictionary<string, List<AnnotationType>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -115,15 +116,9 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private static int _nextTypeID = -1; private static int _nextTypeID = -1;
public static int NextTypeID public static int NextTypeID => _nextTypeID--;
{
get { return _nextTypeID--; }
}
private int _TypeID; private int _TypeID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int TypeID public int TypeID
@@ -262,10 +257,6 @@ namespace VEPROMS.CSLA.Library
return _AnnotationTypeAnnotations; return _AnnotationTypeAnnotations;
} }
} }
public void Reset_AnnotationTypeAnnotations()
{
_AnnotationTypeAnnotationCount = -1;
}
public override bool IsDirty public override bool IsDirty
{ {
get get
@@ -280,37 +271,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 || (_AnnotationTypeAnnotations == null ? false : _AnnotationTypeAnnotations.IsDirtyList(list)); return base.IsDirty || (_AnnotationTypeAnnotations != null && _AnnotationTypeAnnotations.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) && (_AnnotationTypeAnnotations == null ? true : _AnnotationTypeAnnotations.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_AnnotationTypeAnnotations == null || _AnnotationTypeAnnotations.IsValidList(list));
} }
// CSLATODO: Replace base AnnotationType.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationType</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AnnotationType.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AnnotationType.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 AnnotationType</returns> /// <returns>A Unique ID for the current AnnotationType</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationTypeUnique; // Absolutely Unique ID
{
return MyAnnotationTypeUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -339,8 +315,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()
@@ -362,92 +338,14 @@ namespace VEPROMS.CSLA.Library
_AnnotationTypeExtension.AddValidationRules(ValidationRules); _AnnotationTypeExtension.AddValidationRules(ValidationRules);
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
protected override void AddInstanceBusinessRules()
{
_AnnotationTypeExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_AnnotationTypeExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_AnnotationTypeExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _AnnotationTypeAnnotationCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _AnnotationTypeUnique = 0; private static int _AnnotationTypeUnique = 0;
protected static int AnnotationTypeUnique protected static int AnnotationTypeUnique => ++_AnnotationTypeUnique;
{ get { return ++_AnnotationTypeUnique; } } private readonly int _MyAnnotationTypeUnique = AnnotationTypeUnique;
private int _MyAnnotationTypeUnique = AnnotationTypeUnique; // Absolutely Unique ID - Editable
public int MyAnnotationTypeUnique // Absolutely Unique ID - Editable public int MyAnnotationTypeUnique => _MyAnnotationTypeUnique;
{ get { return _MyAnnotationTypeUnique; } }
protected AnnotationType() protected AnnotationType()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -456,15 +354,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; } }
~AnnotationType() ~AnnotationType()
{ {
_CountFinalized++; _CountFinalized++;
@@ -501,8 +395,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationType New() public static AnnotationType New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a AnnotationType");
try try
{ {
return DataPortal.Create<AnnotationType>(); return DataPortal.Create<AnnotationType>();
@@ -568,8 +460,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationType Get(int typeID) public static AnnotationType Get(int typeID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
try try
{ {
AnnotationType tmp = GetCachedByPrimaryKey(typeID); AnnotationType tmp = GetCachedByPrimaryKey(typeID);
@@ -592,8 +482,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationType GetByName(string name) public static AnnotationType GetByName(string name)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
try try
{ {
AnnotationType tmp = GetCachedByName(name); AnnotationType tmp = GetCachedByName(name);
@@ -618,8 +506,6 @@ namespace VEPROMS.CSLA.Library
// doesn't exist, create it (fix B2016-083) // doesn't exist, create it (fix B2016-083)
public static AnnotationType GetByNameOrCreate(string name) public static AnnotationType GetByNameOrCreate(string name)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
try try
{ {
AnnotationType tmp = GetCachedByName(name); AnnotationType tmp = GetCachedByName(name);
@@ -655,8 +541,6 @@ namespace VEPROMS.CSLA.Library
} }
public static void Delete(int typeID) public static void Delete(int typeID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a AnnotationType");
try try
{ {
DataPortal.Delete(new PKCriteria(typeID)); DataPortal.Delete(new PKCriteria(typeID));
@@ -668,12 +552,6 @@ namespace VEPROMS.CSLA.Library
} }
public override AnnotationType Save() public override AnnotationType Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a AnnotationType");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a AnnotationType");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a AnnotationType");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -693,24 +571,16 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _TypeID; private readonly int _TypeID;
public int TypeID public int TypeID => _TypeID;
{ get { return _TypeID; } } public PKCriteria(int typeID) => _TypeID = typeID;
public PKCriteria(int typeID)
{
_TypeID = typeID;
}
} }
[Serializable()] [Serializable()]
private class NameCriteria private class NameCriteria
{ {
private string _Name; private readonly string _Name;
public string Name public string Name => _Name;
{ get { return _Name; } } public NameCriteria(string name) => _Name = name;
public NameCriteria(string name)
{
_Name = name;
}
} }
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal // CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()] [RunLocal()]
@@ -849,10 +719,11 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert() internal void SQLInsert()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; cm.CommandType = CommandType.StoredProcedure;
@@ -864,11 +735,15 @@ namespace VEPROMS.CSLA.Library
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int); SqlParameter param_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int)
param_TypeID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_TypeID); cm.Parameters.Add(param_TypeID);
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();
@@ -876,9 +751,11 @@ namespace VEPROMS.CSLA.Library
_TypeID = (int)cm.Parameters["@newTypeID"].Value; _TypeID = (int)cm.Parameters["@newTypeID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
}
MarkOld(); MarkOld();
// update child objects // update child objects
if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); _AnnotationTypeAnnotations?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLInsert", GetHashCode());
} }
catch (Exception ex) catch (Exception ex)
@@ -905,11 +782,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int); SqlParameter param_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int)
param_TypeID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_TypeID); cm.Parameters.Add(param_TypeID);
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();
@@ -954,7 +835,8 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLUpdate", GetHashCode());
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty) if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
@@ -970,8 +852,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();
@@ -979,9 +863,11 @@ namespace VEPROMS.CSLA.Library
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
} }
}
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); _AnnotationTypeAnnotations?.Update(this);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -992,17 +878,20 @@ namespace VEPROMS.CSLA.Library
} }
internal void Update() internal void Update()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
if (base.IsDirty) if (base.IsDirty)
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew) if (IsNew)
_LastChanged = AnnotationType.Add(cn, ref _TypeID, _Name, _Config, _DTS, _UserID); _LastChanged = AnnotationType.Add(cn, ref _TypeID, _Name, _Config, _DTS, _UserID);
else else
_LastChanged = AnnotationType.Update(cn, ref _TypeID, _Name, _Config, _DTS, _UserID, ref _LastChanged); _LastChanged = AnnotationType.Update(cn, ref _TypeID, _Name, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); _AnnotationTypeAnnotations?.Update(this);
} }
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int typeID, string name, string config, DateTime dts, string userID, ref byte[] lastChanged) public static byte[] Update(SqlConnection cn, ref int typeID, string name, string config, DateTime dts, string userID, ref byte[] lastChanged)
@@ -1023,8 +912,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();
@@ -1039,10 +930,7 @@ namespace VEPROMS.CSLA.Library
} }
} }
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_TypeID));
{
DataPortal_Delete(new PKCriteria(_TypeID));
}
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria) private void DataPortal_Delete(PKCriteria criteria)
{ {
@@ -1109,16 +997,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private int _TypeID; private readonly int _TypeID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(int typeID) => _TypeID = typeID;
get { return _exists; }
}
public ExistsCommand(int typeID)
{
_TypeID = typeID;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Execute", GetHashCode());
@@ -1148,7 +1030,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
AnnotationTypeExtension _AnnotationTypeExtension = new AnnotationTypeExtension(); readonly AnnotationTypeExtension _AnnotationTypeExtension = new AnnotationTypeExtension();
[Serializable()] [Serializable()]
partial class AnnotationTypeExtension : extensionBase partial class AnnotationTypeExtension : extensionBase
{ {
@@ -1157,14 +1039,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)
{ {
@@ -1193,57 +1069,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 AnnotationType) if (destType == typeof(string) && value is AnnotationType type)
{ {
// Return the ToString value // Return the ToString value
return ((AnnotationType)value).ToString(); return type.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 AnnotationTypeExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class AnnotationType
// {
// partial class AnnotationTypeExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ======================================================================== // ========================================================================
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _AnnotationID; private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID public int AnnotationID
@@ -224,10 +218,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current AnnotationTypeAnnotation</returns> /// <returns>A Unique ID for the current AnnotationTypeAnnotation</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationTypeAnnotationUnique; // Absolutely Unique ID
{
return MyAnnotationTypeAnnotationUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base AnnotationTypeAnnotation.ToString function as necessary // CSLATODO: Replace base AnnotationTypeAnnotation.ToString function as necessary
/// <summary> /// <summary>
/// Overrides Base ToString /// Overrides Base ToString
@@ -251,18 +242,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); return base.IsDirty || (_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) && (_MyItem == null ? true : _MyItem.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_MyItem == null || _MyItem.IsValidList(list));
} }
#endregion #endregion
#region ValidationRules #region ValidationRules
@@ -292,8 +280,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()
@@ -324,80 +312,16 @@ 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
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AnnotationID, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(RtfText, "<Role(s)>");
//AuthorizationRules.AllowWrite(RtfText, "<Role(s)>");
//AuthorizationRules.AllowRead(SearchText, "<Role(s)>");
//AuthorizationRules.AllowWrite(SearchText, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _AnnotationTypeAnnotationUnique = 0; private static int _AnnotationTypeAnnotationUnique = 0;
private static int AnnotationTypeAnnotationUnique private static int AnnotationTypeAnnotationUnique => ++_AnnotationTypeAnnotationUnique;
{ get { return ++_AnnotationTypeAnnotationUnique; } } private readonly int _MyAnnotationTypeAnnotationUnique = AnnotationTypeAnnotationUnique;
private int _MyAnnotationTypeAnnotationUnique = AnnotationTypeAnnotationUnique; // Absolutely Unique ID - Editable FK
public int MyAnnotationTypeAnnotationUnique // Absolutely Unique ID - Editable FK public int MyAnnotationTypeAnnotationUnique => _MyAnnotationTypeAnnotationUnique;
{ get { return _MyAnnotationTypeAnnotationUnique; } } internal static AnnotationTypeAnnotation New(Item myItem) => new AnnotationTypeAnnotation(myItem);
internal static AnnotationTypeAnnotation New(Item myItem) internal static AnnotationTypeAnnotation Get(SafeDataReader dr) => new AnnotationTypeAnnotation(dr);
{
return new AnnotationTypeAnnotation(myItem);
}
internal static AnnotationTypeAnnotation Get(SafeDataReader dr)
{
return new AnnotationTypeAnnotation(dr);
}
public AnnotationTypeAnnotation() public AnnotationTypeAnnotation()
{ {
MarkAsChild(); MarkAsChild();
@@ -425,15 +349,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; } }
~AnnotationTypeAnnotation() ~AnnotationTypeAnnotation()
{ {
_CountFinalized++; _CountFinalized++;
@@ -474,33 +394,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(AnnotationType myAnnotationType) internal void Insert(AnnotationType myAnnotationType)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, myAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID); _LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, myAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
}
MarkOld(); MarkOld();
} }
internal void Update(AnnotationType myAnnotationType) internal void Update(AnnotationType myAnnotationType)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Annotation.Update(cn, ref _AnnotationID, _ItemID, myAnnotationType.TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); _LastChanged = Annotation.Update(cn, ref _AnnotationID, _ItemID, myAnnotationType.TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping paramater for CSLA support")]
internal void DeleteSelf(AnnotationType myAnnotationType) internal void DeleteSelf(AnnotationType myAnnotationType)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Annotation.Remove(cn, _AnnotationID); Annotation.Remove(cn, _AnnotationID);
}
MarkNew(); MarkNew();
} }
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
AnnotationTypeAnnotationExtension _AnnotationTypeAnnotationExtension = new AnnotationTypeAnnotationExtension(); readonly AnnotationTypeAnnotationExtension _AnnotationTypeAnnotationExtension = new AnnotationTypeAnnotationExtension();
[Serializable()] [Serializable()]
partial class AnnotationTypeAnnotationExtension : extensionBase partial class AnnotationTypeAnnotationExtension : extensionBase
{ {
@@ -509,14 +439,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)
{ {
@@ -545,57 +469,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 AnnotationTypeAnnotation) if (destType == typeof(string) && value is AnnotationTypeAnnotation ann)
{ {
// Return the ToString value // Return the ToString value
return ((AnnotationTypeAnnotation)value).ToString(); return ann.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 AnnotationTypeAnnotationExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class AnnotationTypeAnnotation
// {
// partial class AnnotationTypeAnnotationExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +29,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
// One To Many // One To Many
public AnnotationTypeAnnotation this[Annotation myAnnotation] public AnnotationTypeAnnotation this[Annotation myAnnotation]
{ {
@@ -47,10 +42,7 @@ namespace VEPROMS.CSLA.Library
return null; return null;
} }
} }
public new System.Collections.Generic.IList<AnnotationTypeAnnotation> Items public new System.Collections.Generic.IList<AnnotationTypeAnnotation> Items => base.Items;
{
get { return base.Items; }
}
public AnnotationTypeAnnotation GetItem(Annotation myAnnotation) public AnnotationTypeAnnotation GetItem(Annotation myAnnotation)
{ {
foreach (AnnotationTypeAnnotation annotation in this) foreach (AnnotationTypeAnnotation annotation in this)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public AnnotationTypeAnnotation Add(Item myItem) // One to Many public AnnotationTypeAnnotation Add(Item myItem) // One to Many
{ {
AnnotationTypeAnnotation annotation = AnnotationTypeAnnotation.New(myItem); AnnotationTypeAnnotation annotation = AnnotationTypeAnnotation.New(myItem);
this.Add(annotation); Add(annotation);
return annotation; return annotation;
} }
public void Remove(Annotation myAnnotation) public void Remove(Annotation myAnnotation)
@@ -103,10 +95,6 @@ namespace VEPROMS.CSLA.Library
return true; return true;
return false; return false;
} }
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list) public bool IsValidList(List<object> list)
{ {
// run through all the child objects // run through all the child objects
@@ -137,19 +125,13 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return (hasBrokenRules?.BrokenRules);
} }
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
internal static AnnotationTypeAnnotations New() internal static AnnotationTypeAnnotations New() => new AnnotationTypeAnnotations();
{ internal static AnnotationTypeAnnotations Get(SafeDataReader dr) => new AnnotationTypeAnnotations(dr);
return new AnnotationTypeAnnotations();
}
internal static AnnotationTypeAnnotations Get(SafeDataReader dr)
{
return new AnnotationTypeAnnotations(dr);
}
public static AnnotationTypeAnnotations GetByTypeID(int typeID) public static AnnotationTypeAnnotations GetByTypeID(int typeID)
{ {
try try
@@ -161,10 +143,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AnnotationTypeAnnotations.GetByTypeID", ex); throw new DbCslaException("Error on AnnotationTypeAnnotations.GetByTypeID", ex);
} }
} }
private AnnotationTypeAnnotations() private AnnotationTypeAnnotations() => MarkAsChild();
{
MarkAsChild();
}
internal AnnotationTypeAnnotations(SafeDataReader dr) internal AnnotationTypeAnnotations(SafeDataReader dr)
{ {
MarkAsChild(); MarkAsChild();
@@ -174,15 +153,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; } }
~AnnotationTypeAnnotations() ~AnnotationTypeAnnotations()
{ {
_CountFinalized++; _CountFinalized++;
@@ -198,18 +173,15 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database // called to load data from the database
private void Fetch(SafeDataReader dr) private void Fetch(SafeDataReader dr)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
while (dr.Read()) while (dr.Read())
this.Add(AnnotationTypeAnnotation.Get(dr)); Add(AnnotationTypeAnnotation.Get(dr));
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class TypeIDCriteria private class TypeIDCriteria
{ {
public TypeIDCriteria(int typeID) public TypeIDCriteria(int typeID) => _TypeID = typeID;
{
_TypeID = typeID;
}
private int _TypeID; private int _TypeID;
public int TypeID public int TypeID
{ {
@@ -219,7 +191,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(TypeIDCriteria criteria) private void DataPortal_Fetch(TypeIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeAnnotations.DataPortal_FetchTypeID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeAnnotations.DataPortal_FetchTypeID", GetHashCode());
try try
{ {
@@ -233,7 +205,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 AnnotationTypeAnnotation(dr)); while (dr.Read()) Add(new AnnotationTypeAnnotation(dr));
} }
} }
} }
@@ -243,11 +215,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeAnnotations.DataPortal_FetchTypeID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeAnnotations.DataPortal_FetchTypeID", ex);
throw new DbCslaException("AnnotationTypeAnnotations.DataPortal_Fetch", ex); throw new DbCslaException("AnnotationTypeAnnotations.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
internal void Update(AnnotationType annotationType) internal void Update(AnnotationType annotationType)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
try try
{ {
// update (thus deleting) any deleted child objects // update (thus deleting) any deleted child objects
@@ -266,39 +238,28 @@ namespace VEPROMS.CSLA.Library
} }
finally finally
{ {
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public String GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary> /// <summary>
/// Called to get the properties of this type. Returns properties with certain /// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here. /// attributes. this restriction is not implemented here.
/// </summary> /// </summary>
/// <param name="attributes"></param> /// <param name="attributes"></param>
/// <returns></returns> /// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return GetProperties(); }
/// <summary> /// <summary>
/// Called to get the properties of this type. /// Called to get the properties of this type.
/// </summary> /// </summary>
@@ -308,7 +269,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
AnnotationTypeAnnotationsPropertyDescriptor pd = new AnnotationTypeAnnotationsPropertyDescriptor(this, i); AnnotationTypeAnnotationsPropertyDescriptor pd = new AnnotationTypeAnnotationsPropertyDescriptor(this, i);
@@ -325,7 +286,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class AnnotationTypeAnnotationsPropertyDescriptor : vlnListPropertyDescriptor public partial class AnnotationTypeAnnotationsPropertyDescriptor : vlnListPropertyDescriptor
{ {
private AnnotationTypeAnnotation Item { get { return (AnnotationTypeAnnotation)_Item; } }
public AnnotationTypeAnnotationsPropertyDescriptor(AnnotationTypeAnnotations collection, int index) : base(collection, index) { ;} public AnnotationTypeAnnotationsPropertyDescriptor(AnnotationTypeAnnotations collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -334,10 +294,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 AnnotationTypeAnnotations) if (destType == typeof(string) && value is AnnotationTypeAnnotations ann)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((AnnotationTypeAnnotations)value).Items.Count.ToString() + " Annotations"; return $"{ann.Items.Count} Annotations";
} }
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;
using System.Linq; using System.Linq;
@@ -30,14 +28,12 @@ namespace VEPROMS.CSLA.Library
public partial class AnnotationTypeInfo : ReadOnlyBase<AnnotationTypeInfo>, IDisposable public partial class AnnotationTypeInfo : ReadOnlyBase<AnnotationTypeInfo>, IDisposable
{ {
public event AnnotationTypeInfoEvent Changed; public event AnnotationTypeInfoEvent 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<AnnotationTypeInfo> _CacheList = new List<AnnotationTypeInfo>(); private static List<AnnotationTypeInfo> _CacheList = new List<AnnotationTypeInfo>();
protected static void AddToCache(AnnotationTypeInfo annotationTypeInfo) protected static void AddToCache(AnnotationTypeInfo annotationTypeInfo)
{ {
@@ -47,6 +43,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(annotationTypeInfo)) _CacheList.Remove(annotationTypeInfo); // In RemoveFromCache while (_CacheList.Contains(annotationTypeInfo)) _CacheList.Remove(annotationTypeInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AnnotationTypeInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationTypeInfo>>(); private static Dictionary<string, List<AnnotationTypeInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationTypeInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -76,21 +73,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 AnnotationType _Editable; protected AnnotationType _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _TypeID; private int _TypeID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int TypeID public int TypeID
@@ -186,32 +170,19 @@ namespace VEPROMS.CSLA.Library
foreach (AnnotationTypeInfo tmp in _CacheByPrimaryKey[_TypeID.ToString()]) foreach (AnnotationTypeInfo tmp in _CacheByPrimaryKey[_TypeID.ToString()])
tmp._AnnotationTypeAnnotationCount = -1; // This will cause the data to be requeried tmp._AnnotationTypeAnnotationCount = -1; // This will cause the data to be requeried
} }
// CSLATODO: Replace base AnnotationTypeInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationTypeInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AnnotationTypeInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AnnotationTypeInfo.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 AnnotationTypeInfo</returns> /// <returns>A Unique ID for the current AnnotationTypeInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAnnotationTypeInfoUnique; // Absolutely Unique ID
{
return MyAnnotationTypeInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _AnnotationTypeInfoUnique = 0; private static int _AnnotationTypeInfoUnique = 0;
private static int AnnotationTypeInfoUnique private static int AnnotationTypeInfoUnique => ++_AnnotationTypeInfoUnique;
{ get { return ++_AnnotationTypeInfoUnique; } } private readonly int _MyAnnotationTypeInfoUnique = AnnotationTypeInfoUnique;
private int _MyAnnotationTypeInfoUnique = AnnotationTypeInfoUnique; // Absolutely Unique ID - Info
public int MyAnnotationTypeInfoUnique // Absolutely Unique ID - Info public int MyAnnotationTypeInfoUnique => _MyAnnotationTypeInfoUnique;
{ get { return _MyAnnotationTypeInfoUnique; } }
protected AnnotationTypeInfo() protected AnnotationTypeInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -220,15 +191,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; } }
~AnnotationTypeInfo() ~AnnotationTypeInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -245,10 +212,7 @@ namespace VEPROMS.CSLA.Library
if (listAnnotationTypeInfo.Count == 0) // If there are no items left in the list if (listAnnotationTypeInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list _CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list
} }
public virtual AnnotationType Get() public virtual AnnotationType Get() => _Editable = AnnotationType.Get(_TypeID);
{
return _Editable = AnnotationType.Get(_TypeID);
}
public static void Refresh(AnnotationType tmp) public static void Refresh(AnnotationType tmp)
{ {
string key = tmp.TypeID.ToString(); string key = tmp.TypeID.ToString();
@@ -268,8 +232,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AnnotationTypeInfo Get(int typeID) public static AnnotationTypeInfo Get(int typeID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
try try
{ {
AnnotationTypeInfo tmp = GetCachedByPrimaryKey(typeID); AnnotationTypeInfo tmp = GetCachedByPrimaryKey(typeID);
@@ -308,13 +270,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _TypeID; private readonly int _TypeID;
public int TypeID public int TypeID => _TypeID;
{ get { return _TypeID; } } public PKCriteria(int typeID) => _TypeID = typeID;
public PKCriteria(int typeID)
{
_TypeID = typeID;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -376,7 +334,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
AnnotationTypeInfoExtension _AnnotationTypeInfoExtension = new AnnotationTypeInfoExtension(); readonly AnnotationTypeInfoExtension _AnnotationTypeInfoExtension = new AnnotationTypeInfoExtension();
[Serializable()] [Serializable()]
partial class AnnotationTypeInfoExtension : extensionBase { } partial class AnnotationTypeInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -392,10 +350,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 AnnotationTypeInfo) if (destType == typeof(string) && value is AnnotationTypeInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((AnnotationTypeInfo)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
@@ -27,18 +25,13 @@ namespace VEPROMS.CSLA.Library
[TypeConverter(typeof(AnnotationTypeInfoListConverter))] [TypeConverter(typeof(AnnotationTypeInfoListConverter))]
public partial class AnnotationTypeInfoList : ReadOnlyListBase<AnnotationTypeInfoList, AnnotationTypeInfo>, ICustomTypeDescriptor, IDisposable public partial class AnnotationTypeInfoList : ReadOnlyListBase<AnnotationTypeInfoList, AnnotationTypeInfo>, ICustomTypeDescriptor, IDisposable
{ {
public static event AnnotationTypeInfoListEvent ListChanged; public new static event AnnotationTypeInfoListEvent ListChanged;
private static void OnListChanged() private static void OnListChanged() => ListChanged?.Invoke();
{
if (ListChanged != null)
ListChanged();
}
#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<AnnotationTypeInfo> Items internal new IList<AnnotationTypeInfo> Items => base.Items;
{ get { return base.Items; } }
public void AddEvents() public void AddEvents()
{ {
foreach (AnnotationTypeInfo tmp in this) foreach (AnnotationTypeInfo tmp in this)
@@ -58,15 +51,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; } }
~AnnotationTypeInfoList() ~AnnotationTypeInfoList()
{ {
_CountFinalized++; _CountFinalized++;
@@ -108,22 +97,7 @@ namespace VEPROMS.CSLA.Library
/// <summary> /// <summary>
/// Reset the list of all AnnotationTypeInfo. /// Reset the list of all AnnotationTypeInfo.
/// </summary> /// </summary>
public static void Reset() public static void Reset() => _AnnotationTypeInfoList = null;
{
_AnnotationTypeInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static AnnotationTypeInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<AnnotationTypeInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on AnnotationTypeInfoList.Get", ex);
// }
//}
private AnnotationTypeInfoList() private AnnotationTypeInfoList()
{ /* require use of factory methods */ } { /* require use of factory methods */ }
#endregion #endregion
@@ -159,34 +133,23 @@ namespace VEPROMS.CSLA.Library
} }
#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>
@@ -213,7 +176,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class AnnotationTypeInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class AnnotationTypeInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private AnnotationTypeInfo Item { get { return (AnnotationTypeInfo)_Item; } }
public AnnotationTypeInfoListPropertyDescriptor(AnnotationTypeInfoList collection, int index) : base(collection, index) { ;} public AnnotationTypeInfoListPropertyDescriptor(AnnotationTypeInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -222,10 +184,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 AnnotationTypeInfoList) if (destType == typeof(string) && value is AnnotationTypeInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((AnnotationTypeInfoList)value).Items.Count.ToString() + " AnnotationTypes"; return list.Items.Count.ToString() + " AnnotationTypes";
} }
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;
using Csla.Validation; using Csla.Validation;
@@ -59,6 +57,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<Assignment> _CacheList = new List<Assignment>(); private static List<Assignment> _CacheList = new List<Assignment>();
protected static void AddToCache(Assignment assignment) protected static void AddToCache(Assignment assignment)
{ {
@@ -68,6 +67,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Assignment>> _CacheByPrimaryKey = new Dictionary<string, List<Assignment>>(); private static Dictionary<string, List<Assignment>> _CacheByPrimaryKey = new Dictionary<string, List<Assignment>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -93,15 +93,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 _nextAID = -1; private static int _nextAID = -1;
public static int NextAID public static int NextAID => _nextAID--;
{
get { return _nextAID--; }
}
private int _AID; private int _AID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AID public int AID
@@ -310,37 +304,14 @@ 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 || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)) || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyRole == null ? false : _MyRole.IsDirtyList(list)); return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list)) || (_MyGroup != null && _MyGroup.IsDirtyList(list)) || (_MyRole != null && _MyRole.IsDirtyList(list));
} }
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
if(list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyRole == null ? true : _MyRole.IsValidList(list));
}
// CSLATODO: Replace base Assignment.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Assignment</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Assignment.GetIdValue to assure that the ID returned is unique // CSLATODO: Check Assignment.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 Assignment</returns> /// <returns>A Unique ID for the current Assignment</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAssignmentUnique; // Absolutely Unique ID
{
return MyAssignmentUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -371,8 +342,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()
@@ -389,15 +360,10 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule( ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength, Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100));
//ValidationRules.AddDependantProperty("x", "y");
_AssignmentExtension.AddValidationRules(ValidationRules); _AssignmentExtension.AddValidationRules(ValidationRules);
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
protected override void AddInstanceBusinessRules() protected override void AddInstanceBusinessRules() => _AssignmentExtension.AddInstanceValidationRules(ValidationRules);
{
_AssignmentExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e) private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e)
{ {
try try
@@ -451,80 +417,14 @@ 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
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AID, "<Role(s)>");
//AuthorizationRules.AllowRead(GID, "<Role(s)>");
//AuthorizationRules.AllowRead(RID, "<Role(s)>");
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(GID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_AssignmentExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_AssignmentExtension.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 _AssignmentUnique = 0; private static int _AssignmentUnique = 0;
protected static int AssignmentUnique protected static int AssignmentUnique => ++_AssignmentUnique;
{ get { return ++_AssignmentUnique; } } private readonly int _MyAssignmentUnique = AssignmentUnique;
private int _MyAssignmentUnique = AssignmentUnique; // Absolutely Unique ID - Editable
public int MyAssignmentUnique // Absolutely Unique ID - Editable public int MyAssignmentUnique => _MyAssignmentUnique;
{ get { return _MyAssignmentUnique; } }
protected Assignment() protected Assignment()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -533,15 +433,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; } }
~Assignment() ~Assignment()
{ {
_CountFinalized++; _CountFinalized++;
@@ -566,8 +462,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Assignment New() public static Assignment New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Assignment");
try try
{ {
return DataPortal.Create<Assignment>(); return DataPortal.Create<Assignment>();
@@ -640,8 +534,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Assignment Get(int aid) public static Assignment Get(int aid)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Assignment");
try try
{ {
Assignment tmp = GetCachedByPrimaryKey(aid); Assignment tmp = GetCachedByPrimaryKey(aid);
@@ -667,14 +559,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Assignment(dr); if (dr.Read()) return new Assignment(dr);
return null; return null;
} }
internal Assignment(SafeDataReader dr) internal Assignment(SafeDataReader dr) => ReadData(dr);
{
ReadData(dr);
}
public static void Delete(int aid) public static void Delete(int aid)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Assignment");
try try
{ {
DataPortal.Delete(new PKCriteria(aid)); DataPortal.Delete(new PKCriteria(aid));
@@ -686,12 +573,6 @@ namespace VEPROMS.CSLA.Library
} }
public override Assignment Save() public override Assignment Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Assignment");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Assignment");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Assignment");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -711,13 +592,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _AID; private readonly int _AID;
public int AID public int AID => _AID;
{ get { return _AID; } } public PKCriteria(int aid) => _AID = aid;
public PKCriteria(int aid)
{
_AID = aid;
}
} }
// 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()]
@@ -818,13 +695,14 @@ 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 (_MyFolder != null) _MyFolder.Update(); _MyFolder?.Update();
if (_MyGroup != null) _MyGroup.Update(); _MyGroup?.Update();
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()) using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; cm.CommandType = CommandType.StoredProcedure;
@@ -839,11 +717,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_AID = new SqlParameter("@newAID", SqlDbType.Int); SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int)
param_AID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AID); cm.Parameters.Add(param_AID);
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();
@@ -851,6 +733,8 @@ namespace VEPROMS.CSLA.Library
_AID = (int)cm.Parameters["@newAID"].Value; _AID = (int)cm.Parameters["@newAID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
}
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLInsert", GetHashCode());
@@ -882,11 +766,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_AID = new SqlParameter("@newAID", SqlDbType.Int); SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int)
param_AID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AID); cm.Parameters.Add(param_AID);
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();
@@ -931,10 +819,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLUpdate", GetHashCode());
try try
{ {
if (_MyFolder != null) _MyFolder.Update(); _MyFolder?.Update();
if (_MyGroup != null) _MyGroup.Update(); _MyGroup?.Update();
if (_MyRole != null) _MyRole.Update(); _MyRole?.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty) if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
@@ -953,8 +842,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();
@@ -962,6 +853,8 @@ namespace VEPROMS.CSLA.Library
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
} }
}
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
} }
@@ -974,14 +867,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) if (IsNew)
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID); _LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
else else
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); _LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
} }
@@ -1007,8 +903,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();
@@ -1023,10 +921,7 @@ namespace VEPROMS.CSLA.Library
} }
} }
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AID));
{
DataPortal_Delete(new PKCriteria(_AID));
}
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria) private void DataPortal_Delete(PKCriteria criteria)
{ {
@@ -1093,16 +988,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private int _AID; private readonly int _AID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(int aid) => _AID = aid;
get { return _exists; }
}
public ExistsCommand(int aid)
{
_AID = aid;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Execute", GetHashCode());
@@ -1132,7 +1021,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
AssignmentExtension _AssignmentExtension = new AssignmentExtension(); readonly AssignmentExtension _AssignmentExtension = new AssignmentExtension();
[Serializable()] [Serializable()]
partial class AssignmentExtension : extensionBase partial class AssignmentExtension : extensionBase
{ {
@@ -1141,18 +1030,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)
{ {
@@ -1181,61 +1061,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 Assignment) if (destType == typeof(string) && value is Assignment assignmnt)
{ {
// Return the ToString value // Return the ToString value
return ((Assignment)value).ToString(); return assignmnt.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 AssignmentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Assignment
// {
// partial class AssignmentExtension : 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 AssignmentInfo : ReadOnlyBase<AssignmentInfo>, IDisposable public partial class AssignmentInfo : ReadOnlyBase<AssignmentInfo>, IDisposable
{ {
public event AssignmentInfoEvent Changed; public event AssignmentInfoEvent 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<AssignmentInfo> _CacheList = new List<AssignmentInfo>(); private static List<AssignmentInfo> _CacheList = new List<AssignmentInfo>();
protected static void AddToCache(AssignmentInfo assignmentInfo) protected static void AddToCache(AssignmentInfo assignmentInfo)
{ {
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AssignmentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AssignmentInfo>>(); private static Dictionary<string, List<AssignmentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AssignmentInfo>>();
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 Assignment _Editable; protected Assignment _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _AID; private int _AID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AID public int AID
@@ -195,15 +179,6 @@ namespace VEPROMS.CSLA.Library
return _UsrID; return _UsrID;
} }
} }
// CSLATODO: Replace base AssignmentInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AssignmentInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AssignmentInfo.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
@@ -216,11 +191,10 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _AssignmentInfoUnique = 0; private static int _AssignmentInfoUnique = 0;
private static int AssignmentInfoUnique private static int AssignmentInfoUnique => ++_AssignmentInfoUnique;
{ get { return ++_AssignmentInfoUnique; } } private readonly int _MyAssignmentInfoUnique = AssignmentInfoUnique;
private int _MyAssignmentInfoUnique = AssignmentInfoUnique; // Absolutely Unique ID - Info
public int MyAssignmentInfoUnique // Absolutely Unique ID - Info public int MyAssignmentInfoUnique => _MyAssignmentInfoUnique;
{ get { return _MyAssignmentInfoUnique; } }
protected AssignmentInfo() protected AssignmentInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -229,15 +203,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; } }
~AssignmentInfo() ~AssignmentInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -254,10 +224,7 @@ namespace VEPROMS.CSLA.Library
if (listAssignmentInfo.Count == 0) // If there are no items left in the list if (listAssignmentInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AID.ToString()); // remove the list _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list
} }
public virtual Assignment Get() public virtual Assignment Get() => _Editable = Assignment.Get(_AID);
{
return _Editable = Assignment.Get(_AID);
}
public static void Refresh(Assignment tmp) public static void Refresh(Assignment tmp)
{ {
string key = tmp.AID.ToString(); string key = tmp.AID.ToString();
@@ -270,25 +237,25 @@ namespace VEPROMS.CSLA.Library
{ {
if (_GID != tmp.GID) if (_GID != tmp.GID)
{ {
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value MyGroup?.RefreshGroupAssignments(); // 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.RefreshGroupAssignments(); // Update List for new value MyGroup?.RefreshGroupAssignments(); // Update List for new value
if (_RID != tmp.RID) if (_RID != tmp.RID)
{ {
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value MyRole?.RefreshRoleAssignments(); // 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.RefreshRoleAssignments(); // Update List for new value MyRole?.RefreshRoleAssignments(); // Update List for new value
if (_FolderID != tmp.FolderID) if (_FolderID != tmp.FolderID)
{ {
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value MyFolder?.RefreshFolderAssignments(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value _FolderID = tmp.FolderID; // Update the value
} }
_MyFolder = null; // Reset list so that the next line gets a new list _MyFolder = null; // Reset list so that the next line gets a new list
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for new value MyFolder?.RefreshFolderAssignments(); // Update List for new value
_StartDate = tmp.StartDate; _StartDate = tmp.StartDate;
_EndDate = tmp.EndDate; _EndDate = tmp.EndDate;
_DTS = tmp.DTS; _DTS = tmp.DTS;
@@ -308,18 +275,18 @@ namespace VEPROMS.CSLA.Library
{ {
if (_GID != tmp.GID) if (_GID != tmp.GID)
{ {
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value MyGroup?.RefreshGroupAssignments(); // 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.RefreshGroupAssignments(); // Update List for new value MyGroup?.RefreshGroupAssignments(); // Update List for new value
if (_RID != tmp.RID) if (_RID != tmp.RID)
{ {
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value MyRole?.RefreshRoleAssignments(); // 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.RefreshRoleAssignments(); // Update List for new value MyRole?.RefreshRoleAssignments(); // Update List for new value
_StartDate = tmp.StartDate; _StartDate = tmp.StartDate;
_EndDate = tmp.EndDate; _EndDate = tmp.EndDate;
_DTS = tmp.DTS; _DTS = tmp.DTS;
@@ -339,18 +306,18 @@ namespace VEPROMS.CSLA.Library
{ {
if (_RID != tmp.RID) if (_RID != tmp.RID)
{ {
if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value MyRole?.RefreshRoleAssignments(); // 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.RefreshRoleAssignments(); // Update List for new value MyRole?.RefreshRoleAssignments(); // Update List for new value
if (_FolderID != tmp.FolderID) if (_FolderID != tmp.FolderID)
{ {
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value MyFolder?.RefreshFolderAssignments(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value _FolderID = tmp.FolderID; // Update the value
} }
_MyFolder = null; // Reset list so that the next line gets a new list _MyFolder = null; // Reset list so that the next line gets a new list
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for new value MyFolder?.RefreshFolderAssignments(); // Update List for new value
_StartDate = tmp.StartDate; _StartDate = tmp.StartDate;
_EndDate = tmp.EndDate; _EndDate = tmp.EndDate;
_DTS = tmp.DTS; _DTS = tmp.DTS;
@@ -370,18 +337,18 @@ namespace VEPROMS.CSLA.Library
{ {
if (_GID != tmp.GID) if (_GID != tmp.GID)
{ {
if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value MyGroup?.RefreshGroupAssignments(); // 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.RefreshGroupAssignments(); // Update List for new value MyGroup?.RefreshGroupAssignments(); // Update List for new value
if (_FolderID != tmp.FolderID) if (_FolderID != tmp.FolderID)
{ {
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for old value MyFolder?.RefreshFolderAssignments(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value _FolderID = tmp.FolderID; // Update the value
} }
_MyFolder = null; // Reset list so that the next line gets a new list _MyFolder = null; // Reset list so that the next line gets a new list
if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // Update List for new value MyFolder?.RefreshFolderAssignments(); // Update List for new value
_StartDate = tmp.StartDate; _StartDate = tmp.StartDate;
_EndDate = tmp.EndDate; _EndDate = tmp.EndDate;
_DTS = tmp.DTS; _DTS = tmp.DTS;
@@ -391,8 +358,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AssignmentInfo Get(int aid) public static AssignmentInfo Get(int aid)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Assignment");
try try
{ {
AssignmentInfo tmp = GetCachedByPrimaryKey(aid); AssignmentInfo tmp = GetCachedByPrimaryKey(aid);
@@ -431,13 +396,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _AID; private readonly int _AID;
public int AID public int AID => _AID;
{ get { return _AID; } } public PKCriteria(int aid) => _AID = aid;
public PKCriteria(int aid)
{
_AID = aid;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -499,7 +460,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
AssignmentInfoExtension _AssignmentInfoExtension = new AssignmentInfoExtension(); readonly AssignmentInfoExtension _AssignmentInfoExtension = new AssignmentInfoExtension();
[Serializable()] [Serializable()]
partial class AssignmentInfoExtension : extensionBase { } partial class AssignmentInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -515,10 +476,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 AssignmentInfo) if (destType == typeof(string) && value is AssignmentInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((AssignmentInfo)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<AssignmentInfo> Items internal new IList<AssignmentInfo> Items => base.Items;
{ get { return base.Items; } }
public void AddEvents() public void AddEvents()
{ {
foreach (AssignmentInfo tmp in this) foreach (AssignmentInfo tmp in this)
@@ -51,15 +48,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; } }
~AssignmentInfoList() ~AssignmentInfoList()
{ {
_CountFinalized++; _CountFinalized++;
@@ -97,25 +90,6 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AssignmentInfoList.Get", ex); throw new DbCslaException("Error on AssignmentInfoList.Get", ex);
} }
} }
/// <summary>
/// Reset the list of all AssignmentInfo.
/// </summary>
public static void Reset()
{
_AssignmentInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static AssignmentInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<AssignmentInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on AssignmentInfoList.Get", ex);
// }
//}
public static AssignmentInfoList GetByFolderID(int folderID) public static AssignmentInfoList GetByFolderID(int folderID)
{ {
try try
@@ -194,10 +168,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class FolderIDCriteria private class FolderIDCriteria
{ {
public FolderIDCriteria(int folderID) public FolderIDCriteria(int folderID) => _FolderID = folderID;
{
_FolderID = folderID;
}
private int _FolderID; private int _FolderID;
public int FolderID public int FolderID
{ {
@@ -238,10 +209,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class GIDCriteria private class GIDCriteria
{ {
public GIDCriteria(int gid) public GIDCriteria(int gid) => _GID = gid;
{
_GID = gid;
}
private int _GID; private int _GID;
public int GID public int GID
{ {
@@ -282,10 +250,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class RIDCriteria private class RIDCriteria
{ {
public RIDCriteria(int rid) public RIDCriteria(int rid) => _RID = rid;
{
_RID = rid;
}
private int _RID; private int _RID;
public int RID public int RID
{ {
@@ -325,34 +290,23 @@ namespace VEPROMS.CSLA.Library
} }
#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>
@@ -379,7 +333,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class AssignmentInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class AssignmentInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private AssignmentInfo Item { get { return (AssignmentInfo)_Item; } }
public AssignmentInfoListPropertyDescriptor(AssignmentInfoList collection, int index) : base(collection, index) { ;} public AssignmentInfoListPropertyDescriptor(AssignmentInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -388,10 +341,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 AssignmentInfoList) if (destType == typeof(string) && value is AssignmentInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((AssignmentInfoList)value).Items.Count.ToString() + " Assignments"; return $"{list.Items.Count} Assignments";
} }
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;
using Csla.Validation; using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty) if (IsDirty)
refreshAssociations.Add(this); refreshAssociations.Add(this);
} }
private void ClearRefreshList() private void ClearRefreshList() => _RefreshAssociations = new List<Association>();
{
_RefreshAssociations = new List<Association>();
}
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<Association> _CacheList = new List<Association>(); private static List<Association> _CacheList = new List<Association>();
protected static void AddToCache(Association association) protected static void AddToCache(Association association)
{ {
@@ -67,7 +63,9 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(association)) _CacheList.Remove(association); // In RemoveFromCache while (_CacheList.Contains(association)) _CacheList.Remove(association); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Association>> _CacheByPrimaryKey = new Dictionary<string, List<Association>>(); private static Dictionary<string, List<Association>> _CacheByPrimaryKey = new Dictionary<string, List<Association>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Association>> _CacheByVersionID_ROFstID = new Dictionary<string, List<Association>>(); private static Dictionary<string, List<Association>> _CacheByVersionID_ROFstID = new Dictionary<string, List<Association>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -102,15 +100,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 _nextAssociationID = -1; private static int _nextAssociationID = -1;
public static int NextAssociationID public static int NextAssociationID => _nextAssociationID--;
{
get { return _nextAssociationID--; }
}
private int _AssociationID; private int _AssociationID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AssociationID public int AssociationID
@@ -254,37 +246,14 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirtyList(list)) || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list)); return base.IsDirty || (_MyDocVersion != null && _MyDocVersion.IsDirtyList(list)) || (_MyROFst != null && _MyROFst.IsDirtyList(list));
} }
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValidList(list)) && (_MyROFst == null ? true : _MyROFst.IsValidList(list));
}
// CSLATODO: Replace base Association.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Association</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Association.GetIdValue to assure that the ID returned is unique // CSLATODO: Check Association.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 Association</returns> /// <returns>A Unique ID for the current Association</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAssociationUnique; // Absolutely Unique ID
{
return MyAssociationUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -314,8 +283,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()
@@ -330,15 +299,10 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule( ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength, Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
//ValidationRules.AddDependantProperty("x", "y");
_AssociationExtension.AddValidationRules(ValidationRules); _AssociationExtension.AddValidationRules(ValidationRules);
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
protected override void AddInstanceBusinessRules() protected override void AddInstanceBusinessRules() => _AssociationExtension.AddInstanceValidationRules(ValidationRules);
{
_AssociationExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
private static bool MyDocVersionRequired(Association target, Csla.Validation.RuleArgs e) private static bool MyDocVersionRequired(Association target, Csla.Validation.RuleArgs e)
{ {
if (target._VersionID == 0 && target._MyDocVersion == null) // Required field missing if (target._VersionID == 0 && target._MyDocVersion == null) // Required field missing
@@ -357,76 +321,14 @@ 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
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AssociationID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_AssociationExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
_AssociationExtension.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 _AssociationUnique = 0; private static int _AssociationUnique = 0;
protected static int AssociationUnique protected static int AssociationUnique => ++_AssociationUnique;
{ get { return ++_AssociationUnique; } } private readonly int _MyAssociationUnique = AssociationUnique;
private int _MyAssociationUnique = AssociationUnique; // Absolutely Unique ID - Editable
public int MyAssociationUnique // Absolutely Unique ID - Editable public int MyAssociationUnique => _MyAssociationUnique;
{ get { return _MyAssociationUnique; } }
protected Association() protected Association()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -435,15 +337,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; } }
~Association() ~Association()
{ {
_CountFinalized++; _CountFinalized++;
@@ -480,8 +378,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Association New() public static Association New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Association");
try try
{ {
return DataPortal.Create<Association>(); return DataPortal.Create<Association>();
@@ -519,7 +415,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;
@@ -550,8 +446,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Association Get(int associationID) public static Association Get(int associationID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Association");
try try
{ {
Association tmp = GetCachedByPrimaryKey(associationID); Association tmp = GetCachedByPrimaryKey(associationID);
@@ -574,8 +468,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Association GetByVersionID_ROFstID(int versionID, int rOFstID) public static Association GetByVersionID_ROFstID(int versionID, int rOFstID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Association");
try try
{ {
Association tmp = GetCachedByVersionID_ROFstID(versionID, rOFstID); Association tmp = GetCachedByVersionID_ROFstID(versionID, rOFstID);
@@ -601,14 +493,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Association(dr); if (dr.Read()) return new Association(dr);
return null; return null;
} }
internal Association(SafeDataReader dr) internal Association(SafeDataReader dr) => ReadData(dr);
{
ReadData(dr);
}
public static void Delete(int associationID) public static void Delete(int associationID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Association");
try try
{ {
DataPortal.Delete(new PKCriteria(associationID)); DataPortal.Delete(new PKCriteria(associationID));
@@ -620,12 +507,6 @@ namespace VEPROMS.CSLA.Library
} }
public override Association Save() public override Association Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Association");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Association");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Association");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -645,23 +526,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _AssociationID; private readonly int _AssociationID;
public int AssociationID public int AssociationID => _AssociationID;
{ get { return _AssociationID; } } public PKCriteria(int associationID) => _AssociationID = associationID;
public PKCriteria(int associationID)
{
_AssociationID = associationID;
}
} }
[Serializable()] [Serializable()]
private class VersionID_ROFstIDCriteria private class VersionID_ROFstIDCriteria
{ {
private int _VersionID; private readonly int _VersionID;
public int VersionID public int VersionID => _VersionID;
{ get { return _VersionID; } } private readonly int _ROFstID;
private int _ROFstID; public int ROFstID => _ROFstID;
public int ROFstID
{ get { return _ROFstID; } }
public VersionID_ROFstIDCriteria(int versionID, int rOFstID) public VersionID_ROFstIDCriteria(int versionID, int rOFstID)
{ {
_VersionID = versionID; _VersionID = versionID;
@@ -801,12 +676,13 @@ 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 (_MyDocVersion != null) _MyDocVersion.Update(); _MyDocVersion?.Update();
if (_MyROFst != null) _MyROFst.Update(); _MyROFst?.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; cm.CommandType = CommandType.StoredProcedure;
@@ -819,11 +695,15 @@ namespace VEPROMS.CSLA.Library
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int); SqlParameter param_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int)
param_AssociationID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AssociationID); cm.Parameters.Add(param_AssociationID);
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();
@@ -831,6 +711,8 @@ namespace VEPROMS.CSLA.Library
_AssociationID = (int)cm.Parameters["@newAssociationID"].Value; _AssociationID = (int)cm.Parameters["@newAssociationID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
}
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.SQLInsert", GetHashCode());
@@ -860,11 +742,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int); SqlParameter param_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int)
param_AssociationID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AssociationID); cm.Parameters.Add(param_AssociationID);
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,9 +795,10 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.SQLUpdate", GetHashCode());
try try
{ {
if (_MyDocVersion != null) _MyDocVersion.Update(); _MyDocVersion?.Update();
if (_MyROFst != null) _MyROFst.Update(); _MyROFst?.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty) if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
@@ -928,8 +815,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();
@@ -937,6 +826,8 @@ namespace VEPROMS.CSLA.Library
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
} }
} }
}
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
} }
@@ -949,14 +840,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) if (IsNew)
_LastChanged = Association.Add(cn, ref _AssociationID, _MyDocVersion, _MyROFst, _Config, _DTS, _UserID); _LastChanged = Association.Add(cn, ref _AssociationID, _MyDocVersion, _MyROFst, _Config, _DTS, _UserID);
else else
_LastChanged = Association.Update(cn, ref _AssociationID, _VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged); _LastChanged = Association.Update(cn, ref _AssociationID, _VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
} }
@@ -980,8 +874,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();
@@ -996,10 +892,7 @@ namespace VEPROMS.CSLA.Library
} }
} }
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AssociationID));
{
DataPortal_Delete(new PKCriteria(_AssociationID));
}
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria) private void DataPortal_Delete(PKCriteria criteria)
{ {
@@ -1066,16 +959,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private int _AssociationID; private readonly int _AssociationID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(int associationID) => _AssociationID = associationID;
get { return _exists; }
}
public ExistsCommand(int associationID)
{
_AssociationID = associationID;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Execute", GetHashCode());
@@ -1105,7 +992,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
AssociationExtension _AssociationExtension = new AssociationExtension(); readonly AssociationExtension _AssociationExtension = new AssociationExtension();
[Serializable()] [Serializable()]
partial class AssociationExtension : extensionBase partial class AssociationExtension : extensionBase
{ {
@@ -1114,14 +1001,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)
{ {
@@ -1150,10 +1031,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 Association) if (destType == typeof(string) && value is Association assn)
{ {
// Return the ToString value // Return the ToString value
return ((Association)value).ToString(); return assn.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -1161,46 +1042,3 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create AssociationExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Association
// {
// partial class AssociationExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class AssociationInfo : ReadOnlyBase<AssociationInfo>, IDisposable public partial class AssociationInfo : ReadOnlyBase<AssociationInfo>, IDisposable
{ {
public event AssociationInfoEvent Changed; public event AssociationInfoEvent 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<AssociationInfo> _CacheList = new List<AssociationInfo>(); private static List<AssociationInfo> _CacheList = new List<AssociationInfo>();
protected static void AddToCache(AssociationInfo associationInfo) protected static void AddToCache(AssociationInfo associationInfo)
{ {
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(associationInfo)) _CacheList.Remove(associationInfo); // In RemoveFromCache while (_CacheList.Contains(associationInfo)) _CacheList.Remove(associationInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<AssociationInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AssociationInfo>>(); private static Dictionary<string, List<AssociationInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AssociationInfo>>();
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 Association _Editable; protected Association _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _AssociationID; private int _AssociationID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AssociationID public int AssociationID
@@ -167,32 +151,19 @@ namespace VEPROMS.CSLA.Library
return _UserID; return _UserID;
} }
} }
// CSLATODO: Replace base AssociationInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AssociationInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check AssociationInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check AssociationInfo.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 AssociationInfo</returns> /// <returns>A Unique ID for the current AssociationInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyAssociationInfoUnique; // Absolutely Unique ID
{
return MyAssociationInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _AssociationInfoUnique = 0; private static int _AssociationInfoUnique = 0;
private static int AssociationInfoUnique private static int AssociationInfoUnique => ++_AssociationInfoUnique;
{ get { return ++_AssociationInfoUnique; } } private readonly int _MyAssociationInfoUnique = AssociationInfoUnique;
private int _MyAssociationInfoUnique = AssociationInfoUnique; // Absolutely Unique ID - Info
public int MyAssociationInfoUnique // Absolutely Unique ID - Info public int MyAssociationInfoUnique => _MyAssociationInfoUnique;
{ get { return _MyAssociationInfoUnique; } }
protected AssociationInfo() protected AssociationInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -201,15 +172,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; } }
~AssociationInfo() ~AssociationInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -226,10 +193,7 @@ namespace VEPROMS.CSLA.Library
if (listAssociationInfo.Count == 0) // If there are no items left in the list if (listAssociationInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AssociationID.ToString()); // remove the list _CacheByPrimaryKey.Remove(AssociationID.ToString()); // remove the list
} }
public virtual Association Get() public virtual Association Get() => _Editable = Association.Get(_AssociationID);
{
return _Editable = Association.Get(_AssociationID);
}
public static void Refresh(Association tmp) public static void Refresh(Association tmp)
{ {
string key = tmp.AssociationID.ToString(); string key = tmp.AssociationID.ToString();
@@ -242,18 +206,18 @@ namespace VEPROMS.CSLA.Library
{ {
if (_VersionID != tmp.VersionID) if (_VersionID != tmp.VersionID)
{ {
if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for old value MyDocVersion?.RefreshDocVersionAssociations(); // Update List for old value
_VersionID = tmp.VersionID; // Update the value _VersionID = tmp.VersionID; // Update the value
} }
_MyDocVersion = null; // Reset list so that the next line gets a new list _MyDocVersion = null; // Reset list so that the next line gets a new list
if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for new value MyDocVersion?.RefreshDocVersionAssociations(); // Update List for new value
if (_ROFstID != tmp.ROFstID) if (_ROFstID != tmp.ROFstID)
{ {
if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // Update List for old value MyROFst?.RefreshROFstAssociations(); // Update List for old value
_ROFstID = tmp.ROFstID; // Update the value _ROFstID = tmp.ROFstID; // Update the value
} }
_MyROFst = null; // Reset list so that the next line gets a new list _MyROFst = null; // Reset list so that the next line gets a new list
if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // Update List for new value MyROFst?.RefreshROFstAssociations(); // Update List for new value
_Config = tmp.Config; _Config = tmp.Config;
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
@@ -272,11 +236,11 @@ namespace VEPROMS.CSLA.Library
{ {
if (_ROFstID != tmp.ROFstID) if (_ROFstID != tmp.ROFstID)
{ {
if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // Update List for old value MyROFst?.RefreshROFstAssociations(); // Update List for old value
_ROFstID = tmp.ROFstID; // Update the value _ROFstID = tmp.ROFstID; // Update the value
} }
_MyROFst = null; // Reset list so that the next line gets a new list _MyROFst = null; // Reset list so that the next line gets a new list
if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // Update List for new value MyROFst?.RefreshROFstAssociations(); // Update List for new value
_Config = tmp.Config; _Config = tmp.Config;
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
@@ -295,11 +259,11 @@ namespace VEPROMS.CSLA.Library
{ {
if (_VersionID != tmp.VersionID) if (_VersionID != tmp.VersionID)
{ {
if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for old value MyDocVersion?.RefreshDocVersionAssociations(); // Update List for old value
_VersionID = tmp.VersionID; // Update the value _VersionID = tmp.VersionID; // Update the value
} }
_MyDocVersion = null; // Reset list so that the next line gets a new list _MyDocVersion = null; // Reset list so that the next line gets a new list
if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for new value MyDocVersion?.RefreshDocVersionAssociations(); // Update List for new value
_Config = tmp.Config; _Config = tmp.Config;
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
@@ -308,8 +272,6 @@ namespace VEPROMS.CSLA.Library
} }
public static AssociationInfo Get(int associationID) public static AssociationInfo Get(int associationID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Association");
try try
{ {
AssociationInfo tmp = GetCachedByPrimaryKey(associationID); AssociationInfo tmp = GetCachedByPrimaryKey(associationID);
@@ -348,13 +310,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _AssociationID; private readonly int _AssociationID;
public int AssociationID public int AssociationID => _AssociationID;
{ get { return _AssociationID; } } public PKCriteria(int associationID) => _AssociationID = associationID;
public PKCriteria(int associationID)
{
_AssociationID = associationID;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -414,7 +372,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
AssociationInfoExtension _AssociationInfoExtension = new AssociationInfoExtension(); readonly AssociationInfoExtension _AssociationInfoExtension = new AssociationInfoExtension();
[Serializable()] [Serializable()]
partial class AssociationInfoExtension : extensionBase { } partial class AssociationInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -430,10 +388,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 AssociationInfo) if (destType == typeof(string) && value is AssociationInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((AssociationInfo)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<AssociationInfo> Items internal new IList<AssociationInfo> Items => base.Items;
{ get { return base.Items; } }
public void AddEvents() public void AddEvents()
{ {
foreach (AssociationInfo tmp in this) foreach (AssociationInfo tmp in this)
@@ -51,15 +48,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; } }
~AssociationInfoList() ~AssociationInfoList()
{ {
_CountFinalized++; _CountFinalized++;
@@ -104,18 +97,7 @@ namespace VEPROMS.CSLA.Library
{ {
_AssociationInfoList = null; _AssociationInfoList = null;
} }
// CSLATODO: Add alternative gets -
//public static AssociationInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<AssociationInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on AssociationInfoList.Get", ex);
// }
//}
public static AssociationInfoList GetByVersionID(int versionID) public static AssociationInfoList GetByVersionID(int versionID)
{ {
try try
@@ -180,10 +162,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class VersionIDCriteria private class VersionIDCriteria
{ {
public VersionIDCriteria(int versionID) public VersionIDCriteria(int versionID) => _VersionID = versionID;
{
_VersionID = versionID;
}
private int _VersionID; private int _VersionID;
public int VersionID public int VersionID
{ {
@@ -224,10 +203,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ROFstIDCriteria private class ROFstIDCriteria
{ {
public ROFstIDCriteria(int rOFstID) public ROFstIDCriteria(int rOFstID) => _ROFstID = rOFstID;
{
_ROFstID = rOFstID;
}
private int _ROFstID; private int _ROFstID;
public int ROFstID public int ROFstID
{ {
@@ -267,34 +243,24 @@ namespace VEPROMS.CSLA.Library
} }
#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 EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes) public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); } { return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetEvents(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
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>
@@ -321,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class AssociationInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class AssociationInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private AssociationInfo Item { get { return (AssociationInfo)_Item; } }
public AssociationInfoListPropertyDescriptor(AssociationInfoList collection, int index) : base(collection, index) { ;} public AssociationInfoListPropertyDescriptor(AssociationInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -330,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 AssociationInfoList) if (destType == typeof(string) && value is AssociationInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((AssociationInfoList)value).Items.Count.ToString() + " Associations"; return $"{list.Items.Count} Associations";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }