mschill 378653c536 C2025-011 PROMS – RO Update Admin Tool Memory Enhancements
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.
2025-02-04 13:23:21 -05:00

498 lines
17 KiB
C#

// ========================================================================
// Copyright 2006 - 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;
namespace Volian.Object.Library
{
/// <summary>
/// UserMembership Generated by MyGeneration using the CSLA Object Mapping template
/// </summary>
[Serializable()]
public partial class UserMembership : BusinessBase<UserMembership>
{
#region Business Methods
private int _ugid;
[System.ComponentModel.DataObjectField(true, true)]
public int Ugid
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _ugid;
}
}
private int _gid;
[System.ComponentModel.DataObjectField(true, true)]
public int Gid
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _gid;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
if (_gid != value)
{
_gid = value;
PropertyHasChanged();
}
}
}
private string _startdate = string.Empty;
[System.ComponentModel.DataObjectField(true, true)]
public string StartDate
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _startdate;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
if (value == null) value = string.Empty;
_startdate = value;
try
{
DateTime tmp = SmartDate.StringToDate(value);
if (_startdate != tmp.ToShortDateString())
{
_startdate = tmp.ToShortDateString();
// TODO: Any Cross Property Validation
}
}
catch
{
}
PropertyHasChanged();
}
}
private string _enddate = string.Empty;
[System.ComponentModel.DataObjectField(true, true)]
public string EndDate
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _enddate;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
if (value == null) value = string.Empty;
_enddate = value;
try
{
DateTime tmp = SmartDate.StringToDate(value);
if (_enddate != tmp.ToShortDateString())
{
_enddate = tmp.ToShortDateString();
// TODO: Any Cross Property Validation
}
}
catch
{
}
PropertyHasChanged();
}
}
private DateTime _dts = new DateTime();
[System.ComponentModel.DataObjectField(true, true)]
public DateTime Dts
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _dts;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
if (_dts != value)
{
_dts = value;
PropertyHasChanged();
}
}
}
private string _usrid = string.Empty;
[System.ComponentModel.DataObjectField(true, true)]
public string Usrid
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _usrid;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
if (value == null) value = string.Empty;
if (_usrid != value)
{
_usrid = value;
PropertyHasChanged();
}
}
}
private byte[] _lastchanged = new byte[8];//timestamp
private string _group_groupname = string.Empty;
[System.ComponentModel.DataObjectField(true, true)]
public string Group_GroupName
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _group_groupname;
}
}
private int _group_grouptype;
[System.ComponentModel.DataObjectField(true, true)]
public int Group_GroupType
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _group_grouptype;
}
}
private string _group_config = string.Empty;
[System.ComponentModel.DataObjectField(true, true)]
public string Group_Config
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _group_config;
}
}
private DateTime _group_dts = new DateTime();
[System.ComponentModel.DataObjectField(true, true)]
public DateTime Group_Dts
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _group_dts;
}
}
private string _group_usrid = string.Empty;
[System.ComponentModel.DataObjectField(true, true)]
public string Group_Usrid
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _group_usrid;
}
}
// TODO: Check UserMembership.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 UserMembership</returns>
protected override object GetIdValue()
{
return _ugid;
}
// TODO: Replace base UserMembership.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current UserMembership</returns>
//public override string ToString()
//{
// return base.ToString();
//}
#endregion
#region ValidationRules
protected override void AddBusinessRules()
{
ValidationRules.AddRule(StartDateValid, "StartDate");
ValidationRules.AddRule(EndDateValid, "EndDate");
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100));
// TODO: Add other validation rules
}
private bool StartDateValid(object target, Csla.Validation.RuleArgs e)
{
try
{
DateTime tmp = SmartDate.StringToDate(_startdate);
}
catch
{
e.Description = "Invalid Date";
return false;
}
return true;
}
private bool EndDateValid(object target, Csla.Validation.RuleArgs e)
{
try
{
DateTime tmp = SmartDate.StringToDate(_enddate);
}
catch
{
e.Description = "Invalid Date";
return false;
}
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()
{
//TODO: Who can read/write which fields
//AuthorizationRules.AllowRead(Ugid, "<Role(s)>");
//AuthorizationRules.AllowRead(Gid, "<Role(s)>");
//AuthorizationRules.AllowWrite(Gid, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(Dts, "<Role(s)>");
//AuthorizationRules.AllowWrite(Dts, "<Role(s)>");
//AuthorizationRules.AllowRead(Usrid, "<Role(s)>");
//AuthorizationRules.AllowWrite(Usrid, "<Role(s)>");
}
public static bool CanAddObject()
{
// TODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// TODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// TODO: 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()
{
// TODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
internal static UserMembership New(int gid)
{
return new UserMembership(Volian.Object.Library.Group.Get(gid));
}
internal static UserMembership Get(SafeDataReader dr)
{
return new UserMembership(dr);
}
private UserMembership()
{
MarkAsChild();
_startdate = ext.DefaultStartDate;
_dts = ext.DefaultDts;
_usrid = ext.DefaultUsrid;
}
private UserMembership(Group group)
{
MarkAsChild();
// TODO: Add any initialization & defaults
_startdate = ext.DefaultStartDate;
_dts = ext.DefaultDts;
_usrid = ext.DefaultUsrid;
_gid = group.Gid;
_group_groupname = group.GroupName;
_group_grouptype = group.GroupType;
_group_config = group.Config;
_group_dts = group.Dts;
_group_usrid = group.Usrid;
}
private UserMembership(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
}
#endregion
#region Data Access Portal
private void Fetch(SafeDataReader dr)
{
try
{
_ugid = dr.GetInt32("UGID");
_gid = dr.GetInt32("GID");
_startdate = dr.GetSmartDate("StartDate").Text;
_enddate = dr.GetSmartDate("EndDate").Text;
_dts = dr.GetDateTime("DTS");
_usrid = dr.GetString("UsrID");
dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8);
_group_groupname = dr.GetString("Groups_GroupName");
_group_grouptype = dr.GetInt32("Groups_GroupType");
_group_config = dr.GetString("Groups_Config");
_group_dts = dr.GetDateTime("Groups_DTS");
_group_usrid = dr.GetString("Groups_UsrID");
}
catch (Exception ex)
{
Database.LogException("UserMembership", ex);
}
MarkOld();
}
internal void Insert(User user, SqlConnection cn)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
_lastchanged = Membership.Add(cn, ref _ugid, user.Uid, _gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid);
MarkOld();
}
internal void Update(User user, SqlConnection cn)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
_lastchanged = Membership.Update(cn, ref _ugid, user.Uid, _gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged);
MarkClean();
}
internal void DeleteSelf(User user, SqlConnection cn)
{
// 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;
Membership.Remove(cn, _ugid);
MarkNew();
}
#endregion
// Standard Default Code
// #region extension
Extension ext = new Extension();
[Serializable()]
partial class Extension : extensionBase
{
}
[Serializable()]
class extensionBase
{
// Default Values
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDts
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrid
{
get { return Environment.UserName.ToUpper(); }
}
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
// Needs to be overriden to add new authorization rules
}
// Validation Rules
public virtual void AddValidationRules(Csla.Validation.ValidationRules rules)
{
// Needs to be overriden to add new validation rules
}
}
//#endregion
// The follwing is a sample Extension File. You can use it to create UserMembershipExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace PatrialClass
//{
// public partial class UserMembership
// {
// partial class Extension : extensionBase
// {
// TODO: Override automatic defaults
// public virtual SmartDate DefaultStartDate
// {
// get { return DateTime.Now.ToShortDateString(); }
// }
// public virtual DateTime DefaultDts
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrid
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// }
// }
//}
} // Class
} // Namespace