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