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