CSLA - M through P
This commit is contained in:
@@ -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 PdfInfo : ReadOnlyBase<PdfInfo>, IDisposable
|
||||
{
|
||||
public event PdfInfoEvent 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<PdfInfo> _CacheList = new List<PdfInfo>();
|
||||
protected static void AddToCache(PdfInfo pdfInfo)
|
||||
{
|
||||
@@ -45,13 +41,14 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(pdfInfo)) _CacheList.Remove(pdfInfo); // In RemoveFromCache
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<PdfInfo>> _CacheByPrimaryKey = new Dictionary<string, List<PdfInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
while (_CacheList.Count > 0) // Move PdfInfo(s) from temporary _CacheList to _CacheByPrimaryKey
|
||||
{
|
||||
PdfInfo tmp = _CacheList[0]; // Get the first PdfInfo
|
||||
string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
|
||||
string pKey = $"{tmp.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
|
||||
if (!_CacheByPrimaryKey.ContainsKey(pKey))
|
||||
{
|
||||
_CacheByPrimaryKey[pKey] = new List<PdfInfo>(); // Add new list for PrimaryKey
|
||||
@@ -67,7 +64,7 @@ namespace VEPROMS.CSLA.Library
|
||||
protected static PdfInfo GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString();
|
||||
string key = $"{docID}_{debugStatus}_{topRow}_{pageLength}_{leftMargin}_{pageWidth}";
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
@@ -77,7 +74,7 @@ namespace VEPROMS.CSLA.Library
|
||||
protected static void RemoveFromCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString();
|
||||
string key = $"{docID}_{debugStatus}_{topRow}_{pageLength}_{leftMargin}_{pageWidth}";
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
{
|
||||
_CacheByPrimaryKey.Remove(key);
|
||||
@@ -87,21 +84,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 Pdf _Editable;
|
||||
private IVEHasBrokenRules HasBrokenRules
|
||||
{
|
||||
get
|
||||
{
|
||||
IVEHasBrokenRules hasBrokenRules = null;
|
||||
if (_Editable != null)
|
||||
hasBrokenRules = _Editable.HasBrokenRules;
|
||||
return hasBrokenRules;
|
||||
}
|
||||
}
|
||||
private int _DocID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int DocID
|
||||
@@ -216,32 +200,19 @@ namespace VEPROMS.CSLA.Library
|
||||
return _UserID;
|
||||
}
|
||||
}
|
||||
// CSLATODO: Replace base PdfInfo.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current PdfInfo</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
// CSLATODO: Check PdfInfo.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 PdfInfo</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MyPdfInfoUnique; // Absolutely Unique ID
|
||||
}
|
||||
protected override object GetIdValue() => MyPdfInfoUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _PdfInfoUnique = 0;
|
||||
private static int PdfInfoUnique
|
||||
{ get { return ++_PdfInfoUnique; } }
|
||||
private int _MyPdfInfoUnique = PdfInfoUnique;
|
||||
public int MyPdfInfoUnique // Absolutely Unique ID - Info
|
||||
{ get { return _MyPdfInfoUnique; } }
|
||||
private static int PdfInfoUnique => ++_PdfInfoUnique;
|
||||
private readonly int _MyPdfInfoUnique = PdfInfoUnique;
|
||||
// Absolutely Unique ID - Info
|
||||
public int MyPdfInfoUnique => _MyPdfInfoUnique;
|
||||
protected PdfInfo()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -250,15 +221,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;
|
||||
~PdfInfo()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -269,19 +236,16 @@ namespace VEPROMS.CSLA.Library
|
||||
_CountDisposed++;
|
||||
_Disposed = true;
|
||||
RemoveFromCache(this);
|
||||
if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString())) return;
|
||||
List<PdfInfo> listPdfInfo = _CacheByPrimaryKey[DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()]; // Get the list of items
|
||||
if (!_CacheByPrimaryKey.ContainsKey($"{DocID}_{DebugStatus}_{TopRow}_{PageLength}_{LeftMargin}_{PageWidth}")) return;
|
||||
List<PdfInfo> listPdfInfo = _CacheByPrimaryKey[$"{DocID}_{DebugStatus}_{TopRow}_{PageLength}_{LeftMargin}_{PageWidth}"]; // Get the list of items
|
||||
while (listPdfInfo.Contains(this)) listPdfInfo.Remove(this); // Remove the item from the list
|
||||
if (listPdfInfo.Count == 0) // If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()); // remove the list
|
||||
}
|
||||
public virtual Pdf Get()
|
||||
{
|
||||
return _Editable = Pdf.Get(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth);
|
||||
_CacheByPrimaryKey.Remove($"{DocID}_{DebugStatus}_{TopRow}_{PageLength}_{LeftMargin}_{PageWidth}"); // remove the list
|
||||
}
|
||||
public virtual Pdf Get() => _Editable = Pdf.Get(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth);
|
||||
public static void Refresh(Pdf tmp)
|
||||
{
|
||||
string key = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
|
||||
string key = $"{tmp.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
|
||||
ConvertListToDictionary();
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
@@ -298,7 +262,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static void Refresh(Document myDocument, DocumentPdf tmp)
|
||||
{
|
||||
string key = myDocument.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString();
|
||||
string key = $"{myDocument.DocID}_{tmp.DebugStatus}_{tmp.TopRow}_{tmp.PageLength}_{tmp.LeftMargin}_{tmp.PageWidth}";
|
||||
ConvertListToDictionary();
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key])
|
||||
@@ -315,8 +279,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static PdfInfo Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
|
||||
{
|
||||
//if (!CanGetObject())
|
||||
// throw new System.Security.SecurityException("User not authorized to view a Pdf");
|
||||
try
|
||||
{
|
||||
PdfInfo tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth);
|
||||
@@ -355,24 +317,18 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _DocID;
|
||||
public int DocID
|
||||
{ get { return _DocID; } }
|
||||
private int _DebugStatus;
|
||||
public int DebugStatus
|
||||
{ get { return _DebugStatus; } }
|
||||
private int _TopRow;
|
||||
public int TopRow
|
||||
{ get { return _TopRow; } }
|
||||
private int _PageLength;
|
||||
public int PageLength
|
||||
{ get { return _PageLength; } }
|
||||
private int _LeftMargin;
|
||||
public int LeftMargin
|
||||
{ get { return _LeftMargin; } }
|
||||
private int _PageWidth;
|
||||
public int PageWidth
|
||||
{ get { return _PageWidth; } }
|
||||
private readonly int _DocID;
|
||||
public int DocID => _DocID;
|
||||
private readonly int _DebugStatus;
|
||||
public int DebugStatus => _DebugStatus;
|
||||
private readonly int _TopRow;
|
||||
public int TopRow => _TopRow;
|
||||
private readonly int _PageLength;
|
||||
public int PageLength => _PageLength;
|
||||
private readonly int _LeftMargin;
|
||||
public int LeftMargin => _LeftMargin;
|
||||
private readonly int _PageWidth;
|
||||
public int PageWidth => _PageWidth;
|
||||
public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
|
||||
{
|
||||
_DocID = docID;
|
||||
@@ -450,7 +406,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
// Standard Refresh
|
||||
#region extension
|
||||
PdfInfoExtension _PdfInfoExtension = new PdfInfoExtension();
|
||||
readonly PdfInfoExtension _PdfInfoExtension = new PdfInfoExtension();
|
||||
[Serializable()]
|
||||
partial class PdfInfoExtension : extensionBase { }
|
||||
[Serializable()]
|
||||
@@ -466,10 +422,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 PdfInfo)
|
||||
if (destType == typeof(string) && value is PdfInfo info)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((PdfInfo)value).ToString();
|
||||
return info.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user