CSLA - E & F

This commit is contained in:
2026-09-09 14:08:28 -04:00
parent a69a2270a6
commit f2b064f459
25 changed files with 1535 additions and 3501 deletions
+100 -226
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,6 +55,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<Entry> _CacheList = new List<Entry>();
protected static void AddToCache(Entry entry)
{
@@ -66,6 +65,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Entry>> _CacheByPrimaryKey = new Dictionary<string, List<Entry>>();
private static void ConvertListToDictionary()
{
@@ -91,10 +91,7 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -199,7 +196,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list));
return base.IsDirty || (_MyDocument != null && _MyDocument.IsDirtyList(list));
}
public override bool IsValid
{
@@ -208,28 +205,16 @@ namespace VEPROMS.CSLA.Library
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocument == null || _MyDocument.IsValidList(list));
}
// CSLATODO: Replace base Entry.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Entry</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Entry.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 Entry</returns>
protected override object GetIdValue()
{
return MyEntryUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -258,8 +243,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()
@@ -288,29 +273,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_EntryExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -318,42 +285,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_EntryExtension.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 _EntryUnique = 0;
protected static int EntryUnique
{ get { return ++_EntryUnique; } }
private int _MyEntryUnique = EntryUnique;
public int MyEntryUnique // Absolutely Unique ID - Editable
{ get { return _MyEntryUnique; } }
protected static int EntryUnique => ++_EntryUnique;
private readonly int _MyEntryUnique = EntryUnique;
// Absolutely Unique ID - Editable
public int MyEntryUnique => _MyEntryUnique;
protected Entry()
{/* require use of factory methods */
AddToCache(this);
@@ -362,15 +301,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;
~Entry()
{
_CountFinalized++;
@@ -395,8 +330,6 @@ namespace VEPROMS.CSLA.Library
}
public static Entry New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Entry");
try
{
return DataPortal.Create<Entry>();
@@ -464,8 +397,6 @@ namespace VEPROMS.CSLA.Library
}
public static Entry Get(int contentID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Entry");
try
{
Entry tmp = GetCachedByPrimaryKey(contentID);
@@ -491,14 +422,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Entry(dr);
return null;
}
internal Entry(SafeDataReader dr)
{
ReadData(dr);
}
internal Entry(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Entry");
try
{
DataPortal.Delete(new PKCriteria(contentID));
@@ -510,12 +436,6 @@ namespace VEPROMS.CSLA.Library
}
public override Entry Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Entry");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Entry");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Entry");
try
{
BuildRefreshList();
@@ -535,13 +455,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -637,30 +553,35 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyDocument != null) _MyDocument.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyDocument?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntry";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntry";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.SQLInsert", GetHashCode());
@@ -689,8 +610,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -734,31 +657,36 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.SQLUpdate", GetHashCode());
try
{
if (_MyDocument != null) _MyDocument.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyDocument?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntry";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
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 = "updateEntry";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
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
}
@@ -771,14 +699,17 @@ namespace VEPROMS.CSLA.Library
}
internal void Update(Content content)
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Entry.Add(cn, content, MyDocument, _DTS, _UserID);
else
_LastChanged = Entry.Update(cn, content.ContentID, _DocID, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Entry.Add(cn, content, MyDocument, _DTS, _UserID);
else
_LastChanged = Entry.Update(cn, content.ContentID, _DocID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
// B2018-126 & B2018-133: Refresh for library document usage change (note that original checkin had a null check for
// _MyDocument.DocumentEntries that was causing a sql Distributed Transaction Coordinator error - this was removed
@@ -808,8 +739,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();
@@ -824,10 +757,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ContentID));
}
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_ContentID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
@@ -894,16 +824,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private readonly int _ContentID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
public bool Exists => _exists;
public ExistsCommand(int contentID) => _ContentID = contentID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Execute", GetHashCode());
@@ -933,7 +857,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
EntryExtension _EntryExtension = new EntryExtension();
readonly EntryExtension _EntryExtension = new EntryExtension();
[Serializable()]
partial class EntryExtension : extensionBase
{
@@ -942,14 +866,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)
{
@@ -978,57 +896,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 Entry)
if (destType == typeof(string) && value is Entry entry)
{
// Return the ToString value
return ((Entry)value).ToString();
return entry.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create EntryExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Entry
// {
// partial class EntryExtension : 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;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshEntryAudits.Add(this);
}
private void ClearRefreshList()
{
_RefreshEntryAudits = new List<EntryAudit>();
}
private void ClearRefreshList() => _RefreshEntryAudits = new List<EntryAudit>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<EntryAudit> _CacheList = new List<EntryAudit>();
protected static void AddToCache(EntryAudit entryAudit)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<EntryAudit>> _CacheByPrimaryKey = new Dictionary<string, List<EntryAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -200,40 +191,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base EntryAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current EntryAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check EntryAudit.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 EntryAudit</returns>
protected override object GetIdValue()
{
return MyEntryAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -261,8 +226,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()
@@ -281,33 +246,11 @@ namespace VEPROMS.CSLA.Library
_EntryAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_EntryAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -315,42 +258,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_EntryAuditExtension.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 _EntryAuditUnique = 0;
protected static int EntryAuditUnique
{ get { return ++_EntryAuditUnique; } }
private int _MyEntryAuditUnique = EntryAuditUnique;
public int MyEntryAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyEntryAuditUnique; } }
protected static int EntryAuditUnique => ++_EntryAuditUnique;
private readonly int _MyEntryAuditUnique = EntryAuditUnique;
// Absolutely Unique ID - Editable
public int MyEntryAuditUnique => _MyEntryAuditUnique;
protected EntryAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -359,15 +274,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;
~EntryAudit()
{
_CountFinalized++;
@@ -392,8 +303,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a EntryAudit");
try
{
return DataPortal.Create<EntryAudit>();
@@ -431,8 +340,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a EntryAudit");
try
{
EntryAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -464,8 +371,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a EntryAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -477,12 +382,6 @@ namespace VEPROMS.CSLA.Library
}
public override EntryAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a EntryAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a EntryAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a EntryAudit");
try
{
BuildRefreshList();
@@ -502,13 +401,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -604,30 +499,35 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntryAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntryAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
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}] EntryAudit.SQLInsert", GetHashCode());
@@ -657,8 +557,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -703,27 +605,30 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntryAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntryAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
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
}
@@ -736,14 +641,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)
EntryAudit.Add(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
else
EntryAudit.Update(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
EntryAudit.Add(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
else
EntryAudit.Update(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
}
MarkOld();
}
}
@@ -834,7 +742,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension();
readonly EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension();
[Serializable()]
partial class EntryAuditExtension : extensionBase
{
@@ -871,49 +779,14 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryAudit)
if (destType == typeof(string) && value is EntryAudit audit)
{
// Return the ToString value
return ((EntryAudit)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 EntryAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class EntryAudit
// {
// partial class EntryAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class EntryAuditInfo : ReadOnlyBase<EntryAuditInfo>, IDisposable
{
public event EntryAuditInfoEvent 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<EntryAuditInfo> _CacheList = new List<EntryAuditInfo>();
protected static void AddToCache(EntryAuditInfo entryAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entryAuditInfo)) _CacheList.Remove(entryAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<EntryAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<EntryAuditInfo>>();
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 EntryAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -144,32 +128,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base EntryAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current EntryAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check EntryAuditInfo.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 EntryAuditInfo</returns>
protected override object GetIdValue()
{
return MyEntryAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _EntryAuditInfoUnique = 0;
private static int EntryAuditInfoUnique
{ get { return ++_EntryAuditInfoUnique; } }
private int _MyEntryAuditInfoUnique = EntryAuditInfoUnique;
public int MyEntryAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyEntryAuditInfoUnique; } }
private static int EntryAuditInfoUnique => ++_EntryAuditInfoUnique;
private readonly int _MyEntryAuditInfoUnique = EntryAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyEntryAuditInfoUnique => _MyEntryAuditInfoUnique;
protected EntryAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -178,15 +149,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;
~EntryAuditInfo()
{
_CountFinalized++;
@@ -203,10 +170,7 @@ namespace VEPROMS.CSLA.Library
if (listEntryAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual EntryAudit Get()
{
return _Editable = EntryAudit.Get(_AuditID);
}
public virtual EntryAudit Get() => _Editable = EntryAudit.Get(_AuditID);
public static void Refresh(EntryAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -227,8 +191,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a EntryAudit");
try
{
EntryAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -267,13 +229,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -333,7 +291,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension();
readonly EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension();
[Serializable()]
partial class EntryAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -349,10 +307,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 EntryAuditInfo)
if (destType == typeof(string) && value is EntryAuditInfo info)
{
// Return the ToString value
return ((EntryAuditInfo)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<EntryAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<EntryAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (EntryAuditInfo 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; } }
~EntryAuditInfoList()
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;
~EntryAuditInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on EntryAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all EntryAuditInfo.
/// </summary>
public static void Reset()
{
_EntryAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static EntryAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<EntryAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on EntryAuditInfoList.Get", ex);
// }
//}
private EntryAuditInfoList()
/// <summary>
/// Reset the list of all EntryAuditInfo.
/// </summary>
public static void Reset() => _EntryAuditInfoList = null;
private EntryAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class EntryAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private EntryAuditInfo Item { get { return (EntryAuditInfo)_Item; } }
public EntryAuditInfoListPropertyDescriptor(EntryAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryAuditInfoList)
if (destType == typeof(string) && value is EntryAuditInfoList list)
{
// Return department and department role separated by comma.
return ((EntryAuditInfoList)value).Items.Count.ToString() + " EntryAudits";
return $"{list.Items.Count} EntryAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class EntryInfo : ReadOnlyBase<EntryInfo>, IDisposable
{
public event EntryInfoEvent 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<EntryInfo> _CacheList = new List<EntryInfo>();
protected static void AddToCache(EntryInfo entryInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<EntryInfo>> _CacheByPrimaryKey = new Dictionary<string, List<EntryInfo>>();
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 Entry _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -149,32 +133,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base EntryInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current EntryInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check EntryInfo.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 EntryInfo</returns>
protected override object GetIdValue()
{
return MyEntryInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _EntryInfoUnique = 0;
private static int EntryInfoUnique
{ get { return ++_EntryInfoUnique; } }
private int _MyEntryInfoUnique = EntryInfoUnique;
public int MyEntryInfoUnique // Absolutely Unique ID - Info
{ get { return _MyEntryInfoUnique; } }
private static int EntryInfoUnique => ++_EntryInfoUnique;
private readonly int _MyEntryInfoUnique = EntryInfoUnique;
// Absolutely Unique ID - Info
public int MyEntryInfoUnique => _MyEntryInfoUnique;
protected EntryInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -183,15 +154,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;
~EntryInfo()
{
_CountFinalized++;
@@ -208,10 +175,7 @@ namespace VEPROMS.CSLA.Library
if (listEntryInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
public virtual Entry Get()
{
return _Editable = Entry.Get(_ContentID);
}
public virtual Entry Get() => _Editable = Entry.Get(_ContentID);
public static void Refresh(Entry tmp)
{
string key = tmp.ContentID.ToString();
@@ -224,11 +188,11 @@ namespace VEPROMS.CSLA.Library
{
if (_DocID != tmp.DocID)
{
if (MyDocument != null) MyDocument.RefreshDocumentEntries(); // Update List for old value
MyDocument?.RefreshDocumentEntries(); // Update List for old value
_DocID = tmp.DocID; // Update the value
}
_MyDocument = null; // Reset list so that the next line gets a new list
if (MyDocument != null) MyDocument.RefreshDocumentEntries(); // Update List for new value
MyDocument?.RefreshDocumentEntries(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_EntryInfoExtension.Refresh(this);
@@ -251,8 +215,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryInfo Get(int contentID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Entry");
try
{
EntryInfo tmp = GetCachedByPrimaryKey(contentID);
@@ -291,13 +253,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
private void ReadData(SafeDataReader dr)
{
@@ -355,7 +313,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension();
readonly EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension();
[Serializable()]
partial class EntryInfoExtension : extensionBase { }
[Serializable()]
@@ -371,10 +329,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 EntryInfo)
if (destType == typeof(string) && value is EntryInfo info)
{
// Return the ToString value
return ((EntryInfo)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<EntryInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<EntryInfo> Items => base.Items;
public void AddEvents()
{
foreach (EntryInfo 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; } }
~EntryInfoList()
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;
~EntryInfoList()
{
_CountFinalized++;
}
@@ -104,18 +97,6 @@ namespace VEPROMS.CSLA.Library
{
_EntryInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static EntryInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<EntryInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on EntryInfoList.Get", ex);
// }
//}
public static EntryInfoList GetByContentID(int contentID)
{
try
@@ -180,11 +161,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -224,11 +202,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -265,41 +240,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 +285,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class EntryInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private EntryInfo Item { get { return (EntryInfo)_Item; } }
public EntryInfoListPropertyDescriptor(EntryInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +293,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 EntryInfoList)
if (destType == typeof(string) && value is EntryInfoList list)
{
// Return department and department role separated by comma.
return ((EntryInfoList)value).Items.Count.ToString() + " Entries";
return $"{list.Items.Count} Entries";
}
return base.ConvertTo(context, culture, value, destType);
}
+121 -253
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;
@@ -58,6 +56,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<Figure> _CacheList = new List<Figure>();
protected static void AddToCache(Figure figure)
{
@@ -67,7 +66,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(figure)) _CacheList.Remove(figure); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Figure>> _CacheByPrimaryKey = new Dictionary<string, List<Figure>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Figure>> _CacheByROFstID_ImageID = new Dictionary<string, List<Figure>>();
private static void ConvertListToDictionary()
{
@@ -102,15 +103,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 _nextFigureID = -1;
public static int NextFigureID
{
get { return _nextFigureID--; }
}
public static int NextFigureID => _nextFigureID--;
private int _FigureID;
[System.ComponentModel.DataObjectField(true, true)]
public int FigureID
@@ -252,37 +247,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list)) || (_MyROImage == null ? false : _MyROImage.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyROFst != null && _MyROFst.IsDirtyList(list)) || (_MyROImage != null && _MyROImage.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)) && (_MyROImage == null ? true : _MyROImage.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyROFst == null || _MyROFst.IsValidList(list)) && (_MyROImage == null || _MyROImage.IsValidList(list));
}
// CSLATODO: Replace base Figure.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Figure</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Figure.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 Figure</returns>
protected override object GetIdValue()
{
return MyFigureUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFigureUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -312,8 +292,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()
@@ -355,33 +335,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FigureID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowRead(ImageID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ImageID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_FigureExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -389,42 +347,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_FigureExtension.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 _FigureUnique = 0;
protected static int FigureUnique
{ get { return ++_FigureUnique; } }
private int _MyFigureUnique = FigureUnique;
public int MyFigureUnique // Absolutely Unique ID - Editable
{ get { return _MyFigureUnique; } }
protected static int FigureUnique => ++_FigureUnique;
private readonly int _MyFigureUnique = FigureUnique;
// Absolutely Unique ID - Editable
public int MyFigureUnique => _MyFigureUnique;
protected Figure()
{/* require use of factory methods */
AddToCache(this);
@@ -433,15 +363,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;
~Figure()
{
_CountFinalized++;
@@ -478,8 +404,6 @@ namespace VEPROMS.CSLA.Library
}
public static Figure New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Figure");
try
{
return DataPortal.Create<Figure>();
@@ -548,8 +472,6 @@ namespace VEPROMS.CSLA.Library
}
public static Figure Get(int figureID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Figure");
try
{
Figure tmp = GetCachedByPrimaryKey(figureID);
@@ -572,8 +494,6 @@ namespace VEPROMS.CSLA.Library
}
public static Figure GetByROFstID_ImageID(int rOFstID, int imageID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Figure");
try
{
Figure tmp = GetCachedByROFstID_ImageID(rOFstID, imageID);
@@ -599,14 +519,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Figure(dr);
return null;
}
internal Figure(SafeDataReader dr)
{
ReadData(dr);
}
internal Figure(SafeDataReader dr) => ReadData(dr);
public static void Delete(int figureID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Figure");
try
{
DataPortal.Delete(new PKCriteria(figureID));
@@ -618,12 +533,6 @@ namespace VEPROMS.CSLA.Library
}
public override Figure Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Figure");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Figure");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Figure");
try
{
BuildRefreshList();
@@ -643,23 +552,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FigureID;
public int FigureID
{ get { return _FigureID; } }
public PKCriteria(int figureID)
{
_FigureID = figureID;
}
private readonly int _FigureID;
public int FigureID => _FigureID;
public PKCriteria(int figureID) => _FigureID = figureID;
}
[Serializable()]
private class ROFstID_ImageIDCriteria
{
private int _ROFstID;
public int ROFstID
{ get { return _ROFstID; } }
private int _ImageID;
public int ImageID
{ get { return _ImageID; } }
private readonly int _ROFstID;
public int ROFstID => _ROFstID;
private readonly int _ImageID;
public int ImageID => _ImageID;
public ROFstID_ImageIDCriteria(int rOFstID, int imageID)
{
_ROFstID = rOFstID;
@@ -799,36 +702,43 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyROFst != null) _MyROFst.Update();
if (_MyROImage != null) _MyROImage.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyROFst?.Update();
_MyROImage?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFigure";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
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_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int);
param_FigureID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_FigureID);
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
_FigureID = (int)cm.Parameters["@newFigureID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFigure";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
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_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FigureID);
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
_FigureID = (int)cm.Parameters["@newFigureID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.SQLInsert", GetHashCode());
@@ -858,11 +768,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_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int);
param_FigureID.Direction = ParameterDirection.Output;
SqlParameter param_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FigureID);
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();
@@ -907,34 +821,39 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.SQLUpdate", GetHashCode());
try
{
if (_MyROFst != null) _MyROFst.Update();
if (_MyROImage != null) _MyROImage.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyROFst?.Update();
_MyROImage?.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 = "updateFigure";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FigureID", _FigureID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
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 = "updateFigure";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FigureID", _FigureID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
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
}
@@ -947,14 +866,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 = Figure.Add(cn, ref _FigureID, _MyROFst, _MyROImage, _Config, _DTS, _UserID);
else
_LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, _MyROImage, _Config, _DTS, _UserID);
else
_LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
@@ -978,8 +900,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();
@@ -1064,16 +988,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _FigureID;
private readonly int _FigureID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int figureID)
{
_FigureID = figureID;
}
public bool Exists => _exists;
public ExistsCommand(int figureID) => _FigureID = figureID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Execute", GetHashCode());
@@ -1103,7 +1021,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
FigureExtension _FigureExtension = new FigureExtension();
readonly FigureExtension _FigureExtension = new FigureExtension();
[Serializable()]
partial class FigureExtension : extensionBase
{
@@ -1112,14 +1030,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)
{
@@ -1148,57 +1060,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 Figure)
if (destType == typeof(string) && value is Figure figure)
{
// Return the ToString value
return ((Figure)value).ToString();
return figure.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FigureExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Figure
// {
// partial class FigureExtension : 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 FigureInfo : ReadOnlyBase<FigureInfo>, IDisposable
{
public event FigureInfoEvent 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<FigureInfo> _CacheList = new List<FigureInfo>();
protected static void AddToCache(FigureInfo figureInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(figureInfo)) _CacheList.Remove(figureInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<FigureInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FigureInfo>>();
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 Figure _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FigureID;
[System.ComponentModel.DataObjectField(true, true)]
public int FigureID
@@ -166,32 +150,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base FigureInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FigureInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FigureInfo.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 FigureInfo</returns>
protected override object GetIdValue()
{
return MyFigureInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFigureInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _FigureInfoUnique = 0;
private static int FigureInfoUnique
{ get { return ++_FigureInfoUnique; } }
private int _MyFigureInfoUnique = FigureInfoUnique;
public int MyFigureInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFigureInfoUnique; } }
private static int FigureInfoUnique => ++_FigureInfoUnique;
private readonly int _MyFigureInfoUnique = FigureInfoUnique;
// Absolutely Unique ID - Info
public int MyFigureInfoUnique => _MyFigureInfoUnique;
protected FigureInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -200,15 +171,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FigureInfo()
{
_CountFinalized++;
@@ -225,10 +192,7 @@ namespace VEPROMS.CSLA.Library
if (listFigureInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(FigureID.ToString()); // remove the list
}
public virtual Figure Get()
{
return _Editable = Figure.Get(_FigureID);
}
public virtual Figure Get() => _Editable = Figure.Get(_FigureID);
public static void Refresh(Figure tmp)
{
string key = tmp.FigureID.ToString();
@@ -241,18 +205,18 @@ namespace VEPROMS.CSLA.Library
{
if (_ROFstID != tmp.ROFstID)
{
if (MyROFst != null) MyROFst.RefreshROFstFigures(); // Update List for old value
MyROFst?.RefreshROFstFigures(); // 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.RefreshROFstFigures(); // Update List for new value
MyROFst?.RefreshROFstFigures(); // Update List for new value
if (_ImageID != tmp.ImageID)
{
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for old value
MyROImage?.RefreshROImageFigures(); // Update List for old value
_ImageID = tmp.ImageID; // Update the value
}
_MyROImage = null; // Reset list so that the next line gets a new list
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for new value
MyROImage?.RefreshROImageFigures(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -271,11 +235,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ImageID != tmp.ImageID)
{
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for old value
MyROImage?.RefreshROImageFigures(); // Update List for old value
_ImageID = tmp.ImageID; // Update the value
}
_MyROImage = null; // Reset list so that the next line gets a new list
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for new value
MyROImage?.RefreshROImageFigures(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -294,11 +258,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ROFstID != tmp.ROFstID)
{
if (MyROFst != null) MyROFst.RefreshROFstFigures(); // Update List for old value
MyROFst?.RefreshROFstFigures(); // 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.RefreshROFstFigures(); // Update List for new value
MyROFst?.RefreshROFstFigures(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -307,8 +271,6 @@ namespace VEPROMS.CSLA.Library
}
public static FigureInfo Get(int figureID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Figure");
try
{
FigureInfo tmp = GetCachedByPrimaryKey(figureID);
@@ -347,13 +309,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FigureID;
public int FigureID
{ get { return _FigureID; } }
public PKCriteria(int figureID)
{
_FigureID = figureID;
}
private readonly int _FigureID;
public int FigureID => _FigureID;
public PKCriteria(int figureID) => _FigureID = figureID;
}
private string _ROImage_FileName = string.Empty;
public string ROImage_FileName
@@ -427,7 +385,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
FigureInfoExtension _FigureInfoExtension = new FigureInfoExtension();
readonly FigureInfoExtension _FigureInfoExtension = new FigureInfoExtension();
[Serializable()]
partial class FigureInfoExtension : extensionBase { }
[Serializable()]
@@ -443,10 +401,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 FigureInfo)
if (destType == typeof(string) && value is FigureInfo info)
{
// Return the ToString value
return ((FigureInfo)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<FigureInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<FigureInfo> Items => base.Items;
public void AddEvents()
{
foreach (FigureInfo 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; } }
~FigureInfoList()
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;
~FigureInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FigureInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all FigureInfo.
/// </summary>
public static void Reset()
{
_FigureInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static FigureInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<FigureInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on FigureInfoList.Get", ex);
// }
//}
public static FigureInfoList GetByROFstID(int rOFstID)
/// <summary>
/// Reset the list of all FigureInfo.
/// </summary>
public static void Reset() => _FigureInfoList = null;
public static FigureInfoList GetByROFstID(int rOFstID)
{
try
{
@@ -180,11 +158,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; }
@@ -224,11 +199,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ImageIDCriteria
{
public ImageIDCriteria(int imageID)
{
_ImageID = imageID;
}
private int _ImageID;
public ImageIDCriteria(int imageID) => _ImageID = imageID;
private int _ImageID;
public int ImageID
{
get { return _ImageID; }
@@ -265,41 +237,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 +282,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FigureInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private FigureInfo Item { get { return (FigureInfo)_Item; } }
public FigureInfoListPropertyDescriptor(FigureInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +290,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FigureInfoList)
if (destType == typeof(string) && value is FigureInfoList list)
{
// Return department and department role separated by comma.
return ((FigureInfoList)value).Items.Count.ToString() + " Figures";
return $"{list.Items.Count} Figures";
}
return base.ConvertTo(context, culture, value, destType);
}
+156 -333
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;
@@ -91,6 +89,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<Folder> _CacheList = new List<Folder>();
protected static void AddToCache(Folder folder)
{
@@ -100,7 +99,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Folder>> _CacheByPrimaryKey = new Dictionary<string, List<Folder>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Folder>> _CacheByParentID_Name = new Dictionary<string, List<Folder>>();
private static void ConvertListToDictionary()
{
@@ -135,15 +136,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 _nextFolderID = -1;
public static int NextFolderID
{
get { return _nextFolderID--; }
}
public static int NextFolderID => _nextFolderID--;
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -407,10 +402,7 @@ namespace VEPROMS.CSLA.Library
return _FolderAssignments;
}
}
public void Reset_FolderAssignments()
{
_FolderAssignmentCount = -1;
}
public void Reset_FolderAssignments() => _FolderAssignmentCount = -1;
private int _FolderDocVersionCount = 0;
/// <summary>
/// Count of FolderDocVersions for this Folder
@@ -442,10 +434,7 @@ namespace VEPROMS.CSLA.Library
return _FolderDocVersions;
}
}
public void Reset_FolderDocVersions()
{
_FolderDocVersionCount = -1;
}
public void Reset_FolderDocVersions() => _FolderDocVersionCount = -1;
private int _ChildFolderCount = 0;
/// <summary>
/// Count of ChildFolders for this Folder
@@ -477,10 +466,7 @@ namespace VEPROMS.CSLA.Library
return _ChildFolders;
}
}
public void Reset_ChildFolders()
{
_ChildFolderCount = -1;
}
public void Reset_ChildFolders() => _ChildFolderCount = -1;
public override bool IsDirty
{
get
@@ -495,37 +481,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_FolderAssignments == null ? false : _FolderAssignments.IsDirtyList(list)) || (_FolderDocVersions == null ? false : _FolderDocVersions.IsDirtyList(list)) || (_ChildFolders == null ? false : _ChildFolders.IsDirtyList(list)) || (_MyConnection == null ? false : _MyConnection.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_FolderAssignments != null && _FolderAssignments.IsDirtyList(list)) || (_FolderDocVersions != null && _FolderDocVersions.IsDirtyList(list)) || (_ChildFolders != null && _ChildFolders.IsDirtyList(list)) || (_MyConnection != null && _MyConnection.IsDirtyList(list)) || (_MyFormat != null && _MyFormat.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_FolderAssignments == null ? true : _FolderAssignments.IsValidList(list)) && (_FolderDocVersions == null ? true : _FolderDocVersions.IsValidList(list)) && (_ChildFolders == null ? true : _ChildFolders.IsValidList(list)) && (_MyConnection == null ? true : _MyConnection.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_FolderAssignments == null || _FolderAssignments.IsValidList(list)) && (_FolderDocVersions == null || _FolderDocVersions.IsValidList(list)) && (_ChildFolders == null || _ChildFolders.IsValidList(list)) && (_MyConnection == null || _MyConnection.IsValidList(list)) && (_MyFormat == null || _MyFormat.IsValidList(list));
}
// CSLATODO: Replace base Folder.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Folder</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Folder.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 Folder</returns>
protected override object GetIdValue()
{
return MyFolderUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFolderUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -558,8 +529,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()
@@ -604,43 +575,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DBID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DBID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_FolderExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -648,57 +587,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_FolderExtension.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 += _FolderAssignmentCount;
usedByCount += _FolderDocVersionCount;
usedByCount += _ChildFolderCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FolderUnique = 0;
protected static int FolderUnique
{ get { return ++_FolderUnique; } }
private int _MyFolderUnique = FolderUnique;
public int MyFolderUnique // Absolutely Unique ID - Editable
{ get { return _MyFolderUnique; } }
protected static int FolderUnique => ++_FolderUnique;
private readonly int _MyFolderUnique = FolderUnique;
// Absolutely Unique ID - Editable
public int MyFolderUnique => _MyFolderUnique;
protected Folder()
{/* require use of factory methods */
AddToCache(this);
@@ -707,15 +603,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;
~Folder()
{
_CountFinalized++;
@@ -752,8 +644,6 @@ namespace VEPROMS.CSLA.Library
}
public static Folder New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Folder");
try
{
return DataPortal.Create<Folder>();
@@ -860,8 +750,6 @@ namespace VEPROMS.CSLA.Library
}
public static Folder Get(int folderID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
Folder tmp = GetCachedByPrimaryKey(folderID);
@@ -884,8 +772,6 @@ namespace VEPROMS.CSLA.Library
}
public static Folder GetByParentID_Name(int parentID, string name)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
Folder tmp = GetCachedByParentID_Name(parentID, name);
@@ -911,15 +797,14 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Folder(dr, parent);
return null;
}
internal Folder(SafeDataReader dr)
{
ReadData(dr);
}
internal Folder(SafeDataReader dr) => ReadData(dr);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private Folder(SafeDataReader dr, Folder parent)
{
ReadData(dr);
MarkAsChild();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal Folder(SafeDataReader dr, int parentID)
{
ReadData(dr);
@@ -927,8 +812,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(int folderID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Folder");
try
{
// B2019-060: On delete, remove the folder from cache:
@@ -943,12 +826,6 @@ namespace VEPROMS.CSLA.Library
}
public override Folder Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Folder");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Folder");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Folder");
try
{
BuildRefreshList();
@@ -968,23 +845,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FolderID;
public int FolderID
{ get { return _FolderID; } }
public PKCriteria(int folderID)
{
_FolderID = folderID;
}
private readonly int _FolderID;
public int FolderID => _FolderID;
public PKCriteria(int folderID) => _FolderID = folderID;
}
[Serializable()]
private class ParentID_NameCriteria
{
private int _ParentID;
public int ParentID
{ get { return _ParentID; } }
private string _Name;
public string Name
{ get { return _Name; } }
private readonly int _ParentID;
public int ParentID => _ParentID;
private readonly string _Name;
public string Name => _Name;
public ParentID_NameCriteria(int parentID, string name)
{
_ParentID = parentID;
@@ -1140,46 +1011,53 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyConnection != null) _MyConnection.Update();
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyConnection?.Update();
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFolder";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int);
param_FolderID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_FolderID);
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
_FolderID = (int)cm.Parameters["@newFolderID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFolder";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FolderID);
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
_FolderID = (int)cm.Parameters["@newFolderID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_FolderAssignments != null) _FolderAssignments.Update(this);
if (_FolderDocVersions != null) _FolderDocVersions.Update(this);
if (_ChildFolders != null) _ChildFolders.Update(this);
_FolderAssignments?.Update(this);
_FolderDocVersions?.Update(this);
_ChildFolders?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1212,11 +1090,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
// Output Calculated Columns
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int);
param_FolderID.Direction = ParameterDirection.Output;
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FolderID);
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();
@@ -1263,44 +1145,49 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLUpdate", GetHashCode());
try
{
if (_MyConnection != null) _MyConnection.Update();
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyConnection?.Update();
_MyFormat?.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 = "updateFolder";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FolderID", _FolderID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFolder";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FolderID", _FolderID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_FolderAssignments != null) _FolderAssignments.Update(this);
if (_FolderDocVersions != null) _FolderDocVersions.Update(this);
if (_ChildFolders != null) _ChildFolders.Update(this);
_FolderAssignments?.Update(this);
_FolderDocVersions?.Update(this);
_ChildFolders?.Update(this);
}
catch (Exception ex)
{
@@ -1313,28 +1200,35 @@ 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 = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
else
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
else
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
if (_FolderAssignments != null) _FolderAssignments.Update(this);
if (_FolderDocVersions != null) _FolderDocVersions.Update(this);
if (_ChildFolders != null) _ChildFolders.Update(this);
_FolderAssignments?.Update(this);
_FolderDocVersions?.Update(this);
_ChildFolders?.Update(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Folder folder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Folder.Remove(cn, _FolderID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Folder.Remove(cn, _FolderID);
}
MarkNew();
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -1362,8 +1256,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1378,10 +1274,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_FolderID));
}
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_FolderID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
@@ -1473,16 +1366,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _FolderID;
private readonly int _FolderID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int folderID)
{
_FolderID = folderID;
}
public bool Exists => _exists;
public ExistsCommand(int folderID) => _FolderID = folderID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Execute", GetHashCode());
@@ -1512,7 +1399,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
FolderExtension _FolderExtension = new FolderExtension();
readonly FolderExtension _FolderExtension = new FolderExtension();
[Serializable()]
partial class FolderExtension : extensionBase
{
@@ -1521,22 +1408,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual int DefaultDBID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
public virtual int DefaultDBID => 1;
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)
{
@@ -1565,65 +1440,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 Folder)
if (destType == typeof(string) && value is Folder folder)
{
// Return the ToString value
return ((Folder)value).ToString();
return folder.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FolderExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Folder
// {
// partial class FolderExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual int DefaultDBID
// {
// get { return 1; }
// }
// 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 */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _AID;
[System.ComponentModel.DataObjectField(true, true)]
public int AID
@@ -298,19 +292,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FolderAssignment</returns>
protected override object GetIdValue()
{
return MyFolderAssignmentUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base FolderAssignment.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FolderAssignment</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyFolderAssignmentUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -325,18 +307,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyRole == null ? false : _MyRole.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyGroup != null && _MyGroup.IsDirtyList(list)) || (_MyRole != null && _MyRole.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyRole == null ? true : _MyRole.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyGroup == null || _MyGroup.IsValidList(list)) && (_MyRole == null || _MyRole.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -367,8 +346,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()
@@ -430,80 +409,21 @@ 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.AllowWrite(GID, "<Role(s)>");
//AuthorizationRules.AllowRead(RID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RID, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FolderAssignmentUnique = 0;
private static int FolderAssignmentUnique
{ get { return ++_FolderAssignmentUnique; } }
private int _MyFolderAssignmentUnique = FolderAssignmentUnique;
public int MyFolderAssignmentUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFolderAssignmentUnique; } }
internal static FolderAssignment New(Group myGroup, Role myRole)
{
return new FolderAssignment(myGroup, myRole);
}
internal static FolderAssignment Get(SafeDataReader dr)
{
return new FolderAssignment(dr);
}
private static int FolderAssignmentUnique => ++_FolderAssignmentUnique;
private readonly int _MyFolderAssignmentUnique = FolderAssignmentUnique;
// Absolutely Unique ID - Editable FK
public int MyFolderAssignmentUnique => _MyFolderAssignmentUnique;
internal static FolderAssignment New(Group myGroup, Role myRole) => new FolderAssignment(myGroup, myRole);
internal static FolderAssignment Get(SafeDataReader dr) => new FolderAssignment(dr);
public FolderAssignment()
{
MarkAsChild();
@@ -534,15 +454,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;
~FolderAssignment()
{
_CountFinalized++;
@@ -588,33 +504,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, myFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, myFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, myFolder.FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, myFolder.FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Assignment.Remove(cn, _AID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Assignment.Remove(cn, _AID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension();
readonly FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension();
[Serializable()]
partial class FolderAssignmentExtension : extensionBase
{
@@ -623,18 +549,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -663,61 +580,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 FolderAssignment)
if (destType == typeof(string) && value is FolderAssignment assignment)
{
// Return the ToString value
return ((FolderAssignment)value).ToString();
return assignment.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FolderAssignmentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FolderAssignment
// {
// partial class FolderAssignmentExtension : 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;
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 FolderAssignment this[Assignment myAssignment]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FolderAssignment this[Assignment myAssignment]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FolderAssignment> Items
{
get { return base.Items; }
}
public FolderAssignment GetItem(Assignment myAssignment)
public new System.Collections.Generic.IList<FolderAssignment> Items => base.Items;
public FolderAssignment GetItem(Assignment myAssignment)
{
foreach (FolderAssignment assignment in this)
if (assignment.AID == myAssignment.AID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FolderAssignment Add(Group myGroup, Role myRole) // One to Many
{
FolderAssignment assignment = FolderAssignment.New(myGroup, myRole);
this.Add(assignment);
Add(assignment);
return assignment;
}
public void Remove(Assignment myAssignment)
@@ -103,11 +95,8 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
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)
{
// run through all the child objects
// and if any are invalid then the
@@ -137,7 +126,7 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
@@ -161,11 +150,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FolderAssignments.GetByFolderID", ex);
}
}
private FolderAssignments()
{
MarkAsChild();
}
internal FolderAssignments(SafeDataReader dr)
private FolderAssignments() => MarkAsChild();
internal FolderAssignments(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +160,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; } }
~FolderAssignments()
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;
~FolderAssignments()
{
_CountFinalized++;
}
@@ -198,10 +180,10 @@ 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(FolderAssignment.Get(dr));
this.RaiseListChangedEvents = true;
Add(FolderAssignment.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FolderIDCriteria
@@ -219,7 +201,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FolderIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderAssignments.DataPortal_FetchFolderID", GetHashCode());
try
{
@@ -233,7 +215,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FolderAssignment(dr));
while (dr.Read()) Add(new FolderAssignment(dr));
}
}
}
@@ -243,11 +225,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderAssignments.DataPortal_FetchFolderID", ex);
throw new DbCslaException("FolderAssignments.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Folder folder)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +248,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
FolderAssignmentsPropertyDescriptor pd = new FolderAssignmentsPropertyDescriptor(this, i);
@@ -325,7 +296,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FolderAssignmentsPropertyDescriptor : vlnListPropertyDescriptor
{
private FolderAssignment Item { get { return (FolderAssignment)_Item; } }
public FolderAssignmentsPropertyDescriptor(FolderAssignments collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +304,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 FolderAssignments)
if (destType == typeof(string) && value is FolderAssignments assignments)
{
// Return department and department role separated by comma.
return ((FolderAssignments)value).Items.Count.ToString() + " Assignments";
return $"{assignments.Items.Count} Assignments";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -239,35 +233,13 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FolderDocVersion</returns>
protected override object GetIdValue()
{
return MyFolderDocVersionUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base FolderDocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FolderDocVersion</returns>
//public override string ToString()
//{
// return base.ToString();
//}
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;
}
protected override object GetIdValue() => MyFolderDocVersionUnique; // Absolutely Unique ID
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -297,8 +269,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()
@@ -321,84 +293,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// 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(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FolderDocVersionUnique = 0;
private static int FolderDocVersionUnique
{ get { return ++_FolderDocVersionUnique; } }
private int _MyFolderDocVersionUnique = FolderDocVersionUnique;
public int MyFolderDocVersionUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFolderDocVersionUnique; } }
internal static FolderDocVersion New(string name)
{
return new FolderDocVersion(name);
}
internal static FolderDocVersion Get(SafeDataReader dr)
{
return new FolderDocVersion(dr);
}
private static int FolderDocVersionUnique => ++_FolderDocVersionUnique;
private readonly int _MyFolderDocVersionUnique = FolderDocVersionUnique;
// Absolutely Unique ID - Editable FK
public int MyFolderDocVersionUnique => _MyFolderDocVersionUnique;
internal static FolderDocVersion New(string name) => new FolderDocVersion(name);
internal static FolderDocVersion Get(SafeDataReader dr) => new FolderDocVersion(dr);
public FolderDocVersion()
{
MarkAsChild();
@@ -428,15 +338,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;
~FolderDocVersion()
{
_CountFinalized++;
@@ -475,33 +381,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Add(cn, ref _VersionID, myFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = DocVersion.Add(cn, ref _VersionID, myFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Update(cn, ref _VersionID, myFolder.FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = DocVersion.Update(cn, ref _VersionID, myFolder.FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
DocVersion.Remove(cn, _VersionID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
DocVersion.Remove(cn, _VersionID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension();
readonly FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension();
[Serializable()]
partial class FolderDocVersionExtension : extensionBase
{
@@ -510,18 +426,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultVersionType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultVersionType => 0;
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)
{
@@ -550,61 +457,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 FolderDocVersion)
if (destType == typeof(string) && value is FolderDocVersion version)
{
// Return the ToString value
return ((FolderDocVersion)value).ToString();
return version.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FolderDocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FolderDocVersion
// {
// partial class FolderDocVersionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultVersionType
// {
// get { return 0; }
// }
// 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 FolderDocVersion this[DocVersion myDocVersion]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FolderDocVersion this[DocVersion myDocVersion]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FolderDocVersion> Items
{
get { return base.Items; }
}
public FolderDocVersion GetItem(DocVersion myDocVersion)
public new System.Collections.Generic.IList<FolderDocVersion> Items => base.Items;
public FolderDocVersion GetItem(DocVersion myDocVersion)
{
foreach (FolderDocVersion docVersion in this)
if (docVersion.VersionID == myDocVersion.VersionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FolderDocVersion Add(string name) // One to Many
{
FolderDocVersion docVersion = FolderDocVersion.New(name);
this.Add(docVersion);
Add(docVersion);
return docVersion;
}
public void Remove(DocVersion myDocVersion)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FolderDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FolderDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static FolderDocVersions New()
{
return new FolderDocVersions();
}
internal static FolderDocVersions Get(SafeDataReader dr)
{
return new FolderDocVersions(dr);
}
public static FolderDocVersions GetByFolderID(int folderID)
#endregion
#region Factory Methods
internal static FolderDocVersions New() => new FolderDocVersions();
internal static FolderDocVersions Get(SafeDataReader dr) => new FolderDocVersions(dr);
public static FolderDocVersions GetByFolderID(int folderID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FolderDocVersions.GetByFolderID", ex);
}
}
private FolderDocVersions()
{
MarkAsChild();
}
internal FolderDocVersions(SafeDataReader dr)
private FolderDocVersions() => MarkAsChild();
internal FolderDocVersions(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FolderDocVersions()
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;
~FolderDocVersions()
{
_CountFinalized++;
}
@@ -198,19 +174,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(FolderDocVersion.Get(dr));
this.RaiseListChangedEvents = true;
Add(FolderDocVersion.Get(dr));
RaiseListChangedEvents = true;
}
[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; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FolderIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderDocVersions.DataPortal_FetchFolderID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FolderDocVersion(dr));
while (dr.Read()) Add(new FolderDocVersion(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderDocVersions.DataPortal_FetchFolderID", ex);
throw new DbCslaException("FolderDocVersions.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Folder folder)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FolderDocVersionsPropertyDescriptor pd = new FolderDocVersionsPropertyDescriptor(this, i);
@@ -334,10 +296,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderDocVersions)
if (destType == typeof(string) && value is FolderDocVersions versions)
{
// Return department and department role separated by comma.
return ((FolderDocVersions)value).Items.Count.ToString() + " DocVersions";
return $"{versions.Items.Count} DocVersions";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class FolderInfo : ReadOnlyBase<FolderInfo>, IDisposable
{
public event FolderInfoEvent 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<FolderInfo> _CacheList = new List<FolderInfo>();
protected static void AddToCache(FolderInfo folderInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<FolderInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FolderInfo>>();
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 Folder _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -330,32 +314,19 @@ namespace VEPROMS.CSLA.Library
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._ChildFolderCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base FolderInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FolderInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FolderInfo.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 FolderInfo</returns>
protected override object GetIdValue()
{
return MyFolderInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFolderInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _FolderInfoUnique = 0;
private static int FolderInfoUnique
{ get { return ++_FolderInfoUnique; } }
private int _MyFolderInfoUnique = FolderInfoUnique;
public int MyFolderInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFolderInfoUnique; } }
private static int FolderInfoUnique => ++_FolderInfoUnique;
private readonly int _MyFolderInfoUnique = FolderInfoUnique;
// Absolutely Unique ID - Info
public int MyFolderInfoUnique => _MyFolderInfoUnique;
protected FolderInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -364,15 +335,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;
~FolderInfo()
{
_CountFinalized++;
@@ -389,10 +356,7 @@ namespace VEPROMS.CSLA.Library
if (listFolderInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list
}
public virtual Folder Get()
{
return _Editable = Folder.Get(_FolderID);
}
public virtual Folder Get() => _Editable = Folder.Get(_FolderID);
public static void Refresh(Folder tmp)
{
string key = tmp.FolderID.ToString();
@@ -405,28 +369,28 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
MyParent?.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
MyParent?.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
MyConnection?.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for new value
MyConnection?.RefreshConnectionFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
MyFormat?.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
MyFormat?.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
@@ -446,21 +410,21 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
MyParent?.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
MyParent?.RefreshChildFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
MyFormat?.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
MyFormat?.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
@@ -480,18 +444,18 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
MyParent?.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
MyParent?.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
MyConnection?.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for new value
MyConnection?.RefreshConnectionFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
@@ -513,8 +477,6 @@ namespace VEPROMS.CSLA.Library
public static FolderInfo Get(int folderID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
FolderInfo tmp = GetCachedByPrimaryKey(folderID);
@@ -553,13 +515,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FolderID;
public int FolderID
{ get { return _FolderID; } }
public PKCriteria(int folderID)
{
_FolderID = folderID;
}
private readonly int _FolderID;
public int FolderID => _FolderID;
public PKCriteria(int folderID) => _FolderID = folderID;
}
private void ReadData(SafeDataReader dr)
{
@@ -627,7 +585,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension();
readonly FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension();
[Serializable()]
partial class FolderInfoExtension : extensionBase { }
[Serializable()]
@@ -643,10 +601,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 FolderInfo)
if (destType == typeof(string) && value is FolderInfo info)
{
// Return the ToString value
return ((FolderInfo)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<FolderInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<FolderInfo> Items => base.Items;
public void AddEvents()
{
foreach (FolderInfo 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; } }
~FolderInfoList()
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;
~FolderInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FolderInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all FolderInfo.
/// </summary>
public static void Reset()
{
_FolderInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static FolderInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<FolderInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on FolderInfoList.Get", ex);
// }
//}
public static FolderInfoList GetChildren(int parentID)
/// <summary>
/// Reset the list of all FolderInfo.
/// </summary>
public static void Reset() => _FolderInfoList = null;
public static FolderInfoList GetChildren(int parentID)
{
try
{
@@ -194,11 +172,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ParentIDCriteria
{
public ParentIDCriteria(int parentID)
{
_ParentID = parentID;
}
private int _ParentID;
public ParentIDCriteria(int parentID) => _ParentID = parentID;
private int _ParentID;
public int ParentID
{
get { return _ParentID; }
@@ -238,11 +213,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class DBIDCriteria
{
public DBIDCriteria(int dbid)
{
_DBID = dbid;
}
private int _DBID;
public DBIDCriteria(int dbid) => _DBID = dbid;
private int _DBID;
public int DBID
{
get { return _DBID; }
@@ -282,11 +254,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int? formatID)
{
_FormatID = formatID;
}
private int? _FormatID;
public FormatIDCriteria(int? formatID) => _FormatID = formatID;
private int? _FormatID;
public int? FormatID
{
get { return _FormatID; }
@@ -323,41 +292,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 +337,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FolderInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private FolderInfo Item { get { return (FolderInfo)_Item; } }
public FolderInfoListPropertyDescriptor(FolderInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -388,10 +345,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 FolderInfoList)
if (destType == typeof(string) && value is FolderInfoList list)
{
// Return department and department role separated by comma.
return ((FolderInfoList)value).Items.Count.ToString() + " Folders";
return $"{list.Items.Count} Folders";
}
return base.ConvertTo(context, culture, value, destType);
}
+149 -313
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;
@@ -102,6 +100,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<Format> _CacheList = new List<Format>();
protected static void AddToCache(Format format)
{
@@ -111,7 +110,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Format>> _CacheByPrimaryKey = new Dictionary<string, List<Format>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Format>> _CacheByParentID_Name = new Dictionary<string, List<Format>>();
private static void ConvertListToDictionary()
{
@@ -154,15 +155,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 _nextFormatID = -1;
public static int NextFormatID
{
get { return _nextFormatID--; }
}
public static int NextFormatID => _nextFormatID--;
private int _FormatID;
[System.ComponentModel.DataObjectField(true, true)]
public int FormatID
@@ -367,10 +362,7 @@ namespace VEPROMS.CSLA.Library
return _FormatContents;
}
}
public void Reset_FormatContents()
{
_FormatContentCount = -1;
}
public void Reset_FormatContents() => _FormatContentCount = -1;
private int _FormatDocVersionCount = 0;
/// <summary>
/// Count of FormatDocVersions for this Format
@@ -402,10 +394,7 @@ namespace VEPROMS.CSLA.Library
return _FormatDocVersions;
}
}
public void Reset_FormatDocVersions()
{
_FormatDocVersionCount = -1;
}
public void Reset_FormatDocVersions() => _FormatDocVersionCount = -1;
private int _FormatFolderCount = 0;
/// <summary>
/// Count of FormatFolders for this Format
@@ -472,10 +461,7 @@ namespace VEPROMS.CSLA.Library
return _ChildFormats;
}
}
public void Reset_ChildFormats()
{
_ChildFormatCount = -1;
}
public void Reset_ChildFormats() => _ChildFormatCount = -1;
public override bool IsDirty
{
get
@@ -490,37 +476,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_FormatContents == null ? false : _FormatContents.IsDirtyList(list)) || (_FormatDocVersions == null ? false : _FormatDocVersions.IsDirtyList(list)) || (_FormatFolders == null ? false : _FormatFolders.IsDirtyList(list)) || (_ChildFormats == null ? false : _ChildFormats.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_FormatContents != null && _FormatContents.IsDirtyList(list)) || (_FormatDocVersions != null && _FormatDocVersions.IsDirtyList(list)) || (_FormatFolders != null && _FormatFolders.IsDirtyList(list)) || (_ChildFormats != null && _ChildFormats.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_FormatContents == null ? true : _FormatContents.IsValidList(list)) && (_FormatDocVersions == null ? true : _FormatDocVersions.IsValidList(list)) && (_FormatFolders == null ? true : _FormatFolders.IsValidList(list)) && (_ChildFormats == null ? true : _ChildFormats.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_FormatContents == null || _FormatContents.IsValidList(list)) && (_FormatDocVersions == null || _FormatDocVersions.IsValidList(list)) && (_FormatFolders == null || _FormatFolders.IsValidList(list)) && (_ChildFormats == null || _ChildFormats.IsValidList(list));
}
// CSLATODO: Replace base Format.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Format</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Format.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 Format</returns>
protected override object GetIdValue()
{
return MyFormatUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -552,8 +523,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()
@@ -566,8 +537,6 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 250));
//ValidationRules.AddRule(
// Csla.Validation.CommonRules.StringRequired, "Data");
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823));
@@ -591,37 +560,11 @@ namespace VEPROMS.CSLA.Library
_FormatExtension.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(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Description, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(GenMac, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Description, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(GenMac, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_FormatExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -629,58 +572,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_FormatExtension.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 += _FormatContentCount;
usedByCount += _FormatDocVersionCount;
usedByCount += _FormatFolderCount;
usedByCount += _ChildFormatCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatUnique = 0;
protected static int FormatUnique
{ get { return ++_FormatUnique; } }
private int _MyFormatUnique = FormatUnique;
public int MyFormatUnique // Absolutely Unique ID - Editable
{ get { return _MyFormatUnique; } }
protected static int FormatUnique => ++_FormatUnique;
private readonly int _MyFormatUnique = FormatUnique;
// Absolutely Unique ID - Editable
public int MyFormatUnique => _MyFormatUnique;
protected Format()
{/* require use of factory methods */
AddToCache(this);
@@ -689,15 +588,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;
~Format()
{
_CountFinalized++;
@@ -734,8 +629,6 @@ namespace VEPROMS.CSLA.Library
}
public static Format New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Format");
try
{
return DataPortal.Create<Format>();
@@ -811,8 +704,6 @@ namespace VEPROMS.CSLA.Library
}
public static Format Get(int formatID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
Format tmp = GetCachedByPrimaryKey(formatID);
@@ -835,8 +726,6 @@ namespace VEPROMS.CSLA.Library
}
public static Format GetByParentID_Name(int parentID, string name)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
Format tmp = GetCachedByParentID_Name(parentID, name);
@@ -862,15 +751,14 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Format(dr, parent);
return null;
}
internal Format(SafeDataReader dr)
{
ReadData(dr);
}
internal Format(SafeDataReader dr) => ReadData(dr);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private Format(SafeDataReader dr, Format parent)
{
ReadData(dr);
MarkAsChild();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal Format(SafeDataReader dr, int parentID)
{
ReadData(dr);
@@ -878,8 +766,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(int formatID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Format");
try
{
DataPortal.Delete(new PKCriteria(formatID));
@@ -891,12 +777,6 @@ namespace VEPROMS.CSLA.Library
}
public override Format Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Format");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Format");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Format");
try
{
BuildRefreshList();
@@ -916,23 +796,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FormatID;
public int FormatID
{ get { return _FormatID; } }
public PKCriteria(int formatID)
{
_FormatID = formatID;
}
private readonly int _FormatID;
public int FormatID => _FormatID;
public PKCriteria(int formatID) => _FormatID = formatID;
}
[Serializable()]
private class ParentID_NameCriteria
{
private int _ParentID;
public int ParentID
{ get { return _ParentID; } }
private string _Name;
public string Name
{ get { return _Name; } }
private readonly int _ParentID;
public int ParentID => _ParentID;
private readonly string _Name;
public string Name => _Name;
public ParentID_NameCriteria(int parentID, string name)
{
_ParentID = parentID;
@@ -1104,43 +978,50 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFormat";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int);
param_FormatID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_FormatID);
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
_FormatID = (int)cm.Parameters["@newFormatID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFormat";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FormatID);
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
_FormatID = (int)cm.Parameters["@newFormatID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_FormatFolders != null) _FormatFolders.Update(this);
if (_FormatContents != null) _FormatContents.Update(this);
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
if (_ChildFormats != null) _ChildFormats.Update(this);
_FormatFolders?.Update(this);
_FormatContents?.Update(this);
_FormatDocVersions?.Update(this);
_ChildFormats?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1171,11 +1052,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_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int);
param_FormatID.Direction = ParameterDirection.Output;
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FormatID);
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();
@@ -1220,41 +1105,46 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFormat";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
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 = "updateFormat";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
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
if (_FormatFolders != null) _FormatFolders.Update(this);
if (_FormatContents != null) _FormatContents.Update(this);
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
if (_ChildFormats != null) _ChildFormats.Update(this);
_FormatFolders?.Update(this);
_FormatContents?.Update(this);
_FormatDocVersions?.Update(this);
_ChildFormats?.Update(this);
}
catch (Exception ex)
{
@@ -1265,29 +1155,36 @@ 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 = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID);
else
_LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID);
else
_LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
if (_FormatFolders != null) _FormatFolders.Update(this);
if (_FormatContents != null) _FormatContents.Update(this);
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
if (_ChildFormats != null) _ChildFormats.Update(this);
_FormatFolders?.Update(this);
_FormatContents?.Update(this);
_FormatDocVersions?.Update(this);
_ChildFormats?.Update(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format format)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Format.Remove(cn, _FormatID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Format.Remove(cn, _FormatID);
}
MarkNew();
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -1313,8 +1210,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();
@@ -1399,16 +1298,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _FormatID;
private readonly int _FormatID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int formatID)
{
_FormatID = formatID;
}
public bool Exists => _exists;
public ExistsCommand(int formatID) => _FormatID = formatID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode());
@@ -1438,7 +1331,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
FormatExtension _FormatExtension = new FormatExtension();
readonly FormatExtension _FormatExtension = new FormatExtension();
[Serializable()]
partial class FormatExtension : extensionBase
{
@@ -1447,18 +1340,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
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)
{
@@ -1487,61 +1371,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 Format)
if (destType == typeof(string) && value is Format format)
{
// Return the ToString value
return ((Format)value).ToString();
return format.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Format
// {
// partial class FormatExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -182,10 +176,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatContent</returns>
protected override object GetIdValue()
{
return MyFormatContentUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatContentUnique; // Absolutely Unique ID
// CSLATODO: Replace base FormatContent.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -195,22 +186,12 @@ namespace VEPROMS.CSLA.Library
//{
// return base.ToString();
//}
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;
}
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -239,7 +220,7 @@ namespace VEPROMS.CSLA.Library
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -260,80 +241,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// 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(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Number, "<Role(s)>");
//AuthorizationRules.AllowWrite(Number, "<Role(s)>");
//AuthorizationRules.AllowRead(Text, "<Role(s)>");
//AuthorizationRules.AllowWrite(Text, "<Role(s)>");
//AuthorizationRules.AllowRead(Type, "<Role(s)>");
//AuthorizationRules.AllowWrite(Type, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatContentUnique = 0;
private static int FormatContentUnique
{ get { return ++_FormatContentUnique; } }
private int _MyFormatContentUnique = FormatContentUnique;
public int MyFormatContentUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFormatContentUnique; } }
internal static FormatContent New()
{
return new FormatContent();
}
internal static FormatContent Get(SafeDataReader dr)
{
return new FormatContent(dr);
}
private static int FormatContentUnique => ++_FormatContentUnique;
private readonly int _MyFormatContentUnique = FormatContentUnique;
// Absolutely Unique ID - Editable FK
public int MyFormatContentUnique => _MyFormatContentUnique;
internal static FormatContent New() => new FormatContent();
internal static FormatContent Get(SafeDataReader dr) => new FormatContent(dr);
public FormatContent()
{
MarkAsChild();
@@ -351,15 +274,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;
~FormatContent()
{
_CountFinalized++;
@@ -397,32 +316,42 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, myFormat, _Config, _DTS, _UserID);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, myFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format myFormat)
{
// 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"];
Content.Remove(cn, _ContentID);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Content.Remove(cn, _ContentID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FormatContentExtension _FormatContentExtension = new FormatContentExtension();
readonly FormatContentExtension _FormatContentExtension = new FormatContentExtension();
[Serializable()]
partial class FormatContentExtension : extensionBase
{
@@ -431,14 +360,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)
{
@@ -467,57 +390,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 FormatContent)
if (destType == typeof(string) && value is FormatContent content)
{
// Return the ToString value
return ((FormatContent)value).ToString();
return content.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatContentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FormatContent
// {
// partial class FormatContentExtension : 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 FormatContent this[Content myContent]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FormatContent this[Content myContent]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FormatContent> Items
{
get { return base.Items; }
}
public FormatContent GetItem(Content myContent)
public new System.Collections.Generic.IList<FormatContent> Items => base.Items;
public FormatContent GetItem(Content myContent)
{
foreach (FormatContent content in this)
if (content.ContentID == myContent.ContentID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FormatContent Add() // One to Many
{
FormatContent content = FormatContent.New();
this.Add(content);
Add(content);
return content;
}
public void Remove(Content myContent)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatContent child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatContent child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static FormatContents New()
{
return new FormatContents();
}
internal static FormatContents Get(SafeDataReader dr)
{
return new FormatContents(dr);
}
public static FormatContents GetByFormatID(int formatID)
#endregion
#region Factory Methods
internal static FormatContents New() => new FormatContents();
internal static FormatContents Get(SafeDataReader dr) => new FormatContents(dr);
public static FormatContents GetByFormatID(int formatID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FormatContents.GetByFormatID", ex);
}
}
private FormatContents()
{
MarkAsChild();
}
internal FormatContents(SafeDataReader dr)
private FormatContents() => MarkAsChild();
internal FormatContents(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatContents()
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;
~FormatContents()
{
_CountFinalized++;
}
@@ -198,19 +174,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(FormatContent.Get(dr));
this.RaiseListChangedEvents = true;
Add(FormatContent.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
private int _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
private int _FormatID;
public int FormatID
{
get { return _FormatID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatContents.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FormatContent(dr));
while (dr.Read()) Add(new FormatContent(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatContents.DataPortal_FetchFormatID", ex);
throw new DbCslaException("FormatContents.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatContentsPropertyDescriptor pd = new FormatContentsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatContentsPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatContent Item { get { return (FormatContent)_Item; } }
public FormatContentsPropertyDescriptor(FormatContents collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatContents)
if (destType == typeof(string) && value is FormatContents contents)
{
// Return department and department role separated by comma.
return ((FormatContents)value).Items.Count.ToString() + " Contents";
return $"{contents.Items.Count} Contents";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -329,10 +323,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatDocVersion</returns>
protected override object GetIdValue()
{
return MyFormatDocVersionUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatDocVersionUnique; // Absolutely Unique ID
// CSLATODO: Replace base FormatDocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -356,18 +347,15 @@ 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));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -398,8 +386,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -432,84 +420,22 @@ 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(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatDocVersionUnique = 0;
private static int FormatDocVersionUnique
{ get { return ++_FormatDocVersionUnique; } }
private int _MyFormatDocVersionUnique = FormatDocVersionUnique;
public int MyFormatDocVersionUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFormatDocVersionUnique; } }
internal static FormatDocVersion New(Folder myFolder, string name)
{
return new FormatDocVersion(myFolder, name);
}
internal static FormatDocVersion Get(SafeDataReader dr)
{
return new FormatDocVersion(dr);
}
private static int FormatDocVersionUnique => ++_FormatDocVersionUnique;
private readonly int _MyFormatDocVersionUnique = FormatDocVersionUnique;
// Absolutely Unique ID - Editable FK
public int MyFormatDocVersionUnique => _MyFormatDocVersionUnique;
internal static FormatDocVersion New(Folder myFolder, string name) => new FormatDocVersion(myFolder, name);
internal static FormatDocVersion Get(SafeDataReader dr) => new FormatDocVersion(dr);
public FormatDocVersion()
{
MarkAsChild();
@@ -540,15 +466,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;
~FormatDocVersion()
{
_CountFinalized++;
@@ -597,33 +519,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, myFormat, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, myFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
DocVersion.Remove(cn, _VersionID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
DocVersion.Remove(cn, _VersionID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension();
readonly FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension();
[Serializable()]
partial class FormatDocVersionExtension : extensionBase
{
@@ -632,18 +564,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultVersionType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultVersionType => 0;
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)
{
@@ -672,61 +595,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 FormatDocVersion)
if (destType == typeof(string) && value is FormatDocVersion version)
{
// Return the ToString value
return ((FormatDocVersion)value).ToString();
return version.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatDocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FormatDocVersion
// {
// partial class FormatDocVersionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultVersionType
// {
// get { return 0; }
// }
// 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 FormatDocVersion this[DocVersion myDocVersion]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FormatDocVersion this[DocVersion myDocVersion]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FormatDocVersion> Items
{
get { return base.Items; }
}
public FormatDocVersion GetItem(DocVersion myDocVersion)
public new System.Collections.Generic.IList<FormatDocVersion> Items => base.Items;
public FormatDocVersion GetItem(DocVersion myDocVersion)
{
foreach (FormatDocVersion docVersion in this)
if (docVersion.VersionID == myDocVersion.VersionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FormatDocVersion Add(Folder myFolder, string name) // One to Many
{
FormatDocVersion docVersion = FormatDocVersion.New(myFolder, name);
this.Add(docVersion);
Add(docVersion);
return docVersion;
}
public void Remove(DocVersion myDocVersion)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static FormatDocVersions New()
{
return new FormatDocVersions();
}
internal static FormatDocVersions Get(SafeDataReader dr)
{
return new FormatDocVersions(dr);
}
public static FormatDocVersions GetByFormatID(int formatID)
#endregion
#region Factory Methods
internal static FormatDocVersions New() => new FormatDocVersions();
internal static FormatDocVersions Get(SafeDataReader dr) => new FormatDocVersions(dr);
public static FormatDocVersions GetByFormatID(int formatID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FormatDocVersions.GetByFormatID", ex);
}
}
private FormatDocVersions()
{
MarkAsChild();
}
internal FormatDocVersions(SafeDataReader dr)
private FormatDocVersions() => MarkAsChild();
internal FormatDocVersions(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatDocVersions()
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;
~FormatDocVersions()
{
_CountFinalized++;
}
@@ -198,19 +174,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(FormatDocVersion.Get(dr));
this.RaiseListChangedEvents = true;
Add(FormatDocVersion.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
private int _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
private int _FormatID;
public int FormatID
{
get { return _FormatID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatDocVersions.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FormatDocVersion(dr));
while (dr.Read()) Add(new FormatDocVersion(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatDocVersions.DataPortal_FetchFormatID", ex);
throw new DbCslaException("FormatDocVersions.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatDocVersionsPropertyDescriptor pd = new FormatDocVersionsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatDocVersionsPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatDocVersion Item { get { return (FormatDocVersion)_Item; } }
public FormatDocVersionsPropertyDescriptor(FormatDocVersions collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatDocVersions)
if (destType == typeof(string) && value is FormatDocVersions versions)
{
// Return department and department role separated by comma.
return ((FormatDocVersions)value).Items.Count.ToString() + " DocVersions";
return $"{versions.Items.Count} DocVersions";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -321,19 +315,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatFolder</returns>
protected override object GetIdValue()
{
return MyFormatFolderUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base FormatFolder.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FormatFolder</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyFormatFolderUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -348,18 +330,15 @@ 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)) || (_MyConnection == null ? false : _MyConnection.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list)) || (_MyConnection != null && _MyConnection.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyConnection == null ? true : _MyConnection.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list)) && (_MyConnection == null || _MyConnection.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -390,8 +369,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()
@@ -439,86 +418,22 @@ 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(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DBID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DBID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatFolderUnique = 0;
private static int FormatFolderUnique
{ get { return ++_FormatFolderUnique; } }
private int _MyFormatFolderUnique = FormatFolderUnique;
public int MyFormatFolderUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFormatFolderUnique; } }
internal static FormatFolder New(Folder myParent, string name, string shortName)
{
return new FormatFolder(myParent, name, shortName);
}
internal static FormatFolder Get(SafeDataReader dr)
{
return new FormatFolder(dr);
}
private static int FormatFolderUnique => ++_FormatFolderUnique;
private readonly int _MyFormatFolderUnique = FormatFolderUnique;
// Absolutely Unique ID - Editable FK
public int MyFormatFolderUnique => _MyFormatFolderUnique;
internal static FormatFolder New(Folder myParent, string name, string shortName) => new FormatFolder(myParent, name, shortName);
internal static FormatFolder Get(SafeDataReader dr) => new FormatFolder(dr);
public FormatFolder()
{
MarkAsChild();
@@ -552,15 +467,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;
~FormatFolder()
{
_CountFinalized++;
@@ -607,33 +518,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Folder.Remove(cn, _FolderID);
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
Folder.Remove(cn, _FolderID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension();
readonly FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension();
[Serializable()]
partial class FormatFolderExtension : extensionBase
{
@@ -642,22 +563,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual int DefaultDBID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
public virtual int DefaultDBID => 1;
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)
{
@@ -686,65 +595,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 FormatFolder)
if (destType == typeof(string) && value is FormatFolder folder)
{
// Return the ToString value
return ((FormatFolder)value).ToString();
return folder.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatFolderExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FormatFolder
// {
// partial class FormatFolderExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual int DefaultDBID
// {
// get { return 1; }
// }
// 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;
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 FormatFolder this[Folder myFolder]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FormatFolder this[Folder myFolder]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FormatFolder> Items
{
get { return base.Items; }
}
public FormatFolder GetItem(Folder myFolder)
public new System.Collections.Generic.IList<FormatFolder> Items => base.Items;
public FormatFolder GetItem(Folder myFolder)
{
foreach (FormatFolder folder in this)
if (folder.FolderID == myFolder.FolderID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FormatFolder Add(Folder myParent, string name, string shortName) // One to Many
{
FormatFolder folder = FormatFolder.New(myParent, name, shortName);
this.Add(folder);
Add(folder);
return folder;
}
public void Remove(Folder myFolder)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatFolder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatFolder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return (hasBrokenRules?.BrokenRules);
}
}
#endregion
#region Factory Methods
internal static FormatFolders New()
{
return new FormatFolders();
}
internal static FormatFolders Get(SafeDataReader dr)
{
return new FormatFolders(dr);
}
public static FormatFolders GetByFormatID(int formatID)
#endregion
#region Factory Methods
internal static FormatFolders New() => new FormatFolders();
internal static FormatFolders Get(SafeDataReader dr) => new FormatFolders(dr);
public static FormatFolders GetByFormatID(int formatID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FormatFolders.GetByFormatID", ex);
}
}
private FormatFolders()
{
MarkAsChild();
}
internal FormatFolders(SafeDataReader dr)
private FormatFolders() => MarkAsChild();
internal FormatFolders(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatFolders()
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;
~FormatFolders()
{
_CountFinalized++;
}
@@ -198,19 +174,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(FormatFolder.Get(dr));
this.RaiseListChangedEvents = true;
Add(FormatFolder.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
private int _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
private int _FormatID;
public int FormatID
{
get { return _FormatID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatFolders.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FormatFolder(dr));
while (dr.Read()) Add(new FormatFolder(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatFolders.DataPortal_FetchFormatID", ex);
throw new DbCslaException("FormatFolders.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,39 @@ 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()
#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()
{ 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()
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
FormatFoldersPropertyDescriptor pd = new FormatFoldersPropertyDescriptor(this, i);
@@ -325,7 +288,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatFoldersPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatFolder Item { get { return (FormatFolder)_Item; } }
public FormatFoldersPropertyDescriptor(FormatFolders collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +296,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatFolders)
if (destType == typeof(string) && value is FormatFolders folders)
{
// Return department and department role separated by comma.
return ((FormatFolders)value).Items.Count.ToString() + " Folders";
return $"{folders.Items.Count} Folders";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class FormatInfo : ReadOnlyBase<FormatInfo>, IDisposable
{
public event FormatInfoEvent 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<FormatInfo> _CacheList = new List<FormatInfo>();
protected static void AddToCache(FormatInfo formatInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<FormatInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FormatInfo>>();
private static void ConvertListToDictionary()
{
@@ -81,21 +78,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Format _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FormatID;
[System.ComponentModel.DataObjectField(true, true)]
public int FormatID
@@ -342,32 +326,19 @@ namespace VEPROMS.CSLA.Library
foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()])
tmp._ChildFormatCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base FormatInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FormatInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FormatInfo.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 FormatInfo</returns>
protected override object GetIdValue()
{
return MyFormatInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _FormatInfoUnique = 0;
private static int FormatInfoUnique
{ get { return ++_FormatInfoUnique; } }
private int _MyFormatInfoUnique = FormatInfoUnique;
public int MyFormatInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFormatInfoUnique; } }
private static int FormatInfoUnique => ++_FormatInfoUnique;
private readonly int _MyFormatInfoUnique = FormatInfoUnique;
// Absolutely Unique ID - Info
public int MyFormatInfoUnique => _MyFormatInfoUnique;
protected FormatInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -376,15 +347,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;
~FormatInfo()
{
_CountFinalized++;
@@ -417,11 +384,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFormats(); // Update List for old value
MyParent?.RefreshChildFormats(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFormats(); // Update List for new value
MyParent?.RefreshChildFormats(); // Update List for new value
_Name = tmp.Name;
_Description = tmp.Description;
_Data = tmp.Data;
@@ -434,8 +401,6 @@ namespace VEPROMS.CSLA.Library
}
public static FormatInfo Get(int formatID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
FormatInfo tmp = GetCachedByPrimaryKey(formatID);
@@ -474,13 +439,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FormatID;
public int FormatID
{ get { return _FormatID; } }
public PKCriteria(int formatID)
{
_FormatID = formatID;
}
private readonly int _FormatID;
public int FormatID => _FormatID;
public PKCriteria(int formatID) => _FormatID = formatID;
}
public static string _Failed = null;
public static string Failed
@@ -564,7 +525,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension();
readonly FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension();
[Serializable()]
partial class FormatInfoExtension : extensionBase { }
[Serializable()]
@@ -580,10 +541,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 FormatInfo)
if (destType == typeof(string) && value is FormatInfo info)
{
// Return the ToString value
return ((FormatInfo)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<FormatInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<FormatInfo> Items => base.Items;
public void AddEvents()
{
foreach (FormatInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatInfoList()
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;
~FormatInfoList()
{
_CountFinalized++;
}
@@ -105,18 +98,6 @@ namespace VEPROMS.CSLA.Library
_FormatInfoList = null;
_SortedFormatInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static FormatInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<FormatInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on FormatInfoList.Get", ex);
// }
//}
public static FormatInfoList GetChildren(int parentID)
{
try
@@ -137,7 +118,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -151,7 +132,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new FormatInfo(dr));
while (dr.Read()) Add(new FormatInfo(dr));
IsReadOnly = true;
}
}
@@ -170,16 +151,13 @@ namespace VEPROMS.CSLA.Library
System.Windows.Forms.MessageBox.Show(sbMsg.ToString(), "Update Stored Procedures", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
throw new DbCslaException("FormatInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class ParentIDCriteria
{
public ParentIDCriteria(int parentID)
{
_ParentID = parentID;
}
private int _ParentID;
public ParentIDCriteria(int parentID) => _ParentID = parentID;
private int _ParentID;
public int ParentID
{
get { return _ParentID; }
@@ -188,7 +166,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ParentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_FetchParentID", GetHashCode());
try
{
@@ -203,7 +181,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new FormatInfo(dr));
while (dr.Read()) Add(new FormatInfo(dr));
IsReadOnly = true;
}
}
@@ -214,48 +192,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfoList.DataPortal_FetchParentID", ex);
throw new DbCslaException("FormatInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatInfoListPropertyDescriptor pd = new FormatInfoListPropertyDescriptor(this, i);
@@ -272,7 +239,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatInfo Item { get { return (FormatInfo)_Item; } }
public FormatInfoListPropertyDescriptor(FormatInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -281,10 +247,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 FormatInfoList)
if (destType == typeof(string) && value is FormatInfoList list)
{
// Return department and department role separated by comma.
return ((FormatInfoList)value).Items.Count.ToString() + " Formats";
return $"{list.Items.Count} Formats";
}
return base.ConvertTo(context, culture, value, destType);
}