The purpose of this upgrade is to improve the user experience when using the Admin tool to Update ROs. Currently for larger RO dbs (like Barakah) we can run up against memory constraints that do not allow all the ROs to be updated at one time. This is based upon some initial resource where some places were identified where we could improve memory usage. Some of these should benefit PROMS as a whole while others will be specific to the RO Update option in Admin Tools.
477 lines
19 KiB
C#
477 lines
19 KiB
C#
// ========================================================================
|
|
// Copyright 2007 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
|
|
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;
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
public delegate void VersionInfoEvent(object sender);
|
|
/// <summary>
|
|
/// VersionInfo Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(VersionInfoConverter))]
|
|
public partial class VersionInfo : ReadOnlyBase<VersionInfo>, IDisposable
|
|
{
|
|
public event VersionInfoEvent Changed;
|
|
private void OnChange()
|
|
{
|
|
if (Changed != null) Changed(this);
|
|
}
|
|
#region Log4Net
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
#region Collection
|
|
private static List<VersionInfo> _CacheList = new List<VersionInfo>();
|
|
protected static void AddToCache(VersionInfo versionInfo)
|
|
{
|
|
if (!_CacheList.Contains(versionInfo)) _CacheList.Add(versionInfo); // In AddToCache
|
|
}
|
|
protected static void RemoveFromCache(VersionInfo versionInfo)
|
|
{
|
|
while (_CacheList.Contains(versionInfo)) _CacheList.Remove(versionInfo); // In RemoveFromCache
|
|
}
|
|
private static Dictionary<string, List<VersionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<VersionInfo>>();
|
|
private static void ConvertListToDictionary()
|
|
{
|
|
while (_CacheList.Count > 0) // Move VersionInfo(s) from temporary _CacheList to _CacheByPrimaryKey
|
|
{
|
|
VersionInfo tmp = _CacheList[0]; // Get the first VersionInfo
|
|
string pKey = tmp.VersionID.ToString();
|
|
if (!_CacheByPrimaryKey.ContainsKey(pKey))
|
|
{
|
|
_CacheByPrimaryKey[pKey] = new List<VersionInfo>(); // Add new list for PrimaryKey
|
|
}
|
|
_CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
|
|
_CacheList.RemoveAt(0); // Remove the first VersionInfo
|
|
}
|
|
}
|
|
internal static void AddList(VersionInfoList lst)
|
|
{
|
|
foreach (VersionInfo item in lst) AddToCache(item);
|
|
}
|
|
protected static VersionInfo GetCachedByPrimaryKey(int versionID)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = versionID.ToString();
|
|
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
|
return null;
|
|
}
|
|
#endregion
|
|
#region Business Methods
|
|
private string _ErrorMessage = string.Empty;
|
|
public string ErrorMessage
|
|
{
|
|
get { return _ErrorMessage; }
|
|
}
|
|
protected Version _Editable;
|
|
private IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_Editable != null)
|
|
hasBrokenRules = _Editable.HasBrokenRules;
|
|
return hasBrokenRules;
|
|
}
|
|
}
|
|
private int _VersionID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int VersionID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _VersionID;
|
|
}
|
|
}
|
|
private int _RevisionID;
|
|
public int RevisionID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID;
|
|
return _RevisionID;
|
|
}
|
|
}
|
|
private RevisionInfo _MyRevision;
|
|
public RevisionInfo MyRevision
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID);
|
|
return _MyRevision;
|
|
}
|
|
}
|
|
private int _StageID;
|
|
public int StageID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyStage != null) _StageID = _MyStage.StageID;
|
|
return _StageID;
|
|
}
|
|
}
|
|
private StageInfo _MyStage;
|
|
public StageInfo MyStage
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID);
|
|
return _MyStage;
|
|
}
|
|
}
|
|
private byte[] _PDF;
|
|
public byte[] PDF
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _PDF;
|
|
}
|
|
set
|
|
{
|
|
_PDF = value;
|
|
}
|
|
}
|
|
private byte[] _SummaryPDF;
|
|
public byte[] SummaryPDF
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _SummaryPDF;
|
|
}
|
|
set
|
|
{
|
|
_SummaryPDF = value;
|
|
}
|
|
}
|
|
private string _ApprovedXML;
|
|
public string ApprovedXML
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ApprovedXML;
|
|
}
|
|
set
|
|
{
|
|
_ApprovedXML = value;
|
|
}
|
|
}
|
|
private DateTime _DTS = new DateTime();
|
|
public DateTime DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _DTS;
|
|
}
|
|
}
|
|
private string _UserID = string.Empty;
|
|
public string UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UserID;
|
|
}
|
|
}
|
|
// CSLATODO: Replace base VersionInfo.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current VersionInfo</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
// CSLATODO: Check VersionInfo.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 VersionInfo</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return MyVersionInfoUnique; // Absolutely Unique ID
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
private static int _VersionInfoUnique = 0;
|
|
private static int VersionInfoUnique
|
|
{ get { return ++_VersionInfoUnique; } }
|
|
private int _MyVersionInfoUnique = VersionInfoUnique;
|
|
public int MyVersionInfoUnique // Absolutely Unique ID - Info
|
|
{ get { return _MyVersionInfoUnique; } }
|
|
protected VersionInfo()
|
|
{/* require use of factory methods */
|
|
AddToCache(this);
|
|
}
|
|
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; } }
|
|
~VersionInfo()
|
|
{
|
|
_CountFinalized++;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_Disposed) return;
|
|
_CountDisposed++;
|
|
_Disposed = true;
|
|
RemoveFromCache(this);
|
|
if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return;
|
|
List<VersionInfo> listVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items
|
|
while (listVersionInfo.Contains(this)) listVersionInfo.Remove(this); // Remove the item from the list
|
|
if (listVersionInfo.Count == 0) // If there are no items left in the list
|
|
_CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list
|
|
}
|
|
public virtual Version Get()
|
|
{
|
|
return _Editable = Version.Get(_VersionID);
|
|
}
|
|
public static void Refresh(Version tmp)
|
|
{
|
|
string key = tmp.VersionID.ToString();
|
|
ConvertListToDictionary();
|
|
if (_CacheByPrimaryKey.ContainsKey(key))
|
|
foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
protected virtual void RefreshFields(Version tmp)
|
|
{
|
|
if (_RevisionID != tmp.RevisionID)
|
|
{
|
|
if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value
|
|
_RevisionID = tmp.RevisionID; // Update the value
|
|
}
|
|
_MyRevision = null; // Reset list so that the next line gets a new list
|
|
if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value
|
|
if (_StageID != tmp.StageID)
|
|
{
|
|
if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value
|
|
_StageID = tmp.StageID; // Update the value
|
|
}
|
|
_MyStage = null; // Reset list so that the next line gets a new list
|
|
if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value
|
|
_PDF = tmp.PDF;
|
|
_SummaryPDF = tmp.SummaryPDF;
|
|
_DTS = tmp.DTS;
|
|
_UserID = tmp.UserID;
|
|
_VersionInfoExtension.Refresh(this);
|
|
OnChange();// raise an event
|
|
}
|
|
public static void Refresh(RevisionVersion tmp)
|
|
{
|
|
string key = tmp.VersionID.ToString();
|
|
ConvertListToDictionary();
|
|
if (_CacheByPrimaryKey.ContainsKey(key))
|
|
foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
protected virtual void RefreshFields(RevisionVersion tmp)
|
|
{
|
|
if (_StageID != tmp.StageID)
|
|
{
|
|
if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value
|
|
_StageID = tmp.StageID; // Update the value
|
|
}
|
|
_MyStage = null; // Reset list so that the next line gets a new list
|
|
if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value
|
|
_PDF = tmp.PDF;
|
|
_SummaryPDF = tmp.SummaryPDF;
|
|
_DTS = tmp.DTS;
|
|
_UserID = tmp.UserID;
|
|
_VersionInfoExtension.Refresh(this);
|
|
OnChange();// raise an event
|
|
}
|
|
public static void Refresh(StageVersion tmp)
|
|
{
|
|
string key = tmp.VersionID.ToString();
|
|
ConvertListToDictionary();
|
|
if (_CacheByPrimaryKey.ContainsKey(key))
|
|
foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key])
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
protected virtual void RefreshFields(StageVersion tmp)
|
|
{
|
|
if (_RevisionID != tmp.RevisionID)
|
|
{
|
|
if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value
|
|
_RevisionID = tmp.RevisionID; // Update the value
|
|
}
|
|
_MyRevision = null; // Reset list so that the next line gets a new list
|
|
if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value
|
|
_PDF = tmp.PDF;
|
|
_SummaryPDF = tmp.SummaryPDF;
|
|
_DTS = tmp.DTS;
|
|
_UserID = tmp.UserID;
|
|
_VersionInfoExtension.Refresh(this);
|
|
OnChange();// raise an event
|
|
}
|
|
public static VersionInfo Get(int versionID)
|
|
{
|
|
//if (!CanGetObject())
|
|
// throw new System.Security.SecurityException("User not authorized to view a Version");
|
|
try
|
|
{
|
|
VersionInfo tmp = GetCachedByPrimaryKey(versionID);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<VersionInfo>(new PKCriteria(versionID));
|
|
AddToCache(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp.Dispose(); // Clean-up VersionInfo
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on VersionInfo.Get", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
internal VersionInfo(SafeDataReader dr)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.Constructor", GetHashCode());
|
|
try
|
|
{
|
|
ReadData(dr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.Constructor", ex);
|
|
throw new DbCslaException("VersionInfo.Constructor", ex);
|
|
}
|
|
}
|
|
[Serializable()]
|
|
protected class PKCriteria
|
|
{
|
|
private int _VersionID;
|
|
public int VersionID
|
|
{ get { return _VersionID; } }
|
|
public PKCriteria(int versionID)
|
|
{
|
|
_VersionID = versionID;
|
|
}
|
|
}
|
|
private void ReadData(SafeDataReader dr)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.ReadData", GetHashCode());
|
|
try
|
|
{
|
|
_VersionID = dr.GetInt32("VersionID");
|
|
_RevisionID = dr.GetInt32("RevisionID");
|
|
_StageID = dr.GetInt32("StageID");
|
|
_PDF = (byte[])dr.GetValue("PDF");
|
|
_SummaryPDF = (byte[])dr.GetValue("SummaryPDF");
|
|
_ApprovedXML = dr.GetString("ApprovedXML");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UserID = dr.GetString("UserID");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.ReadData", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("VersionInfo.ReadData", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.DataPortal_Fetch", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getVersion";
|
|
cm.Parameters.AddWithValue("@VersionID", criteria.VersionID);
|
|
cm.CommandTimeout = Database.DefaultTimeout;
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
if (!dr.Read())
|
|
{
|
|
_ErrorMessage = "No Record Found";
|
|
return;
|
|
}
|
|
ReadData(dr);
|
|
}
|
|
}
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("VersionInfo.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Refresh
|
|
#region extension
|
|
VersionInfoExtension _VersionInfoExtension = new VersionInfoExtension();
|
|
[Serializable()]
|
|
partial class VersionInfoExtension : extensionBase { }
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Refresh
|
|
public virtual void Refresh(VersionInfo tmp) { }
|
|
}
|
|
#endregion
|
|
} // Class
|
|
#region Converter
|
|
internal class VersionInfoConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is VersionInfo)
|
|
{
|
|
// Return the ToString value
|
|
return ((VersionInfo)value).ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|