CSLA - Is

This commit is contained in:
2026-09-10 16:02:04 -04:00
parent 8674b93723
commit e41a4ea65d
21 changed files with 1226 additions and 2954 deletions
+110 -259
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty) if (IsDirty)
refreshImages.Add(this); refreshImages.Add(this);
} }
private void ClearRefreshList() private void ClearRefreshList() => _RefreshImages = new List<Image>();
{
_RefreshImages = new List<Image>();
}
private void BuildRefreshList() private void BuildRefreshList()
{ {
ClearRefreshList(); ClearRefreshList();
@@ -56,16 +51,18 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Image> _CacheList = new List<Image>(); private static List<Image> _CacheList = new List<Image>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
protected static void AddToCache(Image image) protected static void AddToCache(Image image)
{ {
// B2021-147 commented out to fix out of memory bug
//if (!_CacheList.Contains(image)) _CacheList.Add(image); // In AddToCache
} }
protected static void RemoveFromCache(Image image) protected static void RemoveFromCache(Image image)
{ {
while (_CacheList.Contains(image)) _CacheList.Remove(image); // In RemoveFromCache while (_CacheList.Contains(image)) _CacheList.Remove(image); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Image>> _CacheByPrimaryKey = new Dictionary<string, List<Image>>(); private static Dictionary<string, List<Image>> _CacheByPrimaryKey = new Dictionary<string, List<Image>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -91,10 +88,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _ContentID; private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int ContentID public int ContentID
@@ -232,40 +226,18 @@ namespace VEPROMS.CSLA.Library
} }
} }
private byte[] _LastChanged = new byte[8];//timestamp private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty public override bool IsDirty => base.IsDirty;
{ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
get { return base.IsDirty; } public bool IsDirtyList(List<object> list) => base.IsDirty;
} public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
public bool IsDirtyList(List<object> list) [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
{ public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
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 Image.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Image</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Image.GetIdValue to assure that the ID returned is unique // CSLATODO: Check Image.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current Image</returns> /// <returns>A Unique ID for the current Image</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyImageUnique; // Absolutely Unique ID
{
return MyImageUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -293,8 +265,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -321,35 +293,11 @@ namespace VEPROMS.CSLA.Library
_ImageExtension.AddInstanceValidationRules(ValidationRules); _ImageExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(ImageType, "<Role(s)>");
//AuthorizationRules.AllowRead(FileName, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ImageType, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileName, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_ImageExtension.AddAuthorizationRules(AuthorizationRules); _ImageExtension.AddAuthorizationRules(AuthorizationRules);
} }
protected override void AddInstanceAuthorizationRules() protected override void AddInstanceAuthorizationRules()
@@ -357,42 +305,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
_ImageExtension.AddInstanceAuthorizationRules(AuthorizationRules); _ImageExtension.AddInstanceAuthorizationRules(AuthorizationRules);
} }
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ImageUnique = 0; private static int _ImageUnique = 0;
protected static int ImageUnique protected static int ImageUnique => ++_ImageUnique;
{ get { return ++_ImageUnique; } } private readonly int _MyImageUnique = ImageUnique;
private int _MyImageUnique = ImageUnique; // Absolutely Unique ID - Editable
public int MyImageUnique // Absolutely Unique ID - Editable public int MyImageUnique => _MyImageUnique;
{ get { return _MyImageUnique; } }
protected Image() protected Image()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -401,15 +321,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~Image() ~Image()
{ {
_CountFinalized++; _CountFinalized++;
@@ -434,8 +350,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Image New() public static Image New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Image");
try try
{ {
return DataPortal.Create<Image>(); return DataPortal.Create<Image>();
@@ -516,8 +430,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Image Get(int contentID) public static Image Get(int contentID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Image");
try try
{ {
Image tmp = GetCachedByPrimaryKey(contentID); Image tmp = GetCachedByPrimaryKey(contentID);
@@ -543,14 +455,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Image(dr); if (dr.Read()) return new Image(dr);
return null; return null;
} }
internal Image(SafeDataReader dr) internal Image(SafeDataReader dr) => ReadData(dr);
{
ReadData(dr);
}
public static void Delete(int contentID) public static void Delete(int contentID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Image");
try try
{ {
DataPortal.Delete(new PKCriteria(contentID)); DataPortal.Delete(new PKCriteria(contentID));
@@ -562,12 +469,6 @@ namespace VEPROMS.CSLA.Library
} }
public override Image Save() public override Image Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Image");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Image");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Image");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -587,13 +488,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _ContentID; private readonly int _ContentID;
public int ContentID public int ContentID => _ContentID;
{ get { return _ContentID; } } public PKCriteria(int contentID) => _ContentID = contentID;
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
} }
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal // CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()] [RunLocal()]
@@ -693,32 +590,37 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert() internal void SQLInsert()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "addImage"; cm.CommandType = CommandType.StoredProcedure;
// Input All Fields - Except Calculated Columns cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@ContentID", ContentID); cm.CommandText = "addImage";
cm.Parameters.AddWithValue("@ImageType", _ImageType); // Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@FileName", _FileName); cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@Data", _Data); cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@Config", _Config); cm.Parameters.AddWithValue("@FileName", _FileName);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@Config", _Config);
// Output Calculated Columns if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); cm.Parameters.AddWithValue("@UserID", _UserID);
param_LastChanged.Direction = ParameterDirection.Output; // Output Calculated Columns
cm.Parameters.Add(param_LastChanged); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
// CSLATODO: Define any additional output parameters {
cm.ExecuteNonQuery(); Direction = ParameterDirection.Output
// Save all values being returned from the Procedure };
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
} }
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLInsert", GetHashCode());
@@ -750,8 +652,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
param_LastChanged.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged); cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
@@ -795,33 +699,38 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLUpdate", GetHashCode());
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) if (base.IsDirty)
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "updateImage"; cm.CommandType = CommandType.StoredProcedure;
// All Fields including Calculated Fields cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@ContentID", ContentID); cm.CommandText = "updateImage";
cm.Parameters.AddWithValue("@ImageType", _ImageType); // All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FileName", _FileName); cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@Data", _Data); cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@Config", _Config); cm.Parameters.AddWithValue("@FileName", _FileName);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
// Output Calculated Columns cm.Parameters.AddWithValue("@UserID", _UserID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
param_LastChanged.Direction = ParameterDirection.Output; // Output Calculated Columns
cm.Parameters.Add(param_LastChanged); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
// CSLATODO: Define any additional output parameters {
cm.ExecuteNonQuery(); Direction = ParameterDirection.Output
// Save all values being returned from the Procedure };
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
} }
} }
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
} }
@@ -834,14 +743,17 @@ namespace VEPROMS.CSLA.Library
} }
internal void Update(Content content) internal void Update(Content content)
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
if (base.IsDirty) if (base.IsDirty)
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (IsNew) {
_LastChanged = Image.Add(cn, content, _ImageType, _FileName, _Data, _Config, _DTS, _UserID); if (IsNew)
else _LastChanged = Image.Add(cn, content, _ImageType, _FileName, _Data, _Config, _DTS, _UserID);
_LastChanged = Image.Update(cn, content.ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, ref _LastChanged); else
_LastChanged = Image.Update(cn, content.ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
} }
@@ -866,8 +778,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged); cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
param_LastChanged.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged); cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
@@ -952,16 +866,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private int _ContentID; private readonly int _ContentID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(int contentID) => _ContentID = contentID;
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Execute", GetHashCode());
@@ -991,7 +899,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ImageExtension _ImageExtension = new ImageExtension(); readonly ImageExtension _ImageExtension = new ImageExtension();
[Serializable()] [Serializable()]
partial class ImageExtension : extensionBase partial class ImageExtension : extensionBase
{ {
@@ -1000,18 +908,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual int DefaultImageType public virtual int DefaultImageType => 1;
{ public virtual DateTime DefaultDTS => DateTime.Now;
get { return 1; } public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -1040,61 +939,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is Image) if (destType == typeof(string) && value is Image myimage)
{ {
// Return the ToString value // Return the ToString value
return ((Image)value).ToString(); return myimage.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ImageExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Image
// {
// partial class ImageExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultImageType
// {
// 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 */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty) if (IsDirty)
refreshImageAudits.Add(this); refreshImageAudits.Add(this);
} }
private void ClearRefreshList() private void ClearRefreshList() => _RefreshImageAudits = new List<ImageAudit>();
{
_RefreshImageAudits = new List<ImageAudit>();
}
private void BuildRefreshList() private void BuildRefreshList()
{ {
ClearRefreshList(); ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ImageAudit> _CacheList = new List<ImageAudit>(); private static List<ImageAudit> _CacheList = new List<ImageAudit>();
protected static void AddToCache(ImageAudit imageAudit) protected static void AddToCache(ImageAudit imageAudit)
{ {
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(imageAudit)) _CacheList.Remove(imageAudit); // In RemoveFromCache while (_CacheList.Contains(imageAudit)) _CacheList.Remove(imageAudit); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ImageAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ImageAudit>>(); private static Dictionary<string, List<ImageAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ImageAudit>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private static int _nextAuditID = -1; private static int _nextAuditID = -1;
public static int NextAuditID public static int NextAuditID => _nextAuditID--;
{
get { return _nextAuditID--; }
}
private long _AuditID; private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public long AuditID public long AuditID
@@ -256,40 +247,14 @@ namespace VEPROMS.CSLA.Library
} }
} }
} }
public override bool IsDirty public override bool IsDirty => base.IsDirty;
{ public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base ImageAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ImageAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ImageAudit.GetIdValue to assure that the ID returned is unique // CSLATODO: Check ImageAudit.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ImageAudit</returns> /// <returns>A Unique ID for the current ImageAudit</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyImageAuditUnique; // Absolutely Unique ID
{
return MyImageAuditUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -317,8 +282,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -345,39 +310,11 @@ namespace VEPROMS.CSLA.Library
_ImageAuditExtension.AddInstanceValidationRules(ValidationRules); _ImageAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(ImageType, "<Role(s)>");
//AuthorizationRules.AllowRead(FileName, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ImageType, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileName, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_ImageAuditExtension.AddAuthorizationRules(AuthorizationRules); _ImageAuditExtension.AddAuthorizationRules(AuthorizationRules);
} }
protected override void AddInstanceAuthorizationRules() protected override void AddInstanceAuthorizationRules()
@@ -385,42 +322,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
_ImageAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules); _ImageAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
} }
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ImageAuditUnique = 0; private static int _ImageAuditUnique = 0;
protected static int ImageAuditUnique protected static int ImageAuditUnique => ++_ImageAuditUnique;
{ get { return ++_ImageAuditUnique; } } private readonly int _MyImageAuditUnique = ImageAuditUnique;
private int _MyImageAuditUnique = ImageAuditUnique; // Absolutely Unique ID - Editable
public int MyImageAuditUnique // Absolutely Unique ID - Editable public int MyImageAuditUnique => _MyImageAuditUnique;
{ get { return _MyImageAuditUnique; } }
protected ImageAudit() protected ImageAudit()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -429,15 +338,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ImageAudit() ~ImageAudit()
{ {
_CountFinalized++; _CountFinalized++;
@@ -462,8 +367,6 @@ namespace VEPROMS.CSLA.Library
} }
public static ImageAudit New() public static ImageAudit New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ImageAudit");
try try
{ {
return DataPortal.Create<ImageAudit>(); return DataPortal.Create<ImageAudit>();
@@ -516,8 +419,6 @@ namespace VEPROMS.CSLA.Library
} }
public static ImageAudit Get(long auditID) public static ImageAudit Get(long auditID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a ImageAudit");
try try
{ {
ImageAudit tmp = GetCachedByPrimaryKey(auditID); ImageAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -543,14 +444,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new ImageAudit(dr); if (dr.Read()) return new ImageAudit(dr);
return null; return null;
} }
internal ImageAudit(SafeDataReader dr) internal ImageAudit(SafeDataReader dr) => ReadData(dr);
{
ReadData(dr);
}
public static void Delete(long auditID) public static void Delete(long auditID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ImageAudit");
try try
{ {
DataPortal.Delete(new PKCriteria(auditID)); DataPortal.Delete(new PKCriteria(auditID));
@@ -562,12 +458,6 @@ namespace VEPROMS.CSLA.Library
} }
public override ImageAudit Save() public override ImageAudit Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ImageAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ImageAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a ImageAudit");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -587,13 +477,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private long _AuditID; private readonly long _AuditID;
public long AuditID public long AuditID => _AuditID;
{ get { return _AuditID; } } public PKCriteria(long auditID) => _AuditID = auditID;
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
} }
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal // CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()] [RunLocal()]
@@ -692,33 +578,38 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert() internal void SQLInsert()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "addImageAudit"; cm.CommandType = CommandType.StoredProcedure;
// Input All Fields - Except Calculated Columns cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@ContentID", _ContentID); cm.CommandText = "addImageAudit";
cm.Parameters.AddWithValue("@ImageType", _ImageType); // Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@FileName", _FileName); cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Data", _Data); cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@Config", _Config); cm.Parameters.AddWithValue("@FileName", _FileName);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
// Output Calculated Columns cm.Parameters.AddWithValue("@UserID", _UserID);
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
param_AuditID.Direction = ParameterDirection.Output; // Output Calculated Columns
cm.Parameters.Add(param_AuditID); SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
// CSLATODO: Define any additional output parameters {
cm.ExecuteNonQuery(); Direction = ParameterDirection.Output
// Save all values being returned from the Procedure };
_AuditID = (long)cm.Parameters["@newAuditID"].Value; cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
} }
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLInsert", GetHashCode());
@@ -751,8 +642,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
param_AuditID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID); cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
@@ -797,30 +690,33 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLUpdate", GetHashCode());
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) if (base.IsDirty)
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "updateImageAudit"; cm.CommandType = CommandType.StoredProcedure;
// All Fields including Calculated Fields cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@AuditID", _AuditID); cm.CommandText = "updateImageAudit";
cm.Parameters.AddWithValue("@ContentID", _ContentID); // All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ImageType", _ImageType); cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@FileName", _FileName); cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Data", _Data); cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@Config", _Config); cm.Parameters.AddWithValue("@FileName", _FileName);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
// Output Calculated Columns cm.Parameters.AddWithValue("@UserID", _UserID);
// CSLATODO: Define any additional output parameters cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
cm.ExecuteNonQuery(); // Output Calculated Columns
// Save all values being returned from the Procedure // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
} }
} }
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
} }
@@ -833,14 +729,17 @@ namespace VEPROMS.CSLA.Library
} }
internal void Update() internal void Update()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
if (base.IsDirty) if (base.IsDirty)
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (IsNew) {
ImageAudit.Add(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus); if (IsNew)
else ImageAudit.Add(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus);
ImageAudit.Update(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus); else
ImageAudit.Update(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus);
}
MarkOld(); MarkOld();
} }
} }
@@ -934,7 +833,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension(); readonly ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension();
[Serializable()] [Serializable()]
partial class ImageAuditExtension : extensionBase partial class ImageAuditExtension : extensionBase
{ {
@@ -971,49 +870,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ImageAudit) if (destType == typeof(string) && value is ImageAudit audit)
{ {
// Return the ToString value // Return the ToString value
return ((ImageAudit)value).ToString(); return audit.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ImageAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ImageAudit
// {
// partial class ImageAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ImageAuditInfo : ReadOnlyBase<ImageAuditInfo>, IDisposable public partial class ImageAuditInfo : ReadOnlyBase<ImageAuditInfo>, IDisposable
{ {
public event ImageAuditInfoEvent Changed; public event ImageAuditInfoEvent Changed;
private void OnChange() private void OnChange() => Changed?.Invoke(this);
{
if (Changed != null) Changed(this);
}
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ImageAuditInfo> _CacheList = new List<ImageAuditInfo>(); private static List<ImageAuditInfo> _CacheList = new List<ImageAuditInfo>();
protected static void AddToCache(ImageAuditInfo imageAuditInfo) protected static void AddToCache(ImageAuditInfo imageAuditInfo)
{ {
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(imageAuditInfo)) _CacheList.Remove(imageAuditInfo); // In RemoveFromCache while (_CacheList.Contains(imageAuditInfo)) _CacheList.Remove(imageAuditInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ImageAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ImageAuditInfo>>(); private static Dictionary<string, List<ImageAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ImageAuditInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
protected ImageAudit _Editable; protected ImageAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID; private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public long AuditID public long AuditID
@@ -171,32 +155,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus; return _DeleteStatus;
} }
} }
// CSLATODO: Replace base ImageAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ImageAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ImageAuditInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check ImageAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ImageAuditInfo</returns> /// <returns>A Unique ID for the current ImageAuditInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyImageAuditInfoUnique; // Absolutely Unique ID
{
return MyImageAuditInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ImageAuditInfoUnique = 0; private static int _ImageAuditInfoUnique = 0;
private static int ImageAuditInfoUnique private static int ImageAuditInfoUnique => ++_ImageAuditInfoUnique;
{ get { return ++_ImageAuditInfoUnique; } } private readonly int _MyImageAuditInfoUnique = ImageAuditInfoUnique;
private int _MyImageAuditInfoUnique = ImageAuditInfoUnique; // Absolutely Unique ID - Info
public int MyImageAuditInfoUnique // Absolutely Unique ID - Info public int MyImageAuditInfoUnique => _MyImageAuditInfoUnique;
{ get { return _MyImageAuditInfoUnique; } }
protected ImageAuditInfo() protected ImageAuditInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -205,15 +176,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ImageAuditInfo() ~ImageAuditInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -230,10 +197,7 @@ namespace VEPROMS.CSLA.Library
if (listImageAuditInfo.Count == 0) // If there are no items left in the list if (listImageAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
} }
public virtual ImageAudit Get() public virtual ImageAudit Get() => _Editable = ImageAudit.Get(_AuditID);
{
return _Editable = ImageAudit.Get(_AuditID);
}
public static void Refresh(ImageAudit tmp) public static void Refresh(ImageAudit tmp)
{ {
string key = tmp.AuditID.ToString(); string key = tmp.AuditID.ToString();
@@ -257,8 +221,6 @@ namespace VEPROMS.CSLA.Library
} }
public static ImageAuditInfo Get(long auditID) public static ImageAuditInfo Get(long auditID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a ImageAudit");
try try
{ {
ImageAuditInfo tmp = GetCachedByPrimaryKey(auditID); ImageAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -297,13 +259,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private long _AuditID; private readonly long _AuditID;
public long AuditID public long AuditID => _AuditID;
{ get { return _AuditID; } } public PKCriteria(long auditID) => _AuditID = auditID;
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -366,7 +324,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension(); readonly ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension();
[Serializable()] [Serializable()]
partial class ImageAuditInfoExtension : extensionBase { } partial class ImageAuditInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -382,10 +340,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ImageAuditInfo) if (destType == typeof(string) && value is ImageAuditInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((ImageAuditInfo)value).ToString(); return info.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{ {
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
internal new IList<ImageAuditInfo> Items internal new IList<ImageAuditInfo> Items => base.Items;
{ get { return base.Items; } } public void AddEvents()
public void AddEvents()
{ {
foreach (ImageAuditInfo tmp in this) foreach (ImageAuditInfo tmp in this)
{ {
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ImageAuditInfoList()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ImageAuditInfoList()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ImageAuditInfoList.Get", ex); throw new DbCslaException("Error on ImageAuditInfoList.Get", ex);
} }
} }
/// <summary> /// <summary>
/// Reset the list of all ImageAuditInfo. /// Reset the list of all ImageAuditInfo.
/// </summary> /// </summary>
public static void Reset() public static void Reset() => _ImageAuditInfoList = null;
{ private ImageAuditInfoList()
_ImageAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ImageAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ImageAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ImageAuditInfoList.Get", ex);
// }
//}
private ImageAuditInfoList()
{ /* require use of factory methods */ } { /* require use of factory methods */ }
#endregion #endregion
#region Data Access Portal #region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
} }
this.RaiseListChangedEvents = true; this.RaiseListChangedEvents = true;
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ImageAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class ImageAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ImageAuditInfo Item { get { return (ImageAuditInfo)_Item; } }
public ImageAuditInfoListPropertyDescriptor(ImageAuditInfoList collection, int index) : base(collection, index) { ;} public ImageAuditInfoListPropertyDescriptor(ImageAuditInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ImageAuditInfoList) if (destType == typeof(string) && value is ImageAuditInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ImageAuditInfoList)value).Items.Count.ToString() + " ImageAudits"; return $"{list.Items.Count} ImageAudits";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ImageInfo : ReadOnlyBase<ImageInfo>, IDisposable public partial class ImageInfo : ReadOnlyBase<ImageInfo>, IDisposable
{ {
public event ImageInfoEvent Changed; public event ImageInfoEvent Changed;
private void OnChange() private void OnChange() => Changed?.Invoke(this);
{
if (Changed != null) Changed(this);
}
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ImageInfo> _CacheList = new List<ImageInfo>(); private static List<ImageInfo> _CacheList = new List<ImageInfo>();
protected static void AddToCache(ImageInfo imageInfo) protected static void AddToCache(ImageInfo imageInfo)
{ {
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(imageInfo)) _CacheList.Remove(imageInfo); // In RemoveFromCache while (_CacheList.Contains(imageInfo)) _CacheList.Remove(imageInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ImageInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ImageInfo>>(); private static Dictionary<string, List<ImageInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ImageInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -70,21 +67,8 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
protected Image _Editable; protected Image _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID; private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int ContentID public int ContentID
@@ -164,32 +148,19 @@ namespace VEPROMS.CSLA.Library
return _UserID; return _UserID;
} }
} }
// CSLATODO: Replace base ImageInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ImageInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ImageInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check ImageInfo.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ImageInfo</returns> /// <returns>A Unique ID for the current ImageInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyImageInfoUnique; // Absolutely Unique ID
{
return MyImageInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ImageInfoUnique = 0; private static int _ImageInfoUnique = 0;
private static int ImageInfoUnique private static int ImageInfoUnique => ++_ImageInfoUnique;
{ get { return ++_ImageInfoUnique; } } private readonly int _MyImageInfoUnique = ImageInfoUnique;
private int _MyImageInfoUnique = ImageInfoUnique; // Absolutely Unique ID - Info
public int MyImageInfoUnique // Absolutely Unique ID - Info public int MyImageInfoUnique => _MyImageInfoUnique;
{ get { return _MyImageInfoUnique; } }
protected ImageInfo() protected ImageInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -198,15 +169,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ImageInfo() ~ImageInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -223,10 +190,7 @@ namespace VEPROMS.CSLA.Library
if (listImageInfo.Count == 0) // If there are no items left in the list if (listImageInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
} }
public virtual Image Get() public virtual Image Get() => _Editable = Image.Get(_ContentID);
{
return _Editable = Image.Get(_ContentID);
}
public static void Refresh(Image tmp) public static void Refresh(Image tmp)
{ {
string key = tmp.ContentID.ToString(); string key = tmp.ContentID.ToString();
@@ -244,20 +208,10 @@ namespace VEPROMS.CSLA.Library
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
_ImageInfoExtension.Refresh(this); _ImageInfoExtension.Refresh(this);
//RHM Removed 20090724 - Duplicates function of code above.
// - Dispose caused error when a new step was added.
// - Resequence of transitions did not work properly.
// if(_MyContent != null)
// {
// _MyContent.Dispose();// Dispose related value
// _MyContent = null;// Reset related value
// }
OnChange();// raise an event OnChange();// raise an event
} }
public static ImageInfo Get(int contentID) public static ImageInfo Get(int contentID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Image");
try try
{ {
ImageInfo tmp = GetCachedByPrimaryKey(contentID); ImageInfo tmp = GetCachedByPrimaryKey(contentID);
@@ -296,13 +250,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _ContentID; private readonly int _ContentID;
public int ContentID public int ContentID => _ContentID;
{ get { return _ContentID; } } public PKCriteria(int contentID) => _ContentID = contentID;
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -363,7 +313,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
ImageInfoExtension _ImageInfoExtension = new ImageInfoExtension(); readonly ImageInfoExtension _ImageInfoExtension = new ImageInfoExtension();
[Serializable()] [Serializable()]
partial class ImageInfoExtension : extensionBase { } partial class ImageInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -379,10 +329,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ImageInfo) if (destType == typeof(string) && value is ImageInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((ImageInfo)value).ToString(); return info.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
+147 -314
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -133,6 +131,7 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Item> _CacheList = new List<Item>(); private static List<Item> _CacheList = new List<Item>();
protected static void AddToCache(Item item) protected static void AddToCache(Item item)
{ {
@@ -142,6 +141,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Item>> _CacheByPrimaryKey = new Dictionary<string, List<Item>>(); private static Dictionary<string, List<Item>> _CacheByPrimaryKey = new Dictionary<string, List<Item>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -167,15 +167,9 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private static int _nextItemID = -1; private static int _nextItemID = -1;
public static int NextItemID public static int NextItemID => _nextItemID--;
{
get { return _nextItemID--; }
}
private int _ItemID; private int _ItemID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int ItemID public int ItemID
@@ -315,10 +309,7 @@ namespace VEPROMS.CSLA.Library
return _ItemAnnotations; return _ItemAnnotations;
} }
} }
public void Reset_ItemAnnotations() public void Reset_ItemAnnotations() => _ItemAnnotationCount = -1;
{
_ItemAnnotationCount = -1;
}
private int _ItemDocVersionCount = 0; private int _ItemDocVersionCount = 0;
/// <summary> /// <summary>
/// Count of ItemDocVersions for this Item /// Count of ItemDocVersions for this Item
@@ -350,10 +341,7 @@ namespace VEPROMS.CSLA.Library
return _ItemDocVersions; return _ItemDocVersions;
} }
} }
public void Reset_ItemDocVersions() public void Reset_ItemDocVersions() => _ItemDocVersionCount = -1;
{
_ItemDocVersionCount = -1;
}
private int _NextItemCount = 0; private int _NextItemCount = 0;
/// <summary> /// <summary>
/// Count of NextItems for this Item /// Count of NextItems for this Item
@@ -385,10 +373,7 @@ namespace VEPROMS.CSLA.Library
return _NextItems; return _NextItems;
} }
} }
public void Reset_NextItems() public void Reset_NextItems() => _NextItemCount = -1;
{
_NextItemCount = -1;
}
private int _ItemPartCount = 0; private int _ItemPartCount = 0;
/// <summary> /// <summary>
/// Count of ItemParts for this Item /// Count of ItemParts for this Item
@@ -420,10 +405,7 @@ namespace VEPROMS.CSLA.Library
return _ItemParts; return _ItemParts;
} }
} }
public void Reset_ItemParts() public void Reset_ItemParts() => _ItemPartCount = -1;
{
_ItemPartCount = -1;
}
private int _ItemTransition_RangeIDCount = 0; private int _ItemTransition_RangeIDCount = 0;
/// <summary> /// <summary>
/// Count of ItemTransitions for this Item /// Count of ItemTransitions for this Item
@@ -455,10 +437,7 @@ namespace VEPROMS.CSLA.Library
return _ItemTransitions_RangeID; return _ItemTransitions_RangeID;
} }
} }
public void Reset_ItemTransitions_RangeID() public void Reset_ItemTransitions_RangeID() => _ItemTransition_RangeIDCount = -1;
{
_ItemTransition_RangeIDCount = -1;
}
private int _ItemTransition_ToIDCount = 0; private int _ItemTransition_ToIDCount = 0;
/// <summary> /// <summary>
/// Count of ItemTransitions for this Item /// Count of ItemTransitions for this Item
@@ -490,10 +469,7 @@ namespace VEPROMS.CSLA.Library
return _ItemTransitions_ToID; return _ItemTransitions_ToID;
} }
} }
public void Reset_ItemTransitions_ToID() public void Reset_ItemTransitions_ToID() => _ItemTransition_ToIDCount = -1;
{
_ItemTransition_ToIDCount = -1;
}
public override bool IsDirty public override bool IsDirty
{ {
get get
@@ -508,37 +484,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_ItemAnnotations == null ? false : _ItemAnnotations.IsDirtyList(list)) || (_ItemDocVersions == null ? false : _ItemDocVersions.IsDirtyList(list)) || (_NextItems == null ? false : _NextItems.IsDirtyList(list)) || (_ItemParts == null ? false : _ItemParts.IsDirtyList(list)) || (_ItemTransitions_RangeID == null ? false : _ItemTransitions_RangeID.IsDirtyList(list)) || (_ItemTransitions_ToID == null ? false : _ItemTransitions_ToID.IsDirtyList(list)) || (_MyContent == null ? false : _MyContent.IsDirtyList(list)); return base.IsDirty || (_ItemAnnotations != null && _ItemAnnotations.IsDirtyList(list)) || (_ItemDocVersions != null && _ItemDocVersions.IsDirtyList(list)) || (_NextItems != null && _NextItems.IsDirtyList(list)) || (_ItemParts != null && _ItemParts.IsDirtyList(list)) || (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirtyList(list)) || (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirtyList(list)) || (_MyContent != null && _MyContent.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
} }
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list) public bool IsValidList(List<object> list)
{ {
if (list.Contains(this)) if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid; return (IsNew && !IsDirty) || base.IsValid;
list.Add(this); list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ItemAnnotations == null ? true : _ItemAnnotations.IsValidList(list)) && (_ItemDocVersions == null ? true : _ItemDocVersions.IsValidList(list)) && (_NextItems == null ? true : _NextItems.IsValidList(list)) && (_ItemParts == null ? true : _ItemParts.IsValidList(list)) && (_ItemTransitions_RangeID == null ? true : _ItemTransitions_RangeID.IsValidList(list)) && (_ItemTransitions_ToID == null ? true : _ItemTransitions_ToID.IsValidList(list)) && (_MyContent == null ? true : _MyContent.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_ItemAnnotations == null || _ItemAnnotations.IsValidList(list)) && (_ItemDocVersions == null || _ItemDocVersions.IsValidList(list)) && (_NextItems == null || _NextItems.IsValidList(list)) && (_ItemParts == null || _ItemParts.IsValidList(list)) && (_ItemTransitions_RangeID == null || _ItemTransitions_RangeID.IsValidList(list)) && (_ItemTransitions_ToID == null || _ItemTransitions_ToID.IsValidList(list)) && (_MyContent == null || _MyContent.IsValidList(list));
} }
// CSLATODO: Replace base Item.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Item</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Item.GetIdValue to assure that the ID returned is unique // CSLATODO: Check Item.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current Item</returns> /// <returns>A Unique ID for the current Item</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemUnique; // Absolutely Unique ID
{
return MyItemUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -573,8 +534,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -603,31 +564,11 @@ namespace VEPROMS.CSLA.Library
} }
return true; return true;
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_ItemExtension.AddAuthorizationRules(AuthorizationRules); _ItemExtension.AddAuthorizationRules(AuthorizationRules);
} }
protected override void AddInstanceAuthorizationRules() protected override void AddInstanceAuthorizationRules()
@@ -635,60 +576,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
_ItemExtension.AddInstanceAuthorizationRules(AuthorizationRules); _ItemExtension.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 += _ItemAnnotationCount;
usedByCount += _ItemDocVersionCount;
usedByCount += _ItemPartCount;
usedByCount += _ItemTransition_RangeIDCount;
usedByCount += _ItemTransition_ToIDCount;
usedByCount += _NextItemCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemUnique = 0; private static int _ItemUnique = 0;
protected static int ItemUnique protected static int ItemUnique => ++_ItemUnique;
{ get { return ++_ItemUnique; } } private readonly int _MyItemUnique = ItemUnique;
private int _MyItemUnique = ItemUnique; // Absolutely Unique ID - Editable
public int MyItemUnique // Absolutely Unique ID - Editable public int MyItemUnique => _MyItemUnique;
{ get { return _MyItemUnique; } }
protected Item() protected Item()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -697,15 +592,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~Item() ~Item()
{ {
_CountFinalized++; _CountFinalized++;
@@ -732,16 +623,6 @@ namespace VEPROMS.CSLA.Library
_ItemTransitions_RangeID = null; _ItemTransitions_RangeID = null;
if (_ItemTransitions_ToID != null) if (_ItemTransitions_ToID != null)
_ItemTransitions_ToID = null; _ItemTransitions_ToID = null;
//if (_MyPrevious != null)
// _MyPrevious = null;
//if (_NextItems != null)
// _NextItems = null;
//if (_ItemAnnotations != null)
// _ItemAnnotations.Dispose();
//if (_ItemDocVersions != null)
// _ItemDocVersions = null;
//if (_ItemParts != null)
// _ItemParts = null;
} }
private void RemoveFromDictionaries() private void RemoveFromDictionaries()
{ {
@@ -756,8 +637,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Item New() public static Item New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Item");
try try
{ {
return DataPortal.Create<Item>(); return DataPortal.Create<Item>();
@@ -823,8 +702,6 @@ namespace VEPROMS.CSLA.Library
} }
public static Item Get(int itemID) public static Item Get(int itemID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Item");
try try
{ {
Item tmp = GetCachedByPrimaryKey(itemID); Item tmp = GetCachedByPrimaryKey(itemID);
@@ -850,15 +727,14 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Item(dr, previous); if (dr.Read()) return new Item(dr, previous);
return null; return null;
} }
internal Item(SafeDataReader dr) internal Item(SafeDataReader dr) => ReadData(dr);
{ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
ReadData(dr);
}
private Item(SafeDataReader dr, Item previous) private Item(SafeDataReader dr, Item previous)
{ {
ReadData(dr); ReadData(dr);
MarkAsChild(); MarkAsChild();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal Item(SafeDataReader dr, int parentID) internal Item(SafeDataReader dr, int parentID)
{ {
ReadData(dr); ReadData(dr);
@@ -866,8 +742,6 @@ namespace VEPROMS.CSLA.Library
} }
public static void Delete(int itemID) public static void Delete(int itemID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Item");
try try
{ {
DataPortal.Delete(new PKCriteria(itemID)); DataPortal.Delete(new PKCriteria(itemID));
@@ -879,12 +753,6 @@ namespace VEPROMS.CSLA.Library
} }
public override Item Save() public override Item Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Item");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Item");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Item");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -904,13 +772,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _ItemID; private readonly int _ItemID;
public int ItemID public int ItemID => _ItemID;
{ get { return _ItemID; } } public PKCriteria(int itemID) => _ItemID = itemID;
public PKCriteria(int itemID)
{
_ItemID = itemID;
}
} }
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal // CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()] [RunLocal()]
@@ -1028,42 +892,49 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert() internal void SQLInsert()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
try try
{ {
if (_MyContent != null) _MyContent.Update(); _MyContent?.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "addItem"; cm.CommandType = CommandType.StoredProcedure;
// Input All Fields - Except Calculated Columns cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@PreviousID", PreviousID); cm.CommandText = "addItem";
cm.Parameters.AddWithValue("@ContentID", ContentID); // Input All Fields - Except Calculated Columns
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@PreviousID", PreviousID);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@ContentID", ContentID);
// Output Calculated Columns if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int); cm.Parameters.AddWithValue("@UserID", _UserID);
param_ItemID.Direction = ParameterDirection.Output; // Output Calculated Columns
cm.Parameters.Add(param_ItemID); SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int)
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); {
param_LastChanged.Direction = ParameterDirection.Output; Direction = ParameterDirection.Output
cm.Parameters.Add(param_LastChanged); };
// CSLATODO: Define any additional output parameters cm.Parameters.Add(param_ItemID);
cm.ExecuteNonQuery(); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
// Save all values being returned from the Procedure {
_ItemID = (int)cm.Parameters["@newItemID"].Value; Direction = ParameterDirection.Output
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; };
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_ItemID = (int)cm.Parameters["@newItemID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
} }
MarkOld(); MarkOld();
// update child objects // update child objects
if (_ItemAnnotations != null) _ItemAnnotations.Update(this); _ItemAnnotations?.Update(this);
if (_ItemDocVersions != null) _ItemDocVersions.Update(this); _ItemDocVersions?.Update(this);
if (_NextItems != null) _NextItems.Update(this); _NextItems?.Update(this);
if (_ItemParts != null) _ItemParts.Update(this); _ItemParts?.Update(this);
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this); _ItemTransitions_RangeID?.Update(this);
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this); _ItemTransitions_ToID?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode());
} }
catch (Exception ex) catch (Exception ex)
@@ -1090,11 +961,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int); SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int)
param_ItemID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ItemID); cm.Parameters.Add(param_ItemID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
param_LastChanged.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged); cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
@@ -1178,7 +1053,7 @@ namespace VEPROMS.CSLA.Library
return dt; return dt;
} }
catch (Exception ex) catch (Exception)
{ {
//B2025-004 //B2025-004
//if it fails loading previously open tabs, simply treat it as if no tabs were open //if it fails loading previously open tabs, simply treat it as if no tabs were open
@@ -1219,40 +1094,45 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLUpdate", GetHashCode());
try try
{ {
if (_MyContent != null) _MyContent.Update(); _MyContent?.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) if (base.IsDirty)
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "updateItem"; cm.CommandType = CommandType.StoredProcedure;
// All Fields including Calculated Fields cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@ItemID", _ItemID); cm.CommandText = "updateItem";
cm.Parameters.AddWithValue("@PreviousID", PreviousID); // All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID); cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@PreviousID", PreviousID);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
// Output Calculated Columns cm.Parameters.AddWithValue("@UserID", _UserID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
param_LastChanged.Direction = ParameterDirection.Output; // Output Calculated Columns
cm.Parameters.Add(param_LastChanged); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
// CSLATODO: Define any additional output parameters {
cm.ExecuteNonQuery(); Direction = ParameterDirection.Output
// Save all values being returned from the Procedure };
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
} }
} }
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
if (_ItemAnnotations != null) _ItemAnnotations.Update(this); _ItemAnnotations?.Update(this);
if (_ItemDocVersions != null) _ItemDocVersions.Update(this); _ItemDocVersions?.Update(this);
if (_NextItems != null) _NextItems.Update(this); _NextItems?.Update(this);
if (_ItemParts != null) _ItemParts.Update(this); _ItemParts?.Update(this);
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this); _ItemTransitions_RangeID?.Update(this);
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this); _ItemTransitions_ToID?.Update(this);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -1263,31 +1143,38 @@ namespace VEPROMS.CSLA.Library
} }
internal void Update() internal void Update()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
if (base.IsDirty) if (base.IsDirty)
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (IsNew) {
_LastChanged = Item.Add(cn, ref _ItemID, _MyPrevious, _MyContent, _DTS, _UserID); if (IsNew)
else _LastChanged = Item.Add(cn, ref _ItemID, _MyPrevious, _MyContent, _DTS, _UserID);
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, _ContentID, _DTS, _UserID, ref _LastChanged); else
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, _ContentID, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
if (_ItemAnnotations != null) _ItemAnnotations.Update(this); _ItemAnnotations?.Update(this);
if (_ItemDocVersions != null) _ItemDocVersions.Update(this); _ItemDocVersions?.Update(this);
if (_NextItems != null) _NextItems.Update(this); _NextItems?.Update(this);
if (_ItemParts != null) _ItemParts.Update(this); _ItemParts?.Update(this);
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this); _ItemTransitions_RangeID?.Update(this);
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this); _ItemTransitions_ToID?.Update(this);
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item item) internal void DeleteSelf(Item item)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
Item.Remove(cn, _ItemID); {
Item.Remove(cn, _ItemID);
}
MarkNew(); MarkNew();
} }
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
@@ -1309,8 +1196,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged); cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
param_LastChanged.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged); cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
@@ -1395,16 +1284,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class ExistsCommand : CommandBase private class ExistsCommand : CommandBase
{ {
private int _ItemID; private readonly int _ItemID;
private bool _exists; private bool _exists;
public bool Exists public bool Exists => _exists;
{ public ExistsCommand(int itemID) => _ItemID = itemID;
get { return _exists; }
}
public ExistsCommand(int itemID)
{
_ItemID = itemID;
}
protected override void DataPortal_Execute() protected override void DataPortal_Execute()
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode());
@@ -1434,7 +1317,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemExtension _ItemExtension = new ItemExtension(); readonly ItemExtension _ItemExtension = new ItemExtension();
[Serializable()] [Serializable()]
partial class ItemExtension : extensionBase partial class ItemExtension : extensionBase
{ {
@@ -1443,14 +1326,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual DateTime DefaultDTS public virtual DateTime DefaultDTS => DateTime.Now;
{ public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -1479,57 +1356,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is Item) if (destType == typeof(string) && value is Item myitem)
{ {
// Return the ToString value // Return the ToString value
return ((Item)value).ToString(); return myitem.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Item
// {
// partial class ItemExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ======================================================================== // ========================================================================
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _AnnotationID; private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID public int AnnotationID
@@ -224,19 +218,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemAnnotation</returns> /// <returns>A Unique ID for the current ItemAnnotation</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemAnnotationUnique; // Absolutely Unique ID
{
return MyItemAnnotationUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ItemAnnotation.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemAnnotation</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty public override bool IsDirty
{ {
get get
@@ -251,18 +233,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirtyList(list)); return base.IsDirty || (_MyAnnotationType != null && _MyAnnotationType.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
} }
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list) public bool IsValidList(List<object> list)
{ {
if (list.Contains(this)) if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid; return (IsNew && !IsDirty) || base.IsValid;
list.Add(this); list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_MyAnnotationType == null || _MyAnnotationType.IsValidList(list));
} }
#endregion #endregion
#region ValidationRules #region ValidationRules
@@ -292,8 +271,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -324,80 +303,22 @@ namespace VEPROMS.CSLA.Library
} }
return true; return true;
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AnnotationID, "<Role(s)>");
//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
//AuthorizationRules.AllowWrite(TypeID, "<Role(s)>");
//AuthorizationRules.AllowRead(RtfText, "<Role(s)>");
//AuthorizationRules.AllowWrite(RtfText, "<Role(s)>");
//AuthorizationRules.AllowRead(SearchText, "<Role(s)>");
//AuthorizationRules.AllowWrite(SearchText, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemAnnotationUnique = 0; private static int _ItemAnnotationUnique = 0;
private static int ItemAnnotationUnique private static int ItemAnnotationUnique => ++_ItemAnnotationUnique;
{ get { return ++_ItemAnnotationUnique; } } private readonly int _MyItemAnnotationUnique = ItemAnnotationUnique;
private int _MyItemAnnotationUnique = ItemAnnotationUnique; // Absolutely Unique ID - Editable FK
public int MyItemAnnotationUnique // Absolutely Unique ID - Editable FK public int MyItemAnnotationUnique => _MyItemAnnotationUnique;
{ get { return _MyItemAnnotationUnique; } } internal static ItemAnnotation New(AnnotationType myAnnotationType) => new ItemAnnotation(myAnnotationType);
internal static ItemAnnotation New(AnnotationType myAnnotationType) internal static ItemAnnotation Get(SafeDataReader dr) => new ItemAnnotation(dr);
{
return new ItemAnnotation(myAnnotationType);
}
internal static ItemAnnotation Get(SafeDataReader dr)
{
return new ItemAnnotation(dr);
}
public ItemAnnotation() public ItemAnnotation()
{ {
MarkAsChild(); MarkAsChild();
@@ -425,15 +346,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAnnotation() ~ItemAnnotation()
{ {
_CountFinalized++; _CountFinalized++;
@@ -474,33 +391,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Item myItem) internal void Insert(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Annotation.Add(cn, ref _AnnotationID, myItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID); {
_LastChanged = Annotation.Add(cn, ref _AnnotationID, myItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
}
MarkOld(); MarkOld();
} }
internal void Update(Item myItem) internal void Update(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Annotation.Update(cn, ref _AnnotationID, myItem.ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); {
_LastChanged = Annotation.Update(cn, ref _AnnotationID, myItem.ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItem) internal void DeleteSelf(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
Annotation.Remove(cn, _AnnotationID); {
Annotation.Remove(cn, _AnnotationID);
}
MarkNew(); MarkNew();
} }
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension(); readonly ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension();
[Serializable()] [Serializable()]
partial class ItemAnnotationExtension : extensionBase partial class ItemAnnotationExtension : extensionBase
{ {
@@ -509,14 +436,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual DateTime DefaultDTS public virtual DateTime DefaultDTS => DateTime.Now;
{ public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -545,57 +466,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemAnnotation) if (destType == typeof(string) && value is ItemAnnotation annotation)
{ {
// Return the ToString value // Return the ToString value
return ((ItemAnnotation)value).ToString(); return annotation.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemAnnotationExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemAnnotation
// {
// partial class ItemAnnotationExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{ // One To Many
get { return _ErrorMessage; } public ItemAnnotation this[Annotation myAnnotation]
}
// One To Many
public ItemAnnotation this[Annotation myAnnotation]
{ {
get get
{ {
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null; return null;
} }
} }
public new System.Collections.Generic.IList<ItemAnnotation> Items public new System.Collections.Generic.IList<ItemAnnotation> Items => base.Items;
{ public ItemAnnotation GetItem(Annotation myAnnotation)
get { return base.Items; }
}
public ItemAnnotation GetItem(Annotation myAnnotation)
{ {
foreach (ItemAnnotation annotation in this) foreach (ItemAnnotation annotation in this)
if (annotation.AnnotationID == myAnnotation.AnnotationID) if (annotation.AnnotationID == myAnnotation.AnnotationID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ItemAnnotation Add(AnnotationType myAnnotationType) // One to Many public ItemAnnotation Add(AnnotationType myAnnotationType) // One to Many
{ {
ItemAnnotation annotation = ItemAnnotation.New(myAnnotationType); ItemAnnotation annotation = ItemAnnotation.New(myAnnotationType);
this.Add(annotation); Add(annotation);
return annotation; return annotation;
} }
public void Remove(Annotation myAnnotation) public void Remove(Annotation myAnnotation)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true; return true;
return false; return false;
} }
public override bool IsValid public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{ {
get { return IsValidList(new List<object>()); } // run through all the child objects
} // and if any are invalid then the
public bool IsValidList(List<object> list) // collection is invalid
{ foreach (ItemAnnotation child in this)
// run through all the child objects if (!child.IsValidList(list))
// and if any are invalid then the {
// collection is invalid //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
foreach (ItemAnnotation child in this) return false;
if (!child.IsValidList(list)) }
{ return true;
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); }
return false;
}
return true;
}
#endregion #endregion
#region ValidationRules #region ValidationRules
public IVEHasBrokenRules HasBrokenRules public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
internal static ItemAnnotations New() internal static ItemAnnotations New() => new ItemAnnotations();
{ internal static ItemAnnotations Get(SafeDataReader dr) => new ItemAnnotations(dr);
return new ItemAnnotations(); public static ItemAnnotations GetByItemID(int itemID)
}
internal static ItemAnnotations Get(SafeDataReader dr)
{
return new ItemAnnotations(dr);
}
public static ItemAnnotations GetByItemID(int itemID)
{ {
try try
{ {
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemAnnotations.GetByItemID", ex); throw new DbCslaException("Error on ItemAnnotations.GetByItemID", ex);
} }
} }
private ItemAnnotations() private ItemAnnotations() => MarkAsChild();
{ internal ItemAnnotations(SafeDataReader dr)
MarkAsChild();
}
internal ItemAnnotations(SafeDataReader dr)
{ {
MarkAsChild(); MarkAsChild();
Fetch(dr); Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ItemAnnotations()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAnnotations()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database // called to load data from the database
private void Fetch(SafeDataReader dr) private void Fetch(SafeDataReader dr)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
while (dr.Read()) while (dr.Read())
this.Add(ItemAnnotation.Get(dr)); Add(ItemAnnotation.Get(dr));
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class ItemIDCriteria private class ItemIDCriteria
{ {
public ItemIDCriteria(int itemID) public ItemIDCriteria(int itemID) => _ItemID = itemID;
{ private int _ItemID;
_ItemID = itemID;
}
private int _ItemID;
public int ItemID public int ItemID
{ {
get { return _ItemID; } get { return _ItemID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(ItemIDCriteria criteria) private void DataPortal_Fetch(ItemIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotations.DataPortal_FetchItemID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotations.DataPortal_FetchItemID", GetHashCode());
try try
{ {
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout; cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
while (dr.Read()) this.Add(new ItemAnnotation(dr)); while (dr.Read()) Add(new ItemAnnotation(dr));
} }
} }
} }
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotations.DataPortal_FetchItemID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotations.DataPortal_FetchItemID", ex);
throw new DbCslaException("ItemAnnotations.DataPortal_Fetch", ex); throw new DbCslaException("ItemAnnotations.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
internal void Update(Item item) internal void Update(Item item)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
try try
{ {
// update (thus deleting) any deleted child objects // update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
} }
finally finally
{ {
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemAnnotationsPropertyDescriptor pd = new ItemAnnotationsPropertyDescriptor(this, i); ItemAnnotationsPropertyDescriptor pd = new ItemAnnotationsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemAnnotationsPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemAnnotationsPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemAnnotation Item { get { return (ItemAnnotation)_Item; } }
public ItemAnnotationsPropertyDescriptor(ItemAnnotations collection, int index) : base(collection, index) { ;} public ItemAnnotationsPropertyDescriptor(ItemAnnotations collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemAnnotations) if (destType == typeof(string) && value is ItemAnnotations annotations)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemAnnotations)value).Items.Count.ToString() + " Annotations"; return $"{annotations.Items.Count} Annotations";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
+87 -220
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty) if (IsDirty)
refreshItemAudits.Add(this); refreshItemAudits.Add(this);
} }
private void ClearRefreshList() private void ClearRefreshList() => _RefreshItemAudits = new List<ItemAudit>();
{
_RefreshItemAudits = new List<ItemAudit>();
}
private void BuildRefreshList() private void BuildRefreshList()
{ {
ClearRefreshList(); ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ItemAudit> _CacheList = new List<ItemAudit>(); private static List<ItemAudit> _CacheList = new List<ItemAudit>();
protected static void AddToCache(ItemAudit itemAudit) protected static void AddToCache(ItemAudit itemAudit)
{ {
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(itemAudit)) _CacheList.Remove(itemAudit); // In RemoveFromCache while (_CacheList.Contains(itemAudit)) _CacheList.Remove(itemAudit); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ItemAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ItemAudit>>(); private static Dictionary<string, List<ItemAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ItemAudit>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private static int _nextAuditID = -1; private static int _nextAuditID = -1;
public static int NextAuditID public static int NextAuditID => _nextAuditID--;
{
get { return _nextAuditID--; }
}
private long _AuditID; private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public long AuditID public long AuditID
@@ -218,40 +209,14 @@ namespace VEPROMS.CSLA.Library
} }
} }
} }
public override bool IsDirty public override bool IsDirty => base.IsDirty;
{ public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base ItemAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ItemAudit.GetIdValue to assure that the ID returned is unique // CSLATODO: Check ItemAudit.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemAudit</returns> /// <returns>A Unique ID for the current ItemAudit</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemAuditUnique; // Absolutely Unique ID
{
return MyItemAuditUnique; // Absolutely Unique ID
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -279,8 +244,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -299,35 +264,11 @@ namespace VEPROMS.CSLA.Library
_ItemAuditExtension.AddInstanceValidationRules(ValidationRules); _ItemAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_ItemAuditExtension.AddAuthorizationRules(AuthorizationRules); _ItemAuditExtension.AddAuthorizationRules(AuthorizationRules);
} }
protected override void AddInstanceAuthorizationRules() protected override void AddInstanceAuthorizationRules()
@@ -335,42 +276,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
_ItemAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules); _ItemAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
} }
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemAuditUnique = 0; private static int _ItemAuditUnique = 0;
protected static int ItemAuditUnique protected static int ItemAuditUnique => ++_ItemAuditUnique;
{ get { return ++_ItemAuditUnique; } } private readonly int _MyItemAuditUnique = ItemAuditUnique;
private int _MyItemAuditUnique = ItemAuditUnique; // Absolutely Unique ID - Editable
public int MyItemAuditUnique // Absolutely Unique ID - Editable public int MyItemAuditUnique => _MyItemAuditUnique;
{ get { return _MyItemAuditUnique; } }
protected ItemAudit() protected ItemAudit()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -379,15 +292,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAudit() ~ItemAudit()
{ {
_CountFinalized++; _CountFinalized++;
@@ -412,8 +321,6 @@ namespace VEPROMS.CSLA.Library
} }
public static ItemAudit New() public static ItemAudit New()
{ {
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ItemAudit");
try try
{ {
return DataPortal.Create<ItemAudit>(); return DataPortal.Create<ItemAudit>();
@@ -462,8 +369,6 @@ namespace VEPROMS.CSLA.Library
} }
public static ItemAudit Get(long auditID) public static ItemAudit Get(long auditID)
{ {
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a ItemAudit");
try try
{ {
ItemAudit tmp = GetCachedByPrimaryKey(auditID); ItemAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -489,14 +394,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new ItemAudit(dr); if (dr.Read()) return new ItemAudit(dr);
return null; return null;
} }
internal ItemAudit(SafeDataReader dr) internal ItemAudit(SafeDataReader dr) => ReadData(dr);
{
ReadData(dr);
}
public static void Delete(long auditID) public static void Delete(long auditID)
{ {
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ItemAudit");
try try
{ {
DataPortal.Delete(new PKCriteria(auditID)); DataPortal.Delete(new PKCriteria(auditID));
@@ -508,12 +408,6 @@ namespace VEPROMS.CSLA.Library
} }
public override ItemAudit Save() public override ItemAudit Save()
{ {
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ItemAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ItemAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a ItemAudit");
try try
{ {
BuildRefreshList(); BuildRefreshList();
@@ -533,13 +427,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private long _AuditID; private readonly long _AuditID;
public long AuditID public long AuditID => _AuditID;
{ get { return _AuditID; } } public PKCriteria(long auditID) => _AuditID = auditID;
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
} }
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal // CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()] [RunLocal()]
@@ -636,31 +526,36 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)] [Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert() internal void SQLInsert()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlCommand cm = cn.CreateCommand())
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "addItemAudit"; cm.CommandType = CommandType.StoredProcedure;
// Input All Fields - Except Calculated Columns cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@ItemID", _ItemID); cm.CommandText = "addItemAudit";
cm.Parameters.AddWithValue("@PreviousID", _PreviousID); // Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID); cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@PreviousID", _PreviousID);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
// Output Calculated Columns cm.Parameters.AddWithValue("@UserID", _UserID);
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
param_AuditID.Direction = ParameterDirection.Output; // Output Calculated Columns
cm.Parameters.Add(param_AuditID); SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
// CSLATODO: Define any additional output parameters {
cm.ExecuteNonQuery(); Direction = ParameterDirection.Output
// Save all values being returned from the Procedure };
_AuditID = (long)cm.Parameters["@newAuditID"].Value; cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
} }
MarkOld(); MarkOld();
// update child objects // update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLInsert", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLInsert", GetHashCode());
@@ -691,8 +586,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID); cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns // Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
param_AuditID.Direction = ParameterDirection.Output; {
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID); cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
@@ -737,28 +634,31 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLUpdate", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLUpdate", GetHashCode());
try try
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (base.IsDirty)
{ {
using (SqlCommand cm = cn.CreateCommand()) if (base.IsDirty)
{ {
cm.CommandType = CommandType.StoredProcedure; using (SqlCommand cm = cn.CreateCommand())
cm.CommandTimeout = Database.SQLTimeout; {
cm.CommandText = "updateItemAudit"; cm.CommandType = CommandType.StoredProcedure;
// All Fields including Calculated Fields cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@AuditID", _AuditID); cm.CommandText = "updateItemAudit";
cm.Parameters.AddWithValue("@ItemID", _ItemID); // All Fields including Calculated Fields
cm.Parameters.AddWithValue("@PreviousID", _PreviousID); cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID); cm.Parameters.AddWithValue("@ItemID", _ItemID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@PreviousID", _PreviousID);
cm.Parameters.AddWithValue("@UserID", _UserID); cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
// Output Calculated Columns cm.Parameters.AddWithValue("@UserID", _UserID);
// CSLATODO: Define any additional output parameters cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
cm.ExecuteNonQuery(); // Output Calculated Columns
// Save all values being returned from the Procedure // CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
} }
} }
MarkOld(); MarkOld();
// use the open connection to update child objects // use the open connection to update child objects
} }
@@ -771,14 +671,17 @@ namespace VEPROMS.CSLA.Library
} }
internal void Update() internal void Update()
{ {
if (!this.IsDirty) return; if (!IsDirty) return;
if (base.IsDirty) if (base.IsDirty)
{ {
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
if (IsNew) {
ItemAudit.Add(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus); if (IsNew)
else ItemAudit.Add(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus);
ItemAudit.Update(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus); else
ItemAudit.Update(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus);
}
MarkOld(); MarkOld();
} }
} }
@@ -870,7 +773,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension(); readonly ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension();
[Serializable()] [Serializable()]
partial class ItemAuditExtension : extensionBase partial class ItemAuditExtension : extensionBase
{ {
@@ -907,49 +810,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemAudit) if (destType == typeof(string) && value is ItemAudit audit)
{ {
// Return the ToString value // Return the ToString value
return ((ItemAudit)value).ToString(); return audit.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemAudit
// {
// partial class ItemAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ItemAuditInfo : ReadOnlyBase<ItemAuditInfo>, IDisposable public partial class ItemAuditInfo : ReadOnlyBase<ItemAuditInfo>, IDisposable
{ {
public event ItemAuditInfoEvent Changed; public event ItemAuditInfoEvent Changed;
private void OnChange() private void OnChange() => Changed?.Invoke(this);
{
if (Changed != null) Changed(this);
}
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ItemAuditInfo> _CacheList = new List<ItemAuditInfo>(); private static List<ItemAuditInfo> _CacheList = new List<ItemAuditInfo>();
protected static void AddToCache(ItemAuditInfo itemAuditInfo) protected static void AddToCache(ItemAuditInfo itemAuditInfo)
{ {
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{ {
while (_CacheList.Contains(itemAuditInfo)) _CacheList.Remove(itemAuditInfo); // In RemoveFromCache while (_CacheList.Contains(itemAuditInfo)) _CacheList.Remove(itemAuditInfo); // In RemoveFromCache
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ItemAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ItemAuditInfo>>(); private static Dictionary<string, List<ItemAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ItemAuditInfo>>();
private static void ConvertListToDictionary() private static void ConvertListToDictionary()
{ {
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
protected ItemAudit _Editable; protected ItemAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID; private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public long AuditID public long AuditID
@@ -153,32 +137,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus; return _DeleteStatus;
} }
} }
// CSLATODO: Replace base ItemAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ItemAuditInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check ItemAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemAuditInfo</returns> /// <returns>A Unique ID for the current ItemAuditInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemAuditInfoUnique; // Absolutely Unique ID
{
return MyItemAuditInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ItemAuditInfoUnique = 0; private static int _ItemAuditInfoUnique = 0;
private static int ItemAuditInfoUnique private static int ItemAuditInfoUnique => ++_ItemAuditInfoUnique;
{ get { return ++_ItemAuditInfoUnique; } } private readonly int _MyItemAuditInfoUnique = ItemAuditInfoUnique;
private int _MyItemAuditInfoUnique = ItemAuditInfoUnique; // Absolutely Unique ID - Info
public int MyItemAuditInfoUnique // Absolutely Unique ID - Info public int MyItemAuditInfoUnique => _MyItemAuditInfoUnique;
{ get { return _MyItemAuditInfoUnique; } }
protected ItemAuditInfo() protected ItemAuditInfo()
{/* require use of factory methods */ {/* require use of factory methods */
AddToCache(this); AddToCache(this);
@@ -187,15 +158,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAuditInfo() ~ItemAuditInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -212,10 +179,7 @@ namespace VEPROMS.CSLA.Library
if (listItemAuditInfo.Count == 0) // If there are no items left in the list if (listItemAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
} }
public virtual ItemAudit Get() public virtual ItemAudit Get() => _Editable = ItemAudit.Get(_AuditID);
{
return _Editable = ItemAudit.Get(_AuditID);
}
public static void Refresh(ItemAudit tmp) public static void Refresh(ItemAudit tmp)
{ {
string key = tmp.AuditID.ToString(); string key = tmp.AuditID.ToString();
@@ -237,8 +201,6 @@ namespace VEPROMS.CSLA.Library
} }
public static ItemAuditInfo Get(long auditID) public static ItemAuditInfo Get(long auditID)
{ {
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a ItemAudit");
try try
{ {
ItemAuditInfo tmp = GetCachedByPrimaryKey(auditID); ItemAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -277,13 +239,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private long _AuditID; private readonly long _AuditID;
public long AuditID public long AuditID => _AuditID;
{ get { return _AuditID; } } public PKCriteria(long auditID) => _AuditID = auditID;
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
} }
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
@@ -344,7 +302,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension(); readonly ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension();
[Serializable()] [Serializable()]
partial class ItemAuditInfoExtension : extensionBase { } partial class ItemAuditInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -360,10 +318,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemAuditInfo) if (destType == typeof(string) && value is ItemAuditInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((ItemAuditInfo)value).ToString(); return info.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{ {
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
internal new IList<ItemAuditInfo> Items internal new IList<ItemAuditInfo> Items => base.Items;
{ get { return base.Items; } } public void AddEvents()
public void AddEvents()
{ {
foreach (ItemAuditInfo tmp in this) foreach (ItemAuditInfo tmp in this)
{ {
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
if (base[i] == sender) if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
} }
} }
private bool _Disposed = false; private bool _Disposed = false;
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ItemAuditInfoList()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAuditInfoList()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemAuditInfoList.Get", ex); throw new DbCslaException("Error on ItemAuditInfoList.Get", ex);
} }
} }
/// <summary> /// <summary>
/// Reset the list of all ItemAuditInfo. /// Reset the list of all ItemAuditInfo.
/// </summary> /// </summary>
public static void Reset() public static void Reset() => _ItemAuditInfoList = null;
{ private ItemAuditInfoList()
_ItemAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ItemAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ItemAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ItemAuditInfoList.Get", ex);
// }
//}
private ItemAuditInfoList()
{ /* require use of factory methods */ } { /* require use of factory methods */ }
#endregion #endregion
#region Data Access Portal #region Data Access Portal
private void DataPortal_Fetch() private void DataPortal_Fetch()
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode());
try try
{ {
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
IsReadOnly = false; IsReadOnly = false;
while (dr.Read()) this.Add(new ItemAuditInfo(dr)); while (dr.Read()) Add(new ItemAuditInfo(dr));
IsReadOnly = true; IsReadOnly = true;
} }
} }
@@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemAuditInfoListPropertyDescriptor pd = new ItemAuditInfoListPropertyDescriptor(this, i); ItemAuditInfoListPropertyDescriptor pd = new ItemAuditInfoListPropertyDescriptor(this, i);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemAuditInfo Item { get { return (ItemAuditInfo)_Item; } }
public ItemAuditInfoListPropertyDescriptor(ItemAuditInfoList collection, int index) : base(collection, index) { ;} public ItemAuditInfoListPropertyDescriptor(ItemAuditInfoList collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemAuditInfoList) if (destType == typeof(string) && value is ItemAuditInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemAuditInfoList)value).Items.Count.ToString() + " ItemAudits"; return $"{list.Items.Count} ItemAudits";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -9,12 +9,9 @@
// ======================================================================== // ========================================================================
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _VersionID; private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int VersionID public int VersionID
@@ -329,19 +323,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemDocVersion</returns> /// <returns>A Unique ID for the current ItemDocVersion</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemDocVersionUnique; // Absolutely Unique ID
{
return MyItemDocVersionUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ItemDocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemDocVersion</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty public override bool IsDirty
{ {
get get
@@ -356,18 +338,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)); return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
} }
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list) public bool IsValidList(List<object> list)
{ {
if (list.Contains(this)) if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid; return (IsNew && !IsDirty) || base.IsValid;
list.Add(this); list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list));
} }
#endregion #endregion
#region ValidationRules #region ValidationRules
@@ -399,7 +378,7 @@ namespace VEPROMS.CSLA.Library
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -432,84 +411,22 @@ namespace VEPROMS.CSLA.Library
} }
return true; return true;
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(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(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 #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemDocVersionUnique = 0; private static int _ItemDocVersionUnique = 0;
private static int ItemDocVersionUnique private static int ItemDocVersionUnique => ++_ItemDocVersionUnique;
{ get { return ++_ItemDocVersionUnique; } } private readonly int _MyItemDocVersionUnique = ItemDocVersionUnique;
private int _MyItemDocVersionUnique = ItemDocVersionUnique; // Absolutely Unique ID - Editable FK
public int MyItemDocVersionUnique // Absolutely Unique ID - Editable FK public int MyItemDocVersionUnique => _MyItemDocVersionUnique;
{ get { return _MyItemDocVersionUnique; } } internal static ItemDocVersion New(Folder myFolder, string name) => new ItemDocVersion(myFolder, name);
internal static ItemDocVersion New(Folder myFolder, string name) internal static ItemDocVersion Get(SafeDataReader dr) => new ItemDocVersion(dr);
{
return new ItemDocVersion(myFolder, name);
}
internal static ItemDocVersion Get(SafeDataReader dr)
{
return new ItemDocVersion(dr);
}
public ItemDocVersion() public ItemDocVersion()
{ {
MarkAsChild(); MarkAsChild();
@@ -540,15 +457,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemDocVersion() ~ItemDocVersion()
{ {
_CountFinalized++; _CountFinalized++;
@@ -598,32 +511,42 @@ namespace VEPROMS.CSLA.Library
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, myItem, _MyFormat, _Config, _DTS, _UserID); {
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, myItem, _MyFormat, _Config, _DTS, _UserID);
}
MarkOld(); MarkOld();
} }
internal void Update(Item myItem) internal void Update(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, myItem != null ? (int?)myItem.ItemID : (int?)null, _FormatID, _Config, _DTS, _UserID, ref _LastChanged); {
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, myItem != null ? (int?)myItem.ItemID : (int?)null, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItem) internal void DeleteSelf(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!this.IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
DocVersion.Remove(cn, _VersionID); {
DocVersion.Remove(cn, _VersionID);
}
MarkNew(); MarkNew();
} }
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension(); readonly ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension();
[Serializable()] [Serializable()]
partial class ItemDocVersionExtension : extensionBase partial class ItemDocVersionExtension : extensionBase
{ {
@@ -632,18 +555,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual int DefaultVersionType public virtual int DefaultVersionType => 0;
{ public virtual DateTime DefaultDTS => DateTime.Now;
get { return 0; } public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -672,61 +586,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemDocVersion) if (destType == typeof(string) && value is ItemDocVersion version)
{ {
// Return the ToString value // Return the ToString value
return ((ItemDocVersion)value).ToString(); return version.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemDocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemDocVersion
// {
// partial class ItemDocVersionExtension : 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 System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{ // One To Many
get { return _ErrorMessage; } public ItemDocVersion this[DocVersion myDocVersion]
}
// One To Many
public ItemDocVersion this[DocVersion myDocVersion]
{ {
get get
{ {
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null; return null;
} }
} }
public new System.Collections.Generic.IList<ItemDocVersion> Items public new System.Collections.Generic.IList<ItemDocVersion> Items => base.Items;
{ public ItemDocVersion GetItem(DocVersion myDocVersion)
get { return base.Items; }
}
public ItemDocVersion GetItem(DocVersion myDocVersion)
{ {
foreach (ItemDocVersion docVersion in this) foreach (ItemDocVersion docVersion in this)
if (docVersion.VersionID == myDocVersion.VersionID) if (docVersion.VersionID == myDocVersion.VersionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ItemDocVersion Add(Folder myFolder, string name) // One to Many public ItemDocVersion Add(Folder myFolder, string name) // One to Many
{ {
ItemDocVersion docVersion = ItemDocVersion.New(myFolder, name); ItemDocVersion docVersion = ItemDocVersion.New(myFolder, name);
this.Add(docVersion); Add(docVersion);
return docVersion; return docVersion;
} }
public void Remove(DocVersion myDocVersion) public void Remove(DocVersion myDocVersion)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true; return true;
return false; return false;
} }
public override bool IsValid public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{ {
get { return IsValidList(new List<object>()); } // run through all the child objects
} // and if any are invalid then the
public bool IsValidList(List<object> list) // collection is invalid
{ foreach (ItemDocVersion child in this)
// run through all the child objects if (!child.IsValidList(list))
// and if any are invalid then the {
// collection is invalid //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
foreach (ItemDocVersion child in this) return false;
if (!child.IsValidList(list)) }
{ return true;
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); }
return false;
}
return true;
}
#endregion #endregion
#region ValidationRules #region ValidationRules
public IVEHasBrokenRules HasBrokenRules public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
internal static ItemDocVersions New() internal static ItemDocVersions New() => new ItemDocVersions();
{ internal static ItemDocVersions Get(SafeDataReader dr) => new ItemDocVersions(dr);
return new ItemDocVersions(); public static ItemDocVersions GetByItemID(int itemID)
}
internal static ItemDocVersions Get(SafeDataReader dr)
{
return new ItemDocVersions(dr);
}
public static ItemDocVersions GetByItemID(int itemID)
{ {
try try
{ {
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemDocVersions.GetByItemID", ex); throw new DbCslaException("Error on ItemDocVersions.GetByItemID", ex);
} }
} }
private ItemDocVersions() private ItemDocVersions() => MarkAsChild();
{ internal ItemDocVersions(SafeDataReader dr)
MarkAsChild();
}
internal ItemDocVersions(SafeDataReader dr)
{ {
MarkAsChild(); MarkAsChild();
Fetch(dr); Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ItemDocVersions()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemDocVersions()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database // called to load data from the database
private void Fetch(SafeDataReader dr) private void Fetch(SafeDataReader dr)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
while (dr.Read()) while (dr.Read())
this.Add(ItemDocVersion.Get(dr)); Add(ItemDocVersion.Get(dr));
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class ItemIDCriteria private class ItemIDCriteria
{ {
public ItemIDCriteria(int itemID) public ItemIDCriteria(int itemID) => _ItemID = itemID;
{ private int _ItemID;
_ItemID = itemID;
}
private int _ItemID;
public int ItemID public int ItemID
{ {
get { return _ItemID; } get { return _ItemID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(ItemIDCriteria criteria) private void DataPortal_Fetch(ItemIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemDocVersions.DataPortal_FetchItemID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemDocVersions.DataPortal_FetchItemID", GetHashCode());
try try
{ {
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout; cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
while (dr.Read()) this.Add(new ItemDocVersion(dr)); while (dr.Read()) Add(new ItemDocVersion(dr));
} }
} }
} }
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemDocVersions.DataPortal_FetchItemID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemDocVersions.DataPortal_FetchItemID", ex);
throw new DbCslaException("ItemDocVersions.DataPortal_Fetch", ex); throw new DbCslaException("ItemDocVersions.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
internal void Update(Item item) internal void Update(Item item)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
try try
{ {
// update (thus deleting) any deleted child objects // update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
} }
finally finally
{ {
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemDocVersionsPropertyDescriptor pd = new ItemDocVersionsPropertyDescriptor(this, i); ItemDocVersionsPropertyDescriptor pd = new ItemDocVersionsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemDocVersionsPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemDocVersionsPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemDocVersion Item { get { return (ItemDocVersion)_Item; } }
public ItemDocVersionsPropertyDescriptor(ItemDocVersions collection, int index) : base(collection, index) { ;} public ItemDocVersionsPropertyDescriptor(ItemDocVersions collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemDocVersions) if (destType == typeof(string) && value is ItemDocVersions versions)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemDocVersions)value).Items.Count.ToString() + " DocVersions"; return $"{versions.Items.Count} DocVersions";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -13,11 +13,8 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Volian.Base.Library;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
{ {
public delegate void ItemInfoEvent(object sender); public delegate void ItemInfoEvent(object sender);
@@ -29,27 +26,17 @@ namespace VEPROMS.CSLA.Library
public partial class ItemInfo : ReadOnlyBase<ItemInfo>, IDisposable public partial class ItemInfo : ReadOnlyBase<ItemInfo>, IDisposable
{ {
public event ItemInfoEvent Changed; public event ItemInfoEvent Changed;
private void OnChange() private void OnChange() => Changed?.Invoke(this);
{
if (Changed != null) Changed(this);
}
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Collection #region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ItemInfo> _CacheList = new List<ItemInfo>(); private static List<ItemInfo> _CacheList = new List<ItemInfo>();
protected static void AddToCache(ItemInfo itemInfo) protected static void AddToCache(ItemInfo itemInfo)
{ {
if (!_CacheList.Contains(itemInfo)) if (!_CacheList.Contains(itemInfo))
_CacheList.Add(itemInfo); // In AddToCache _CacheList.Add(itemInfo);
//try
//{
// _CacheList.Add(itemInfo); // In AddToCache
//}
//catch (Exception ex)
//{
// _MyLog.ErrorFormat("ItemInfo {0}.{1} already exists in the cache", itemInfo.ItemID, itemInfo.MyItemInfoUnique);
//}
} }
protected static void RemoveFromCache(ItemInfo itemInfo) protected static void RemoveFromCache(ItemInfo itemInfo)
{ {
@@ -84,10 +71,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
protected Item _Editable; protected Item _Editable;
private IVEHasBrokenRules HasBrokenRules private IVEHasBrokenRules HasBrokenRules
{ {
@@ -259,10 +243,7 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
private class PreviousIDCriteria private class PreviousIDCriteria
{ {
public PreviousIDCriteria(int? previousID) public PreviousIDCriteria(int? previousID) => _PreviousID = previousID;
{
_PreviousID = previousID;
}
private int? _PreviousID; private int? _PreviousID;
public int? PreviousID public int? PreviousID
{ {
@@ -469,24 +450,12 @@ namespace VEPROMS.CSLA.Library
foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()])
tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried
} }
// CSLATODO: Replace base ItemInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ItemInfo.GetIdValue to assure that the ID returned is unique // CSLATODO: Check ItemInfo.GetIdValue to assure that the ID returned is unique
/// <summary> /// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemInfo</returns> /// <returns>A Unique ID for the current ItemInfo</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemInfoUnique; // Absolutely Unique ID
{
return MyItemInfoUnique; // Absolutely Unique ID
}
#endregion #endregion
#region Factory Methods #region Factory Methods
private static int _ItemInfoUnique = 0; private static int _ItemInfoUnique = 0;
@@ -500,9 +469,9 @@ namespace VEPROMS.CSLA.Library
return ui; return ui;
} }
} }
private int _MyItemInfoUnique = ItemInfoUnique; private readonly int _MyItemInfoUnique = ItemInfoUnique;
public int MyItemInfoUnique // Absolutely Unique ID - Info // Absolutely Unique ID - Info
{ get { return _MyItemInfoUnique; } } public int MyItemInfoUnique => _MyItemInfoUnique;
protected ItemInfo() protected ItemInfo()
{/* require use of factory methods */ {/* require use of factory methods */
//AddToCache(this); //AddToCache(this);
@@ -511,15 +480,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemInfo() ~ItemInfo()
{ {
_CountFinalized++; _CountFinalized++;
@@ -540,21 +505,8 @@ namespace VEPROMS.CSLA.Library
_MyContent = null; _MyContent = null;
if (_MyPrevious != null) if (_MyPrevious != null)
_MyPrevious = null; _MyPrevious = null;
//if (_ActiveFormat != null)
// _ActiveFormat = null;
//if (_ActiveParent != null)
// _ActiveParent = null;
//if (_ActiveSection != null)
// _ActiveSection = null;
//if (_MyDocVersion != null)
// _MyDocVersion = null;
//if (_ParentNoteOrCaution != null)
// _ParentNoteOrCaution = null;
}
public virtual Item Get()
{
return _Editable = Item.Get(_ItemID);
} }
public virtual Item Get() => _Editable = Item.Get(_ItemID);
public static void Refresh(Item tmp) public static void Refresh(Item tmp)
{ {
string key = tmp.ItemID.ToString(); string key = tmp.ItemID.ToString();
@@ -567,18 +519,17 @@ namespace VEPROMS.CSLA.Library
{ {
if (_PreviousID != tmp.PreviousID) if (_PreviousID != tmp.PreviousID)
{ {
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value MyPrevious?.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value _PreviousID = tmp.PreviousID; // Update the value
} }
_MyPrevious = null; // Reset list so that the next line gets a new list _MyPrevious = null; // Reset list so that the next line gets a new list
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value MyPrevious?.RefreshNextItems(); // Update List for new value
//if (_ContentID != tmp.ContentID)
//{ MyContent?.RefreshContentItems(); // Update List for old value
if (MyContent != null) MyContent.RefreshContentItems(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value _ContentID = tmp.ContentID; // Update the value
//}
_MyContent = null; // Reset list so that the next line gets a new list _MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentItems(); // Update List for new value MyContent?.RefreshContentItems(); // Update List for new value
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
_ItemInfoExtension.Refresh(this); _ItemInfoExtension.Refresh(this);
@@ -596,11 +547,11 @@ namespace VEPROMS.CSLA.Library
{ {
if (_PreviousID != tmp.PreviousID) if (_PreviousID != tmp.PreviousID)
{ {
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value MyPrevious?.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value _PreviousID = tmp.PreviousID; // Update the value
} }
_MyPrevious = null; // Reset list so that the next line gets a new list _MyPrevious = null; // Reset list so that the next line gets a new list
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value MyPrevious?.RefreshNextItems(); // Update List for new value
_DTS = tmp.DTS; _DTS = tmp.DTS;
_UserID = tmp.UserID; _UserID = tmp.UserID;
_ItemInfoExtension.Refresh(this); _ItemInfoExtension.Refresh(this);
@@ -675,13 +626,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()] [Serializable()]
protected class PKCriteria protected class PKCriteria
{ {
private int _ItemID; private readonly int _ItemID;
public int ItemID public int ItemID => _ItemID;
{ get { return _ItemID; } } public PKCriteria(int itemID) => _ItemID = itemID;
public PKCriteria(int itemID)
{
_ItemID = itemID;
}
} }
protected void ReadData(SafeDataReader dr) protected void ReadData(SafeDataReader dr)
{ {
@@ -746,7 +693,7 @@ namespace VEPROMS.CSLA.Library
#endregion #endregion
// Standard Refresh // Standard Refresh
#region extension #region extension
ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension(); readonly ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension();
[Serializable()] [Serializable()]
partial class ItemInfoExtension : extensionBase { } partial class ItemInfoExtension : extensionBase { }
[Serializable()] [Serializable()]
@@ -762,10 +709,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemInfo) if (destType == typeof(string) && value is ItemInfo info)
{ {
// Return the ToString value // Return the ToString value
return ((ItemInfo)value).ToString(); return info.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -30,8 +28,7 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
internal new IList<ItemInfo> Items internal new IList<ItemInfo> Items => base.Items;
{ get { return base.Items; } }
public void AddEvents() public void AddEvents()
{ {
foreach (ItemInfo tmp in this) foreach (ItemInfo tmp in this)
@@ -48,14 +45,13 @@ namespace VEPROMS.CSLA.Library
} }
void tmp_Deleted(object sender) void tmp_Deleted(object sender)
{ {
ItemInfo ii = sender as ItemInfo; if (sender is ItemInfo ii)
if (ii != null)
{ {
RefreshingList = true; RefreshingList = true;
IsReadOnly = false; IsReadOnly = false;
Remove(ii); Remove(ii);
IsReadOnly = true; IsReadOnly = true;
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, 0)); OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, 0));
RefreshingList = false; RefreshingList = false;
} }
} }
@@ -75,7 +71,7 @@ namespace VEPROMS.CSLA.Library
if (SourceOfList != "Search" && (sender as ItemInfo).MyPrevious != null && i > 0 && base[i - 1].ItemID != (sender as ItemInfo).MyPrevious.ItemID) if (SourceOfList != "Search" && (sender as ItemInfo).MyPrevious != null && i > 0 && base[i - 1].ItemID != (sender as ItemInfo).MyPrevious.ItemID)
Items.Insert(i, (sender as ItemInfo).MyPrevious); Items.Insert(i, (sender as ItemInfo).MyPrevious);
IsReadOnly = true; IsReadOnly = true;
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
RefreshingList = false; RefreshingList = false;
break; break;
} }
@@ -87,27 +83,15 @@ namespace VEPROMS.CSLA.Library
get { return _SourceOfList; } get { return _SourceOfList; }
set { _SourceOfList = value; } set { _SourceOfList = value; }
} }
//private void ShowList(string txt)
//{
// Console.WriteLine("\r\n{0} - {1} - {2}: i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText", txt, Count, SourceOfList);
// for (int i = 0; i < Count; i++)
// {
// Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText, base[i].MyItemInfoUnique, base[i].Disposed);
// }
//}
private bool _Disposed = false; private bool _Disposed = false;
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemInfoList() ~ItemInfoList()
{ {
_CountFinalized++; _CountFinalized++;
@@ -149,22 +133,7 @@ namespace VEPROMS.CSLA.Library
/// <summary> /// <summary>
/// Reset the list of all ItemInfo. /// Reset the list of all ItemInfo.
/// </summary> /// </summary>
public static void Reset() public static void Reset() => _ItemInfoList = null;
{
_ItemInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ItemInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ItemInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ItemInfoList.Get", ex);
// }
//}
public static ItemInfoList GetNext(int? previousID) public static ItemInfoList GetNext(int? previousID)
{ {
try try
@@ -199,7 +168,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal #region Data Access Portal
private void DataPortal_Fetch() private void DataPortal_Fetch()
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_Fetch", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_Fetch", GetHashCode());
try try
{ {
@@ -213,7 +182,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
IsReadOnly = false; IsReadOnly = false;
while (dr.Read()) this.Add(new ItemInfo(dr)); while (dr.Read()) Add(new ItemInfo(dr));
IsReadOnly = true; IsReadOnly = true;
} }
} }
@@ -224,15 +193,12 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_Fetch", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class PreviousIDCriteria private class PreviousIDCriteria
{ {
public PreviousIDCriteria(int? previousID) public PreviousIDCriteria(int? previousID) => _PreviousID = previousID;
{
_PreviousID = previousID;
}
private int? _PreviousID; private int? _PreviousID;
public int? PreviousID public int? PreviousID
{ {
@@ -242,7 +208,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(PreviousIDCriteria criteria) private void DataPortal_Fetch(PreviousIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchPreviousID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchPreviousID", GetHashCode());
try try
{ {
@@ -257,7 +223,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
IsReadOnly = false; IsReadOnly = false;
while (dr.Read()) this.Add(new ItemInfo(dr)); while (dr.Read()) Add(new ItemInfo(dr));
IsReadOnly = true; IsReadOnly = true;
} }
} }
@@ -268,15 +234,12 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchPreviousID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchPreviousID", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class ContentIDCriteria private class ContentIDCriteria
{ {
public ContentIDCriteria(int contentID) public ContentIDCriteria(int contentID) => _ContentID = contentID;
{
_ContentID = contentID;
}
private int _ContentID; private int _ContentID;
public int ContentID public int ContentID
{ {
@@ -286,7 +249,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(ContentIDCriteria criteria) private void DataPortal_Fetch(ContentIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchContentID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchContentID", GetHashCode());
try try
{ {
@@ -301,7 +264,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
IsReadOnly = false; IsReadOnly = false;
while (dr.Read()) this.Add(new ItemInfo(dr)); while (dr.Read()) Add(new ItemInfo(dr));
IsReadOnly = true; IsReadOnly = true;
} }
} }
@@ -312,38 +275,27 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchContentID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchContentID", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary> /// <summary>
/// Called to get the properties of this type. Returns properties with certain /// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here. /// attributes. this restriction is not implemented here.
/// </summary> /// </summary>
/// <param name="attributes"></param> /// <param name="attributes"></param>
/// <returns></returns> /// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return GetProperties(); }
/// <summary> /// <summary>
/// Called to get the properties of this type. /// Called to get the properties of this type.
/// </summary> /// </summary>
@@ -353,7 +305,7 @@ namespace VEPROMS.CSLA.Library
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemInfoListPropertyDescriptor pd = new ItemInfoListPropertyDescriptor(this, i); ItemInfoListPropertyDescriptor pd = new ItemInfoListPropertyDescriptor(this, i);
@@ -370,7 +322,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemInfoListPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemInfoListPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemInfo Item { get { return (ItemInfo)_Item; } }
public ItemInfoListPropertyDescriptor(ItemInfoList collection, int index) : base(collection, index) {; } public ItemInfoListPropertyDescriptor(ItemInfoList collection, int index) : base(collection, index) {; }
} }
#endregion #endregion
@@ -379,10 +330,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemInfoList) if (destType == typeof(string) && value is ItemInfoList list)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemInfoList)value).Items.Count.ToString() + " Items"; return $"{list.Items.Count} Items";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
+48 -171
View File
@@ -9,12 +9,9 @@
// ======================================================================== // ========================================================================
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _ContentID; private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int ContentID public int ContentID
@@ -180,35 +174,13 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemPart</returns> /// <returns>A Unique ID for the current ItemPart</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemPartUnique; // Absolutely Unique ID
{ public override bool IsDirty => base.IsDirty;
return MyItemPartUnique; // Absolutely Unique ID [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
} public bool IsDirtyList(List<object> list) => base.IsDirty;
// CSLATODO: Replace base ItemPart.ToString function as necessary public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
/// <summary> [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
/// Overrides Base ToString public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
/// </summary>
/// <returns>A string representation of current ItemPart</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;
}
#endregion #endregion
#region ValidationRules #region ValidationRules
[NonSerialized] [NonSerialized]
@@ -236,8 +208,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -249,73 +221,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// CSLATODO: Add other validation rules // CSLATODO: Add other validation rules
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(FromType, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemPartUnique = 0; private static int _ItemPartUnique = 0;
private static int ItemPartUnique private static int ItemPartUnique => ++_ItemPartUnique;
{ get { return ++_ItemPartUnique; } } private readonly int _MyItemPartUnique = ItemPartUnique;
private int _MyItemPartUnique = ItemPartUnique; // Absolutely Unique ID - Editable FK
public int MyItemPartUnique // Absolutely Unique ID - Editable FK public int MyItemPartUnique => _MyItemPartUnique;
{ get { return _MyItemPartUnique; } } internal static ItemPart New(Content myContent, int fromType) => new ItemPart(myContent, fromType);
internal static ItemPart New(Content myContent, int fromType) internal static ItemPart Get(SafeDataReader dr) => new ItemPart(dr);
{
return new ItemPart(myContent, fromType);
}
internal static ItemPart Get(SafeDataReader dr)
{
return new ItemPart(dr);
}
public ItemPart() public ItemPart()
{ {
MarkAsChild(); MarkAsChild();
@@ -343,15 +264,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemPart() ~ItemPart()
{ {
_CountFinalized++; _CountFinalized++;
@@ -392,33 +309,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Item myItem) internal void Insert(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Part.Add(cn, _MyContent, _FromType, myItem, _DTS, _UserID); {
_LastChanged = Part.Add(cn, _MyContent, _FromType, myItem, _DTS, _UserID);
}
MarkOld(); MarkOld();
} }
internal void Update(Item myItem) internal void Update(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Part.Update(cn, _ContentID, _FromType, myItem.ItemID, _DTS, _UserID, ref _LastChanged); {
_LastChanged = Part.Update(cn, _ContentID, _FromType, myItem.ItemID, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItem) internal void DeleteSelf(Item myItem)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
Part.Remove(cn, _ContentID, _FromType); {
Part.Remove(cn, _ContentID, _FromType);
}
MarkNew(); MarkNew();
} }
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemPartExtension _ItemPartExtension = new ItemPartExtension(); readonly ItemPartExtension _ItemPartExtension = new ItemPartExtension();
[Serializable()] [Serializable()]
partial class ItemPartExtension : extensionBase partial class ItemPartExtension : extensionBase
{ {
@@ -427,14 +354,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual DateTime DefaultDTS public virtual DateTime DefaultDTS => DateTime.Now;
{ public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -463,57 +384,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemPart) if (destType == typeof(string) && value is ItemPart part)
{ {
// Return the ToString value // Return the ToString value
return ((ItemPart)value).ToString(); return part.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemPartExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemPart
// {
// partial class ItemPartExtension : 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 */);
// }
// }
// }
//}
+71 -110
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{ // One To Many
get { return _ErrorMessage; } public ItemPart this[Content myContent, int fromType]
}
// One To Many
public ItemPart this[Content myContent, int fromType]
{ {
get get
{ {
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null; return null;
} }
} }
public new System.Collections.Generic.IList<ItemPart> Items public new System.Collections.Generic.IList<ItemPart> Items => base.Items;
{ public ItemPart GetItem(Content myContent, int fromType)
get { return base.Items; }
}
public ItemPart GetItem(Content myContent, int fromType)
{ {
foreach (ItemPart part in this) foreach (ItemPart part in this)
if (part.ContentID == myContent.ContentID && part.FromType == fromType) if (part.ContentID == myContent.ContentID && part.FromType == fromType)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ItemPart Add(Content myContent, int fromType) // One to Many public ItemPart Add(Content myContent, int fromType) // One to Many
{ {
ItemPart part = ItemPart.New(myContent, fromType); ItemPart part = ItemPart.New(myContent, fromType);
this.Add(part); Add(part);
return part; return part;
} }
public void Remove(Content myContent, int fromType) public void Remove(Content myContent, int fromType)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true; return true;
return false; return false;
} }
public override bool IsValid public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{ {
get { return IsValidList(new List<object>()); } // run through all the child objects
} // and if any are invalid then the
public bool IsValidList(List<object> list) // collection is invalid
{ foreach (ItemPart child in this)
// run through all the child objects if (!child.IsValidList(list))
// and if any are invalid then the {
// collection is invalid //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
foreach (ItemPart child in this) return false;
if (!child.IsValidList(list)) }
{ return true;
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); }
return false;
}
return true;
}
#endregion #endregion
#region ValidationRules #region ValidationRules
public IVEHasBrokenRules HasBrokenRules public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
internal static ItemParts New() internal static ItemParts New() => new ItemParts();
{ internal static ItemParts Get(SafeDataReader dr) => new ItemParts(dr);
return new ItemParts(); public static ItemParts GetByItemID(int itemID)
}
internal static ItemParts Get(SafeDataReader dr)
{
return new ItemParts(dr);
}
public static ItemParts GetByItemID(int itemID)
{ {
try try
{ {
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemParts.GetByItemID", ex); throw new DbCslaException("Error on ItemParts.GetByItemID", ex);
} }
} }
private ItemParts() private ItemParts() => MarkAsChild();
{ internal ItemParts(SafeDataReader dr)
MarkAsChild();
}
internal ItemParts(SafeDataReader dr)
{ {
MarkAsChild(); MarkAsChild();
Fetch(dr); Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ItemParts()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemParts()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database // called to load data from the database
private void Fetch(SafeDataReader dr) private void Fetch(SafeDataReader dr)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
while (dr.Read()) while (dr.Read())
this.Add(ItemPart.Get(dr)); Add(ItemPart.Get(dr));
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class ItemIDCriteria private class ItemIDCriteria
{ {
public ItemIDCriteria(int itemID) public ItemIDCriteria(int itemID) => _ItemID = itemID;
{ private int _ItemID;
_ItemID = itemID;
}
private int _ItemID;
public int ItemID public int ItemID
{ {
get { return _ItemID; } get { return _ItemID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(ItemIDCriteria criteria) private void DataPortal_Fetch(ItemIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemParts.DataPortal_FetchItemID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemParts.DataPortal_FetchItemID", GetHashCode());
try try
{ {
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout; cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
while (dr.Read()) this.Add(new ItemPart(dr)); while (dr.Read()) Add(new ItemPart(dr));
} }
} }
} }
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemParts.DataPortal_FetchItemID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemParts.DataPortal_FetchItemID", ex);
throw new DbCslaException("ItemParts.DataPortal_Fetch", ex); throw new DbCslaException("ItemParts.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
internal void Update(Item item) internal void Update(Item item)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
try try
{ {
// update (thus deleting) any deleted child objects // update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
} }
finally finally
{ {
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemPartsPropertyDescriptor pd = new ItemPartsPropertyDescriptor(this, i); ItemPartsPropertyDescriptor pd = new ItemPartsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemPartsPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemPartsPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemPart Item { get { return (ItemPart)_Item; } }
public ItemPartsPropertyDescriptor(ItemParts collection, int index) : base(collection, index) { ;} public ItemPartsPropertyDescriptor(ItemParts collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemParts) if (destType == typeof(string) && value is ItemParts parts)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemParts)value).Items.Count.ToString() + " Parts"; return $"{parts.Items.Count} Parts";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -9,12 +9,9 @@
// ======================================================================== // ========================================================================
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _TransitionID; private int _TransitionID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int TransitionID public int TransitionID
@@ -295,15 +289,6 @@ namespace VEPROMS.CSLA.Library
{ {
return MyItemTransition_RangeIDUnique; // Absolutely Unique ID return MyItemTransition_RangeIDUnique; // Absolutely Unique ID
} }
// CSLATODO: Replace base ItemTransition_RangeID.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemTransition_RangeID</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty public override bool IsDirty
{ {
get get
@@ -318,18 +303,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)); return base.IsDirty || (_MyContent != null && _MyContent.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
} }
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list) public bool IsValidList(List<object> list)
{ {
if (list.Contains(this)) if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid; return (IsNew && !IsDirty) || base.IsValid;
list.Add(this); list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_MyContent == null || _MyContent.IsValidList(list));
} }
#endregion #endregion
#region ValidationRules #region ValidationRules
@@ -359,8 +341,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -385,82 +367,22 @@ namespace VEPROMS.CSLA.Library
} }
return true; return true;
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(TransitionID, "<Role(s)>");
//AuthorizationRules.AllowRead(FromID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FromID, "<Role(s)>");
//AuthorizationRules.AllowRead(ToID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ToID, "<Role(s)>");
//AuthorizationRules.AllowRead(IsRange, "<Role(s)>");
//AuthorizationRules.AllowWrite(IsRange, "<Role(s)>");
//AuthorizationRules.AllowRead(TranType, "<Role(s)>");
//AuthorizationRules.AllowWrite(TranType, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemTransition_RangeIDUnique = 0; private static int _ItemTransition_RangeIDUnique = 0;
private static int ItemTransition_RangeIDUnique private static int ItemTransition_RangeIDUnique => ++_ItemTransition_RangeIDUnique;
{ get { return ++_ItemTransition_RangeIDUnique; } } private readonly int _MyItemTransition_RangeIDUnique = ItemTransition_RangeIDUnique;
private int _MyItemTransition_RangeIDUnique = ItemTransition_RangeIDUnique; // Absolutely Unique ID - Editable FK
public int MyItemTransition_RangeIDUnique // Absolutely Unique ID - Editable FK public int MyItemTransition_RangeIDUnique => _MyItemTransition_RangeIDUnique;
{ get { return _MyItemTransition_RangeIDUnique; } } internal static ItemTransition_RangeID New(Content myContent, Item myItemToID) => new ItemTransition_RangeID(myContent, myItemToID);
internal static ItemTransition_RangeID New(Content myContent, Item myItemToID) internal static ItemTransition_RangeID Get(SafeDataReader dr) => new ItemTransition_RangeID(dr);
{
return new ItemTransition_RangeID(myContent, myItemToID);
}
internal static ItemTransition_RangeID Get(SafeDataReader dr)
{
return new ItemTransition_RangeID(dr);
}
public ItemTransition_RangeID() public ItemTransition_RangeID()
{ {
MarkAsChild(); MarkAsChild();
@@ -493,15 +415,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemTransition_RangeID() ~ItemTransition_RangeID()
{ {
_CountFinalized++; _CountFinalized++;
@@ -546,33 +464,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Item myItemRangeID) internal void Insert(Item myItemRangeID)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); {
_LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID);
}
MarkOld(); MarkOld();
} }
internal void Update(Item myItemRangeID) internal void Update(Item myItemRangeID)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, _ToID, myItemRangeID.ItemID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); {
_LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, _ToID, myItemRangeID.ItemID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItemRangeID) internal void DeleteSelf(Item myItemRangeID)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
Transition.Remove(cn, _TransitionID); {
Transition.Remove(cn, _TransitionID);
}
MarkNew(); MarkNew();
} }
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemTransition_RangeIDExtension _ItemTransition_RangeIDExtension = new ItemTransition_RangeIDExtension(); readonly ItemTransition_RangeIDExtension _ItemTransition_RangeIDExtension = new ItemTransition_RangeIDExtension();
[Serializable()] [Serializable()]
partial class ItemTransition_RangeIDExtension : extensionBase partial class ItemTransition_RangeIDExtension : extensionBase
{ {
@@ -581,22 +509,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual int DefaultIsRange public virtual int DefaultIsRange => 0;
{ public virtual int DefaultTranType => 0;
get { return 0; } public virtual DateTime DefaultDTS => DateTime.Now;
} public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
public virtual int DefaultTranType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -625,65 +541,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemTransition_RangeID) if (destType == typeof(string) && value is ItemTransition_RangeID iD)
{ {
// Return the ToString value // Return the ToString value
return ((ItemTransition_RangeID)value).ToString(); return iD.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemTransition_RangeIDExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemTransition_RangeID
// {
// partial class ItemTransition_RangeIDExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultIsRange
// {
// get { return 0; }
// }
// public virtual int DefaultTranType
// {
// 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 */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ======================================================================== // ========================================================================
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{
get { return _ErrorMessage; }
}
private int _TransitionID; private int _TransitionID;
[System.ComponentModel.DataObjectField(true, true)] [System.ComponentModel.DataObjectField(true, true)]
public int TransitionID public int TransitionID
@@ -288,19 +282,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary> /// </summary>
/// <returns>A Unique ID for the current ItemTransition_ToID</returns> /// <returns>A Unique ID for the current ItemTransition_ToID</returns>
protected override object GetIdValue() protected override object GetIdValue() => MyItemTransition_ToIDUnique; // Absolutely Unique ID
{
return MyItemTransition_ToIDUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ItemTransition_ToID.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemTransition_ToID</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty public override bool IsDirty
{ {
get get
@@ -315,18 +297,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this)) if (base.IsDirty || list.Contains(this))
return base.IsDirty; return base.IsDirty;
list.Add(this); list.Add(this);
return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)); return base.IsDirty || (_MyContent != null && _MyContent.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
} }
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list) public bool IsValidList(List<object> list)
{ {
if (list.Contains(this)) if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid; return (IsNew && !IsDirty) || base.IsValid;
list.Add(this); list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); return ((IsNew && !IsDirty) || base.IsValid) && (_MyContent == null || _MyContent.IsValidList(list));
} }
#endregion #endregion
#region ValidationRules #region ValidationRules
@@ -356,8 +335,8 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
protected override void AddBusinessRules() protected override void AddBusinessRules()
@@ -382,82 +361,22 @@ namespace VEPROMS.CSLA.Library
} }
return true; return true;
} }
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion #endregion
#region Authorization Rules #region Authorization Rules
protected override void AddAuthorizationRules() protected override void AddAuthorizationRules()
{ {
//CSLATODO: Who can read/write which fields //CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(TransitionID, "<Role(s)>");
//AuthorizationRules.AllowRead(FromID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FromID, "<Role(s)>");
//AuthorizationRules.AllowRead(RangeID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RangeID, "<Role(s)>");
//AuthorizationRules.AllowRead(IsRange, "<Role(s)>");
//AuthorizationRules.AllowWrite(IsRange, "<Role(s)>");
//AuthorizationRules.AllowRead(TranType, "<Role(s)>");
//AuthorizationRules.AllowWrite(TranType, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
public int CurrentEditLevel public int CurrentEditLevel => EditLevel;
{ get { return EditLevel; } }
private static int _ItemTransition_ToIDUnique = 0; private static int _ItemTransition_ToIDUnique = 0;
private static int ItemTransition_ToIDUnique private static int ItemTransition_ToIDUnique => ++_ItemTransition_ToIDUnique;
{ get { return ++_ItemTransition_ToIDUnique; } } private readonly int _MyItemTransition_ToIDUnique = ItemTransition_ToIDUnique;
private int _MyItemTransition_ToIDUnique = ItemTransition_ToIDUnique; // Absolutely Unique ID - Editable FK
public int MyItemTransition_ToIDUnique // Absolutely Unique ID - Editable FK public int MyItemTransition_ToIDUnique => _MyItemTransition_ToIDUnique;
{ get { return _MyItemTransition_ToIDUnique; } } internal static ItemTransition_ToID New(Content myContent, Item myItemRangeID) => new ItemTransition_ToID(myContent, myItemRangeID);
internal static ItemTransition_ToID New(Content myContent, Item myItemRangeID) internal static ItemTransition_ToID Get(SafeDataReader dr) => new ItemTransition_ToID(dr);
{
return new ItemTransition_ToID(myContent, myItemRangeID);
}
internal static ItemTransition_ToID Get(SafeDataReader dr)
{
return new ItemTransition_ToID(dr);
}
public ItemTransition_ToID() public ItemTransition_ToID()
{ {
MarkAsChild(); MarkAsChild();
@@ -490,15 +409,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemTransition_ToID() ~ItemTransition_ToID()
{ {
_CountFinalized++; _CountFinalized++;
@@ -543,33 +458,43 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Item myItemToID) internal void Insert(Item myItemToID)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); {
_LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID);
}
MarkOld(); MarkOld();
} }
internal void Update(Item myItemToID) internal void Update(Item myItemToID)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
_LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, myItemToID.ItemID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); {
_LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, myItemToID.ItemID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld(); MarkOld();
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItemToID) internal void DeleteSelf(Item myItemToID)
{ {
// if we're not dirty then don't update the database // if we're not dirty then don't update the database
if (!this.IsDirty) return; if (!IsDirty) return;
// if we're new then don't update the database // if we're new then don't update the database
if (this.IsNew) return; if (IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
Transition.Remove(cn, _TransitionID); {
Transition.Remove(cn, _TransitionID);
}
MarkNew(); MarkNew();
} }
#endregion #endregion
// Standard Default Code // Standard Default Code
#region extension #region extension
ItemTransition_ToIDExtension _ItemTransition_ToIDExtension = new ItemTransition_ToIDExtension(); readonly ItemTransition_ToIDExtension _ItemTransition_ToIDExtension = new ItemTransition_ToIDExtension();
[Serializable()] [Serializable()]
partial class ItemTransition_ToIDExtension : extensionBase partial class ItemTransition_ToIDExtension : extensionBase
{ {
@@ -578,22 +503,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase class extensionBase
{ {
// Default Values // Default Values
public virtual int DefaultIsRange public virtual int DefaultIsRange => 0;
{ public virtual int DefaultTranType => 0;
get { return 0; } public virtual DateTime DefaultDTS => DateTime.Now;
} public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
public virtual int DefaultTranType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
// Authorization Rules // Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{ {
@@ -622,65 +535,13 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemTransition_ToID) if (destType == typeof(string) && value is ItemTransition_ToID iD)
{ {
// Return the ToString value // Return the ToString value
return ((ItemTransition_ToID)value).ToString(); return iD.ToString();
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
} }
#endregion #endregion
} // Namespace } // Namespace
//// The following is a sample Extension File. You can use it to create ItemTransition_ToIDExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemTransition_ToID
// {
// partial class ItemTransition_ToIDExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultIsRange
// {
// get { return 0; }
// }
// public virtual int DefaultTranType
// {
// 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 System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{ // One To Many
get { return _ErrorMessage; } public ItemTransition_RangeID this[Transition myTransition]
}
// One To Many
public ItemTransition_RangeID this[Transition myTransition]
{ {
get get
{ {
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null; return null;
} }
} }
public new System.Collections.Generic.IList<ItemTransition_RangeID> Items public new System.Collections.Generic.IList<ItemTransition_RangeID> Items => base.Items;
{ public ItemTransition_RangeID GetItem(Transition myTransition)
get { return base.Items; }
}
public ItemTransition_RangeID GetItem(Transition myTransition)
{ {
foreach (ItemTransition_RangeID transition in this) foreach (ItemTransition_RangeID transition in this)
if (transition.TransitionID == myTransition.TransitionID) if (transition.TransitionID == myTransition.TransitionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ItemTransition_RangeID Add(Content myContent, Item myItemToID) // One to Many public ItemTransition_RangeID Add(Content myContent, Item myItemToID) // One to Many
{ {
ItemTransition_RangeID transition = ItemTransition_RangeID.New(myContent, myItemToID); ItemTransition_RangeID transition = ItemTransition_RangeID.New(myContent, myItemToID);
this.Add(transition); Add(transition);
return transition; return transition;
} }
public void Remove(Transition myTransition) public void Remove(Transition myTransition)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true; return true;
return false; return false;
} }
public override bool IsValid public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{ {
get { return IsValidList(new List<object>()); } // run through all the child objects
} // and if any are invalid then the
public bool IsValidList(List<object> list) // collection is invalid
{ foreach (ItemTransition_RangeID child in this)
// run through all the child objects if (!child.IsValidList(list))
// and if any are invalid then the {
// collection is invalid //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
foreach (ItemTransition_RangeID child in this) return false;
if (!child.IsValidList(list)) }
{ return true;
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); }
return false;
}
return true;
}
#endregion #endregion
#region ValidationRules #region ValidationRules
public IVEHasBrokenRules HasBrokenRules public IVEHasBrokenRules HasBrokenRules
@@ -137,7 +126,7 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
#endregion #endregion
@@ -174,16 +163,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ItemTransitions_RangeID()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemTransitions_RangeID()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -198,19 +183,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database // called to load data from the database
private void Fetch(SafeDataReader dr) private void Fetch(SafeDataReader dr)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
while (dr.Read()) while (dr.Read())
this.Add(ItemTransition_RangeID.Get(dr)); Add(ItemTransition_RangeID.Get(dr));
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class RangeIDCriteria private class RangeIDCriteria
{ {
public RangeIDCriteria(int rangeID) public RangeIDCriteria(int rangeID) => _RangeID = rangeID;
{ private int _RangeID;
_RangeID = rangeID;
}
private int _RangeID;
public int RangeID public int RangeID
{ {
get { return _RangeID; } get { return _RangeID; }
@@ -219,7 +201,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(RangeIDCriteria criteria) private void DataPortal_Fetch(RangeIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransitions_RangeID.DataPortal_FetchRangeID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransitions_RangeID.DataPortal_FetchRangeID", GetHashCode());
try try
{ {
@@ -233,7 +215,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout; cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
while (dr.Read()) this.Add(new ItemTransition_RangeID(dr)); while (dr.Read()) Add(new ItemTransition_RangeID(dr));
} }
} }
} }
@@ -243,11 +225,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransitions_RangeID.DataPortal_FetchRangeID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransitions_RangeID.DataPortal_FetchRangeID", ex);
throw new DbCslaException("ItemTransitions_RangeID.DataPortal_Fetch", ex); throw new DbCslaException("ItemTransitions_RangeID.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
internal void Update(Item item) internal void Update(Item item)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
try try
{ {
// update (thus deleting) any deleted child objects // update (thus deleting) any deleted child objects
@@ -266,49 +248,38 @@ namespace VEPROMS.CSLA.Library
} }
finally finally
{ {
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemTransitions_RangeIDPropertyDescriptor pd = new ItemTransitions_RangeIDPropertyDescriptor(this, i); ItemTransitions_RangeIDPropertyDescriptor pd = new ItemTransitions_RangeIDPropertyDescriptor(this, i);
@@ -325,7 +296,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemTransitions_RangeIDPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemTransitions_RangeIDPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemTransition_RangeID Item { get { return (ItemTransition_RangeID)_Item; } }
public ItemTransitions_RangeIDPropertyDescriptor(ItemTransitions_RangeID collection, int index) : base(collection, index) { ;} public ItemTransitions_RangeIDPropertyDescriptor(ItemTransitions_RangeID collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -334,10 +304,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemTransitions_RangeID) if (destType == typeof(string) && value is ItemTransitions_RangeID iD)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemTransitions_RangeID)value).Items.Count.ToString() + " Transitions_RangeID"; return $"{iD.Items.Count} Transitions_RangeID";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using Csla; using Csla;
using Csla.Data; using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using Csla.Validation; using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
#region Business Methods #region Business Methods
private string _ErrorMessage = string.Empty; private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage public string ErrorMessage => _ErrorMessage;
{ // One To Many
get { return _ErrorMessage; } public ItemTransition_ToID this[Transition myTransition]
}
// One To Many
public ItemTransition_ToID this[Transition myTransition]
{ {
get get
{ {
@@ -61,7 +56,7 @@ namespace VEPROMS.CSLA.Library
public ItemTransition_ToID Add(Content myContent, Item myItemRangeID) // One to Many public ItemTransition_ToID Add(Content myContent, Item myItemRangeID) // One to Many
{ {
ItemTransition_ToID transition = ItemTransition_ToID.New(myContent, myItemRangeID); ItemTransition_ToID transition = ItemTransition_ToID.New(myContent, myItemRangeID);
this.Add(transition); Add(transition);
return transition; return transition;
} }
public void Remove(Transition myTransition) public void Remove(Transition myTransition)
@@ -103,23 +98,20 @@ namespace VEPROMS.CSLA.Library
return true; return true;
return false; return false;
} }
public override bool IsValid public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{ {
get { return IsValidList(new List<object>()); } // run through all the child objects
} // and if any are invalid then the
public bool IsValidList(List<object> list) // collection is invalid
{ foreach (ItemTransition_ToID child in this)
// run through all the child objects if (!child.IsValidList(list))
// and if any are invalid then the {
// collection is invalid //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
foreach (ItemTransition_ToID child in this) return false;
if (!child.IsValidList(list)) }
{ return true;
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); }
return false;
}
return true;
}
#endregion #endregion
#region ValidationRules #region ValidationRules
public IVEHasBrokenRules HasBrokenRules public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +129,14 @@ namespace VEPROMS.CSLA.Library
get get
{ {
IVEHasBrokenRules hasBrokenRules = HasBrokenRules; IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); return hasBrokenRules?.BrokenRules;
} }
} }
#endregion #endregion
#region Factory Methods #region Factory Methods
internal static ItemTransitions_ToID New() internal static ItemTransitions_ToID New() => new ItemTransitions_ToID();
{ internal static ItemTransitions_ToID Get(SafeDataReader dr) => new ItemTransitions_ToID(dr);
return new ItemTransitions_ToID(); public static ItemTransitions_ToID GetByToID(int toID)
}
internal static ItemTransitions_ToID Get(SafeDataReader dr)
{
return new ItemTransitions_ToID(dr);
}
public static ItemTransitions_ToID GetByToID(int toID)
{ {
try try
{ {
@@ -161,11 +147,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemTransitions_ToID.GetByToID", ex); throw new DbCslaException("Error on ItemTransitions_ToID.GetByToID", ex);
} }
} }
private ItemTransitions_ToID() private ItemTransitions_ToID() => MarkAsChild();
{ internal ItemTransitions_ToID(SafeDataReader dr)
MarkAsChild();
}
internal ItemTransitions_ToID(SafeDataReader dr)
{ {
MarkAsChild(); MarkAsChild();
Fetch(dr); Fetch(dr);
@@ -174,16 +157,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0; private static int _CountCreated = 0;
private static int _CountDisposed = 0; private static int _CountDisposed = 0;
private static int _CountFinalized = 0; private static int _CountFinalized = 0;
private static int IncrementCountCreated private static int IncrementCountCreated => ++_CountCreated;
{ get { return ++_CountCreated; } } private readonly int _CountWhenCreated = IncrementCountCreated;
private int _CountWhenCreated = IncrementCountCreated; public static int CountCreated => _CountCreated;
public static int CountCreated public static int CountNotDisposed => _CountCreated - _CountDisposed;
{ get { return _CountCreated; } } public static int CountNotFinalized => _CountCreated - _CountFinalized;
public static int CountNotDisposed ~ItemTransitions_ToID()
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemTransitions_ToID()
{ {
_CountFinalized++; _CountFinalized++;
} }
@@ -198,19 +177,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database // called to load data from the database
private void Fetch(SafeDataReader dr) private void Fetch(SafeDataReader dr)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
while (dr.Read()) while (dr.Read())
this.Add(ItemTransition_ToID.Get(dr)); Add(ItemTransition_ToID.Get(dr));
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
[Serializable()] [Serializable()]
private class ToIDCriteria private class ToIDCriteria
{ {
public ToIDCriteria(int toID) public ToIDCriteria(int toID) => _ToID = toID;
{ private int _ToID;
_ToID = toID;
}
private int _ToID;
public int ToID public int ToID
{ {
get { return _ToID; } get { return _ToID; }
@@ -219,7 +195,7 @@ namespace VEPROMS.CSLA.Library
} }
private void DataPortal_Fetch(ToIDCriteria criteria) private void DataPortal_Fetch(ToIDCriteria criteria)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransitions_ToID.DataPortal_FetchToID", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransitions_ToID.DataPortal_FetchToID", GetHashCode());
try try
{ {
@@ -233,7 +209,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout; cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{ {
while (dr.Read()) this.Add(new ItemTransition_ToID(dr)); while (dr.Read()) Add(new ItemTransition_ToID(dr));
} }
} }
} }
@@ -243,11 +219,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransitions_ToID.DataPortal_FetchToID", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransitions_ToID.DataPortal_FetchToID", ex);
throw new DbCslaException("ItemTransitions_ToID.DataPortal_Fetch", ex); throw new DbCslaException("ItemTransitions_ToID.DataPortal_Fetch", ex);
} }
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
internal void Update(Item item) internal void Update(Item item)
{ {
this.RaiseListChangedEvents = false; RaiseListChangedEvents = false;
try try
{ {
// update (thus deleting) any deleted child objects // update (thus deleting) any deleted child objects
@@ -266,49 +242,38 @@ namespace VEPROMS.CSLA.Library
} }
finally finally
{ {
this.RaiseListChangedEvents = true; RaiseListChangedEvents = true;
} }
} }
#endregion #endregion
#region ICustomTypeDescriptor impl #region ICustomTypeDescriptor impl
public String GetClassName() public string GetClassName() => TypeDescriptor.GetClassName(this, true);
{ return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public AttributeCollection GetAttributes() public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
{ return TypeDescriptor.GetAttributes(this, true); } public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public String GetComponentName() public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
{ return TypeDescriptor.GetComponentName(this, true); } public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public TypeConverter GetConverter() public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
{ return TypeDescriptor.GetConverter(this, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptor GetDefaultEvent() public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
{ return TypeDescriptor.GetDefaultEvent(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) => this;
public PropertyDescriptor GetDefaultProperty() /// <summary>
{ return TypeDescriptor.GetDefaultProperty(this, true); } /// Called to get the properties of this type. Returns properties with certain
public object GetEditor(Type editorBaseType) /// attributes. this restriction is not implemented here.
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); } /// </summary>
public EventDescriptorCollection GetEvents(Attribute[] attributes) /// <param name="attributes"></param>
{ return TypeDescriptor.GetEvents(this, attributes, true); } /// <returns></returns>
public EventDescriptorCollection GetEvents() public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
{ return TypeDescriptor.GetEvents(this, true); } /// <summary>
public object GetPropertyOwner(PropertyDescriptor pd) /// Called to get the properties of this type.
{ return this; } /// </summary>
/// <summary> /// <returns></returns>
/// Called to get the properties of this type. Returns properties with certain public PropertyDescriptorCollection GetProperties()
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{ {
// Create a collection object to hold property descriptors // Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list // Iterate the list
for (int i = 0; i < this.Items.Count; i++) for (int i = 0; i < Items.Count; i++)
{ {
// Create a property descriptor for the item and add to the property descriptor collection // Create a property descriptor for the item and add to the property descriptor collection
ItemTransitions_ToIDPropertyDescriptor pd = new ItemTransitions_ToIDPropertyDescriptor(this, i); ItemTransitions_ToIDPropertyDescriptor pd = new ItemTransitions_ToIDPropertyDescriptor(this, i);
@@ -325,7 +290,6 @@ namespace VEPROMS.CSLA.Library
/// </summary> /// </summary>
public partial class ItemTransitions_ToIDPropertyDescriptor : vlnListPropertyDescriptor public partial class ItemTransitions_ToIDPropertyDescriptor : vlnListPropertyDescriptor
{ {
private ItemTransition_ToID Item { get { return (ItemTransition_ToID)_Item; } }
public ItemTransitions_ToIDPropertyDescriptor(ItemTransitions_ToID collection, int index) : base(collection, index) { ;} public ItemTransitions_ToIDPropertyDescriptor(ItemTransitions_ToID collection, int index) : base(collection, index) { ;}
} }
#endregion #endregion
@@ -334,10 +298,10 @@ namespace VEPROMS.CSLA.Library
{ {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{ {
if (destType == typeof(string) && value is ItemTransitions_ToID) if (destType == typeof(string) && value is ItemTransitions_ToID iD)
{ {
// Return department and department role separated by comma. // Return department and department role separated by comma.
return ((ItemTransitions_ToID)value).Items.Count.ToString() + " Transitions_ToID"; return $"{iD.Items.Count} Transitions_ToID";
} }
return base.ConvertTo(context, culture, value, destType); return base.ConvertTo(context, culture, value, destType);
} }