Memory Utilities

Reduce Memory Use
Added GetJustFormat method
Added CheckColumnMode method
This commit is contained in:
Rich
2012-05-21 13:32:28 +00:00
parent 683bf51ef8
commit c8de9f8538
4 changed files with 923 additions and 6 deletions

View File

@@ -22,6 +22,80 @@ using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
{
public partial class Format
{
public static Format GetJustFormat(int formatID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
Format tmp = GetCachedByPrimaryKey(formatID);
if (tmp == null)
{
tmp = DataPortal.Fetch<Format>(new PKCriteriaJustFormat(formatID));
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Format
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on Format.GetJustFormat", ex);
}
}
[Serializable()]
protected class PKCriteriaJustFormat
{
private int _FormatID;
public int FormatID
{ get { return _FormatID; } }
public PKCriteriaJustFormat(int formatID)
{
_FormatID = formatID;
}
}
private void DataPortal_Fetch(PKCriteriaJustFormat criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch JustFormat", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
ApplicationContext.LocalContext["cn"] = cn;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getJustFormat";
cm.Parameters.AddWithValue("@FormatID", criteria.FormatID);
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("Format.DataPortal_Fetch JustFormat", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Format.DataPortal_Fetch JustFormat", ex);
}
}
}
public partial interface IFormatOrFormatInfo
{
PlantFormat PlantFormat { get;}
@@ -166,8 +240,6 @@ namespace VEPROMS.CSLA.Library
{
try
{
FileInfo fi = new FileInfo(path);
Dts = fi.LastWriteTime;
StreamReader srf = new StreamReader(path);
xd = new XmlDocument();
xd.Load(srf);
@@ -232,8 +304,6 @@ namespace VEPROMS.CSLA.Library
rec = Format.Get(LookupFormats[fname]);
rec.Data = fmtdata;
rec.GenMac = genmacdata;
rec.DTS = Dts;
rec.UserID = Volian.Base.Library.VlnSettings.UserID;
rec = rec.Save();
}
}