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
+193 -346
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,11 +35,8 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshAnnotations.Add(this);
}
private void ClearRefreshList()
{
_RefreshAnnotations = new List<Annotation>();
}
private void BuildRefreshList()
private void ClearRefreshList() => _RefreshAnnotations = new List<Annotation>();
private void BuildRefreshList()
{
ClearRefreshList();
AddToRefreshList(_RefreshAnnotations);
@@ -56,9 +51,10 @@ namespace VEPROMS.CSLA.Library
}
ClearRefreshList();
}
#endregion
#region Collection
private static List<Annotation> _CacheList = new List<Annotation>();
#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)
{
if (!_CacheList.Contains(annotation)) _CacheList.Add(annotation); // In AddToCache
@@ -67,7 +63,8 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(annotation)) _CacheList.Remove(annotation); // In RemoveFromCache
}
private static Dictionary<string, List<Annotation>> _CacheByPrimaryKey = new Dictionary<string, List<Annotation>>();
[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()
{
while (_CacheList.Count > 0) // Move Annotation(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -92,16 +89,10 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private static int _nextAnnotationID = -1;
public static int NextAnnotationID
{
get { return _nextAnnotationID--; }
}
private int _AnnotationID;
public string ErrorMessage => _ErrorMessage;
private static int _nextAnnotationID = -1;
public static int NextAnnotationID => _nextAnnotationID--;
private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID
{
@@ -280,40 +271,25 @@ 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));
return base.IsDirty || (_MyAnnotationType != null && _MyAnnotationType.IsDirtyList(list)) || (_MyItem != null && _MyItem.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> 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
}
#endregion
#region ValidationRules
[NonSerialized]
// 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() => MyAnnotationUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
@@ -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,16 +338,10 @@ 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
}
private static bool MyItemRequired(Annotation target, Csla.Validation.RuleArgs e)
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,98 +359,26 @@ 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; } }
~Annotation()
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);
@@ -599,37 +493,29 @@ namespace VEPROMS.CSLA.Library
{
throw new DbCslaException("Error on Annotation.Get", ex);
}
}
public static Annotation Get(SafeDataReader dr)
{
if (dr.Read()) return new Annotation(dr);
return null;
}
internal Annotation(SafeDataReader dr)
{
ReadData(dr);
}
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));
}
catch (Exception ex)
{
throw new DbCslaException("Error on Annotation.Delete", ex);
}
}
}
public static Annotation Get(SafeDataReader dr)
{
if (dr.Read()) return new Annotation(dr);
return null;
}
internal Annotation(SafeDataReader dr)
{
ReadData(dr);
}
public static void Delete(int annotationID)
{
try
{
DataPortal.Delete(new PKCriteria(annotationID));
}
catch (Exception ex)
{
throw new DbCslaException("Error on Annotation.Delete", ex);
}
}
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,14 +536,10 @@ 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()]
private new void DataPortal_Create()
@@ -756,43 +638,50 @@ 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"];
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAnnotation";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@TypeID", TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
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;
cm.Parameters.Add(param_AnnotationID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_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());
}
catch (Exception ex)
{
_MyAnnotationType?.Update();
_MyItem?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAnnotation";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@TypeID", TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
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)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AnnotationID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_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());
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLInsert", ex);
_ErrorMessage = ex.Message;
@@ -818,13 +707,17 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@Config", config);
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;
cm.Parameters.Add(param_AnnotationID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// Output Calculated Columns
SqlParameter param_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AnnotationID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -867,41 +760,46 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return; // If not dirty - nothing to do
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"];
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAnnotation";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID);
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@TypeID", TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// use the open connection to update child objects
}
catch (Exception ex)
{
_MyAnnotationType?.Update();
_MyItem?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAnnotation";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID);
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@TypeID", TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLUpdate", ex);
_ErrorMessage = ex.Message;
@@ -910,17 +808,20 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = 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();
}
}
{
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();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
@@ -942,10 +843,12 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -1029,17 +932,11 @@ 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;
}
protected override void DataPortal_Execute()
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());
try
@@ -1065,10 +962,10 @@ namespace VEPROMS.CSLA.Library
}
}
}
#endregion
// Standard Default Code
#region extension
AnnotationExtension _AnnotationExtension = new AnnotationExtension();
#endregion
// Standard Default Code
#region extension
readonly AnnotationExtension _AnnotationExtension = new AnnotationExtension();
[Serializable()]
partial class AnnotationExtension : extensionBase
{
@@ -1076,17 +973,11 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// Default Values
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)
{
// Needs to be overriden to add new authorization 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;
@@ -54,9 +52,10 @@ namespace VEPROMS.CSLA.Library
}
ClearRefreshList();
}
#endregion
#region Collection
private static List<AnnotationAudit> _CacheList = new List<AnnotationAudit>();
#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)
{
if (!_CacheList.Contains(annotationAudit)) _CacheList.Add(annotationAudit); // In AddToCache
@@ -65,7 +64,8 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(annotationAudit)) _CacheList.Remove(annotationAudit); // In RemoveFromCache
}
private static Dictionary<string, List<AnnotationAudit>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationAudit>>();
[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()
{
while (_CacheList.Count > 0) // Move AnnotationAudit(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -90,16 +90,10 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
private long _AuditID;
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
{
@@ -275,43 +269,18 @@ 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();
//}
// 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
}
#endregion
#region ValidationRules
[NonSerialized]
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() => MyAnnotationAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
@@ -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,16 +342,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationAudit()
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);
@@ -559,20 +442,15 @@ namespace VEPROMS.CSLA.Library
{
throw new DbCslaException("Error on AnnotationAudit.Get", ex);
}
}
public static AnnotationAudit Get(SafeDataReader dr)
}
public static AnnotationAudit Get(SafeDataReader dr)
{
if (dr.Read()) return new AnnotationAudit(dr);
return null;
}
internal AnnotationAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (dr.Read()) return new AnnotationAudit(dr);
return null;
}
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,14 +481,10 @@ 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()]
private new void DataPortal_Create()
@@ -715,39 +583,44 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAnnotationAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@TypeID", _TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAnnotationAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@TypeID", _TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLInsert", ex);
_ErrorMessage = ex.Message;
@@ -775,10 +648,12 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -821,36 +696,39 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAnnotationAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@TypeID", _TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
MarkOld();
// use the open connection to update child objects
}
catch (Exception ex)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAnnotationAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@TypeID", _TypeID);
cm.Parameters.AddWithValue("@RtfText", _RtfText);
cm.Parameters.AddWithValue("@SearchText", _SearchText);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLUpdate", ex);
_ErrorMessage = ex.Message;
@@ -859,17 +737,20 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
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();
}
}
{
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();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus)
{
@@ -976,17 +857,11 @@ 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;
}
protected override void DataPortal_Execute()
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());
try
@@ -1012,10 +887,10 @@ namespace VEPROMS.CSLA.Library
}
}
}
#endregion
// Standard Default Code
#region extension
AnnotationAuditExtension _AnnotationAuditExtension = new AnnotationAuditExtension();
#endregion
// Standard Default Code
#region extension
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,15 +26,13 @@ namespace VEPROMS.CSLA.Library
public partial class AnnotationAuditInfo : ReadOnlyBase<AnnotationAuditInfo>, IDisposable
{
public event AnnotationAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
private static List<AnnotationAuditInfo> _CacheList = new List<AnnotationAuditInfo>();
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)
{
if (!_CacheList.Contains(annotationAuditInfo)) _CacheList.Add(annotationAuditInfo); // In AddToCache
@@ -45,7 +41,8 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(annotationAuditInfo)) _CacheList.Remove(annotationAuditInfo); // In RemoveFromCache
}
private static Dictionary<string, List<AnnotationAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationAuditInfo>>();
[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()
{
while (_CacheList.Count > 0) // Move AnnotationAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
protected AnnotationAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
public string ErrorMessage => _ErrorMessage;
protected AnnotationAudit _Editable;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -180,50 +164,33 @@ 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
}
#endregion
#region Factory Methods
// 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() => 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);
}
private bool _Disposed = false;
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationAuditInfo()
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,14 +272,10 @@ 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)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.ReadData", GetHashCode());
@@ -374,10 +335,10 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationAuditInfo.DataPortal_Fetch", ex);
}
}
#endregion
// Standard Refresh
#region extension
AnnotationAuditInfoExtension _AnnotationAuditInfoExtension = new AnnotationAuditInfoExtension();
#endregion
// Standard Refresh
#region extension
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
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<AnnotationAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<AnnotationAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (AnnotationAuditInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationAuditInfoList()
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
@@ -149,41 +123,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,8 +168,7 @@ 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) { ;}
public AnnotationAuditInfoListPropertyDescriptor(AnnotationAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
#region Converter
@@ -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,28 +26,21 @@ 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);
}
public event AnnotationInfoEvent Changed;
[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);
OnInfoChanged(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
private static List<AnnotationInfo> _CacheList = new List<AnnotationInfo>();
#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)
{
if (!_CacheList.Contains(annotationInfo)) _CacheList.Add(annotationInfo); // In AddToCache
@@ -58,7 +49,8 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(annotationInfo)) _CacheList.Remove(annotationInfo); // In RemoveFromCache
}
private static Dictionary<string, List<AnnotationInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationInfo>>();
[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()
{
while (_CacheList.Count > 0) // Move AnnotationInfo(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -87,21 +79,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
protected Annotation _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
public string ErrorMessage => _ErrorMessage;
protected Annotation _Editable;
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
}
#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; } }
// 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() => MyAnnotationInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _AnnotationInfoUnique = 0;
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,16 +197,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationInfo()
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,11 +218,8 @@ 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 static void Refresh(Annotation tmp)
public virtual Annotation Get() => _Editable = Annotation.Get(_AnnotationID);
public static void Refresh(Annotation tmp)
{
string key = tmp.AnnotationID.ToString();
ConvertListToDictionary();
@@ -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,14 +341,10 @@ 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)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.ReadData", GetHashCode());
@@ -449,10 +402,10 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationInfo.DataPortal_Fetch", ex);
}
}
#endregion
// Standard Refresh
#region extension
AnnotationInfoExtension _AnnotationInfoExtension = new AnnotationInfoExtension();
#endregion
// Standard Refresh
#region extension
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
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<AnnotationInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<AnnotationInfo> Items => base.Items;
public void AddEvents()
{
foreach (AnnotationInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationInfoList()
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,8 +113,8 @@ 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,11 +154,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class TypeIDCriteria
{
public TypeIDCriteria(int typeID)
{
_TypeID = typeID;
}
private int _TypeID;
public TypeIDCriteria(int typeID) => _TypeID = typeID;
private int _TypeID;
public int TypeID
{
get { return _TypeID; }
@@ -224,11 +195,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ItemIDCriteria
{
public ItemIDCriteria(int itemID)
{
_ItemID = itemID;
}
private int _ItemID;
public ItemIDCriteria(int itemID) => _ItemID = itemID;
private int _ItemID;
public int ItemID
{
get { return _ItemID; }
@@ -265,41 +233,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -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;
@@ -69,9 +67,10 @@ namespace VEPROMS.CSLA.Library
}
ClearRefreshList();
}
#endregion
#region Collection
private static List<AnnotationType> _CacheList = new List<AnnotationType>();
#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)
{
if (!_CacheList.Contains(annotationType)) _CacheList.Add(annotationType); // In AddToCache
@@ -80,8 +79,10 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(annotationType)) _CacheList.Remove(annotationType); // In RemoveFromCache
}
private static Dictionary<string, List<AnnotationType>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationType>>();
private static Dictionary<string, List<AnnotationType>> _CacheByName = 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>> _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()
{
while (_CacheList.Count > 0) // Move AnnotationType(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -115,16 +116,10 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private static int _nextTypeID = -1;
public static int NextTypeID
{
get { return _nextTypeID--; }
}
private int _TypeID;
public string ErrorMessage => _ErrorMessage;
private static int _nextTypeID = -1;
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,40 +271,25 @@ 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));
return base.IsDirty || (_AnnotationTypeAnnotations != null && _AnnotationTypeAnnotations.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> 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
}
#endregion
#region ValidationRules
[NonSerialized]
// 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() => MyAnnotationTypeUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
@@ -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; } }
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; } }
#endregion
#region Factory Methods
public int CurrentEditLevel => EditLevel;
private static int _AnnotationTypeUnique = 0;
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,16 +354,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationType()
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,25 +571,17 @@ 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()]
private new void DataPortal_Create()
@@ -849,39 +719,46 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAnnotationType";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Config", _Config);
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;
cm.Parameters.Add(param_TypeID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_TypeID = (int)cm.Parameters["@newTypeID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
MarkOld();
// update child objects
if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAnnotationType";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Config", _Config);
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)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_TypeID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_TypeID = (int)cm.Parameters["@newTypeID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
_AnnotationTypeAnnotations?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.SQLInsert", ex);
_ErrorMessage = ex.Message;
@@ -904,13 +781,17 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@Config", config);
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;
cm.Parameters.Add(param_TypeID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// Output Calculated Columns
SqlParameter param_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_TypeID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -953,37 +834,42 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAnnotationType";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@TypeID", _TypeID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// use the open connection to update child objects
if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this);
}
catch (Exception ex)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAnnotationType";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@TypeID", _TypeID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
_AnnotationTypeAnnotations?.Update(this);
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.SQLUpdate", ex);
_ErrorMessage = ex.Message;
@@ -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"];
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);
{
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();
}
_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)
@@ -1022,10 +911,12 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -1038,12 +929,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationType.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_TypeID));
}
[Transactional(TransactionalTypes.TransactionScope)]
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_TypeID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Delete", GetHashCode());
@@ -1109,17 +997,11 @@ 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;
}
protected override void DataPortal_Execute()
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());
try
@@ -1145,10 +1027,10 @@ namespace VEPROMS.CSLA.Library
}
}
}
#endregion
// Standard Default Code
#region extension
AnnotationTypeExtension _AnnotationTypeExtension = new AnnotationTypeExtension();
#endregion
// Standard Default Code
#region extension
readonly AnnotationTypeExtension _AnnotationTypeExtension = new AnnotationTypeExtension();
[Serializable()]
partial class AnnotationTypeExtension : extensionBase
{
@@ -1156,17 +1038,11 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// Default Values
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)
{
// Needs to be overriden to add new authorization 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,12 +28,9 @@ 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 int _AnnotationID;
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID
{
@@ -219,25 +213,22 @@ namespace VEPROMS.CSLA.Library
return _Item_UserID;
}
}
// CSLATODO: Check AnnotationTypeAnnotation.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 AnnotationTypeAnnotation</returns>
protected override object GetIdValue()
{
return MyAnnotationTypeAnnotationUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base AnnotationTypeAnnotation.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationTypeAnnotation</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty
// CSLATODO: Check AnnotationTypeAnnotation.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 AnnotationTypeAnnotation</returns>
protected override object GetIdValue() => MyAnnotationTypeAnnotationUnique; // Absolutely Unique ID
// CSLATODO: Replace base AnnotationTypeAnnotation.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current AnnotationTypeAnnotation</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty
{
get
{
@@ -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));
return base.IsDirty || (_MyItem != null && _MyItem.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> 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,81 +312,17 @@ 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; } }
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);
}
public AnnotationTypeAnnotation()
#endregion
#region Factory Methods
public int CurrentEditLevel => EditLevel;
private static int _AnnotationTypeAnnotationUnique = 0;
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();
_AnnotationID = Annotation.NextAnnotationID;
@@ -425,16 +349,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationTypeAnnotation()
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++;
}
@@ -472,35 +392,45 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
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"];
_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"];
_LastChanged = Annotation.Update(cn, ref _AnnotationID, _ItemID, myAnnotationType.TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
MarkOld();
}
internal void DeleteSelf(AnnotationType myAnnotationType)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Annotation.Remove(cn, _AnnotationID);
MarkNew();
}
#endregion
// Standard Default Code
#region extension
AnnotationTypeAnnotationExtension _AnnotationTypeAnnotationExtension = new AnnotationTypeAnnotationExtension();
{
// if we're not dirty then don't update the database
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 (!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 (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Annotation.Remove(cn, _AnnotationID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
readonly AnnotationTypeAnnotationExtension _AnnotationTypeAnnotationExtension = new AnnotationTypeAnnotationExtension();
[Serializable()]
partial class AnnotationTypeAnnotationExtension : extensionBase
{
@@ -508,17 +438,11 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// Default Values
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)
{
// Needs to be overriden to add new authorization 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,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public AnnotationTypeAnnotation this[Annotation myAnnotation]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public AnnotationTypeAnnotation this[Annotation myAnnotation]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<AnnotationTypeAnnotation> Items
{
get { return base.Items; }
}
public AnnotationTypeAnnotation GetItem(Annotation myAnnotation)
public new System.Collections.Generic.IList<AnnotationTypeAnnotation> Items => base.Items;
public AnnotationTypeAnnotation GetItem(Annotation myAnnotation)
{
foreach (AnnotationTypeAnnotation annotation in this)
if (annotation.AnnotationID == myAnnotation.AnnotationID)
@@ -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,20 +125,14 @@ 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);
}
public static AnnotationTypeAnnotations GetByTypeID(int typeID)
#endregion
#region Factory Methods
internal static AnnotationTypeAnnotations New() => new AnnotationTypeAnnotations();
internal static AnnotationTypeAnnotations Get(SafeDataReader dr) => new AnnotationTypeAnnotations(dr);
public static AnnotationTypeAnnotations GetByTypeID(int typeID)
{
try
{
@@ -161,11 +143,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AnnotationTypeAnnotations.GetByTypeID", ex);
}
}
private AnnotationTypeAnnotations()
{
MarkAsChild();
}
internal AnnotationTypeAnnotations(SafeDataReader dr)
private AnnotationTypeAnnotations() => MarkAsChild();
internal AnnotationTypeAnnotations(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +153,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationTypeAnnotations()
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,19 +173,16 @@ 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;
}
private int _TypeID;
public TypeIDCriteria(int typeID) => _TypeID = typeID;
private int _TypeID;
public int TypeID
{
get { return _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,49 +238,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
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,15 +28,13 @@ namespace VEPROMS.CSLA.Library
public partial class AnnotationTypeInfo : ReadOnlyBase<AnnotationTypeInfo>, IDisposable
{
public event AnnotationTypeInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
private static List<AnnotationTypeInfo> _CacheList = new List<AnnotationTypeInfo>();
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)
{
if (!_CacheList.Contains(annotationTypeInfo)) _CacheList.Add(annotationTypeInfo); // In AddToCache
@@ -47,7 +43,8 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(annotationTypeInfo)) _CacheList.Remove(annotationTypeInfo); // In RemoveFromCache
}
private static Dictionary<string, List<AnnotationTypeInfo>> _CacheByPrimaryKey = new Dictionary<string, List<AnnotationTypeInfo>>();
[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()
{
while (_CacheList.Count > 0) // Move AnnotationTypeInfo(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -76,21 +73,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
protected AnnotationType _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
public string ErrorMessage => _ErrorMessage;
protected AnnotationType _Editable;
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
}
#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; } }
// 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() => MyAnnotationTypeInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _AnnotationTypeInfoUnique = 0;
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,16 +191,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationTypeInfo()
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,11 +212,8 @@ 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 static void Refresh(AnnotationType tmp)
public virtual AnnotationType Get() => _Editable = AnnotationType.Get(_TypeID);
public static void Refresh(AnnotationType tmp)
{
string key = tmp.TypeID.ToString();
ConvertListToDictionary();
@@ -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,14 +270,10 @@ 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)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.ReadData", GetHashCode());
@@ -373,10 +331,10 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationTypeInfo.DataPortal_Fetch", ex);
}
}
#endregion
// Standard Refresh
#region extension
AnnotationTypeInfoExtension _AnnotationTypeInfoExtension = new AnnotationTypeInfoExtension();
#endregion
// Standard Refresh
#region extension
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,19 +25,14 @@ 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();
}
#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; } }
public void AddEvents()
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 => base.Items;
public void AddEvents()
{
foreach (AnnotationTypeInfo tmp in this)
{
@@ -58,16 +51,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AnnotationTypeInfoList()
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++;
}
@@ -105,26 +94,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AnnotationTypeInfoList.Get", ex);
}
}
/// <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);
// }
//}
private AnnotationTypeInfoList()
/// <summary>
/// Reset the list of all AnnotationTypeInfo.
/// </summary>
public static void Reset() => _AnnotationTypeInfoList = null;
private AnnotationTypeInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -157,41 +131,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -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);
}
+178 -346
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -57,9 +55,10 @@ namespace VEPROMS.CSLA.Library
}
ClearRefreshList();
}
#endregion
#region Collection
private static List<Assignment> _CacheList = new List<Assignment>();
#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)
{
if (!_CacheList.Contains(assignment)) _CacheList.Add(assignment); // In AddToCache
@@ -68,7 +67,8 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache
}
private static Dictionary<string, List<Assignment>> _CacheByPrimaryKey = new Dictionary<string, List<Assignment>>();
[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()
{
while (_CacheList.Count > 0) // Move Assignment(s) from temporary _CacheList to _CacheByPrimaryKey
@@ -93,16 +93,10 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private static int _nextAID = -1;
public static int NextAID
{
get { return _nextAID--; }
}
private int _AID;
public string ErrorMessage => _ErrorMessage;
private static int _nextAID = -1;
public static int NextAID => _nextAID--;
private int _AID;
[System.ComponentModel.DataObjectField(true, true)]
public int AID
{
@@ -310,40 +304,17 @@ 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
}
#endregion
#region ValidationRules
[NonSerialized]
// 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() => MyAssignmentUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
@@ -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,16 +360,11 @@ 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
}
private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e)
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; } }
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; } }
#endregion
#region Factory Methods
public int CurrentEditLevel => EditLevel;
private static int _AssignmentUnique = 0;
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,16 +433,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~Assignment()
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)
internal Assignment(SafeDataReader dr) => ReadData(dr);
public static void Delete(int aid)
{
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,14 +592,10 @@ 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()]
private new void DataPortal_Create()
@@ -818,44 +695,51 @@ 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"];
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAssignment";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
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;
cm.Parameters.Add(param_AID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_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());
}
catch (Exception ex)
{
_MyFolder?.Update();
_MyGroup?.Update();
_MyRole?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAssignment";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
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)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_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());
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLInsert", ex);
_ErrorMessage = ex.Message;
@@ -881,13 +765,17 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@EndDate", endDate.DBValue);
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;
cm.Parameters.Add(param_AID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// Output Calculated Columns
SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -930,42 +818,47 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return; // If not dirty - nothing to do
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"];
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAssignment";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AID", _AID);
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// use the open connection to update child objects
}
catch (Exception ex)
{
_MyFolder?.Update();
_MyGroup?.Update();
_MyRole?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAssignment";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AID", _AID);
cm.Parameters.AddWithValue("@GID", GID);
cm.Parameters.AddWithValue("@RID", RID);
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLUpdate", ex);
_ErrorMessage = ex.Message;
@@ -974,17 +867,20 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = 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();
}
}
{
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();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int aid, int gid, int rid, int folderID, SmartDate startDate, SmartDate endDate, DateTime dts, string usrID, ref byte[] lastChanged)
{
@@ -1006,10 +902,12 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
@@ -1022,12 +920,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Assignment.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AID));
}
[Transactional(TransactionalTypes.TransactionScope)]
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Delete", GetHashCode());
@@ -1093,17 +988,11 @@ 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;
}
protected override void DataPortal_Execute()
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());
try
@@ -1129,10 +1018,10 @@ namespace VEPROMS.CSLA.Library
}
}
}
#endregion
// Standard Default Code
#region extension
AssignmentExtension _AssignmentExtension = new AssignmentExtension();
#endregion
// Standard Default Code
#region extension
readonly AssignmentExtension _AssignmentExtension = new AssignmentExtension();
[Serializable()]
partial class AssignmentExtension : extensionBase
{
@@ -1140,21 +1029,12 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
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; }
}
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// Default Values
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)
{
// Needs to be overriden to add new authorization 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
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<AssignmentInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<AssignmentInfo> Items => base.Items;
public void AddEvents()
{
foreach (AssignmentInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AssignmentInfoList()
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,11 +168,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class FolderIDCriteria
{
public FolderIDCriteria(int folderID)
{
_FolderID = folderID;
}
private int _FolderID;
public FolderIDCriteria(int folderID) => _FolderID = folderID;
private int _FolderID;
public int FolderID
{
get { return _FolderID; }
@@ -238,11 +209,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class GIDCriteria
{
public GIDCriteria(int gid)
{
_GID = gid;
}
private int _GID;
public GIDCriteria(int gid) => _GID = gid;
private int _GID;
public int GID
{
get { return _GID; }
@@ -282,11 +250,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class RIDCriteria
{
public RIDCriteria(int rid)
{
_RID = rid;
}
private int _RID;
public RIDCriteria(int rid) => _RID = rid;
private int _RID;
public int RID
{
get { return _RID; }
@@ -323,41 +288,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -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,36 +676,43 @@ 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"];
using (SqlCommand cm = cn.CreateCommand())
_MyDocVersion?.Update();
_MyROFst?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAssociation";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@VersionID", VersionID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@Config", _Config);
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;
cm.Parameters.Add(param_AssociationID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AssociationID = (int)cm.Parameters["@newAssociationID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addAssociation";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@VersionID", VersionID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@Config", _Config);
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)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AssociationID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_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,34 +795,39 @@ 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"];
if (base.IsDirty)
_MyDocVersion?.Update();
_MyROFst?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAssociation";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AssociationID", _AssociationID);
cm.Parameters.AddWithValue("@VersionID", VersionID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateAssociation";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AssociationID", _AssociationID);
cm.Parameters.AddWithValue("@VersionID", VersionID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -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"];
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);
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
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<AssociationInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<AssociationInfo> Items => base.Items;
public void AddEvents()
{
foreach (AssociationInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~AssociationInfoList()
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,11 +162,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class VersionIDCriteria
{
public VersionIDCriteria(int versionID)
{
_VersionID = versionID;
}
private int _VersionID;
public VersionIDCriteria(int versionID) => _VersionID = versionID;
private int _VersionID;
public int VersionID
{
get { return _VersionID; }
@@ -224,11 +203,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ROFstIDCriteria
{
public ROFstIDCriteria(int rOFstID)
{
_ROFstID = rOFstID;
}
private int _ROFstID;
public ROFstIDCriteria(int rOFstID) => _ROFstID = rOFstID;
private int _ROFstID;
public int ROFstID
{
get { return _ROFstID; }
@@ -265,41 +241,31 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -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);
}