System out of Memory Exception in Production Server. Below is the code in Body. Could somebody can g

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
using System;
using System.Collections;
using BB.Bankruptcy;
using BB.Business.Interfaces;
using BB.Case;
using BB.Common;
using BB.Constants;
using BB.Data;
using BB.Exceptions;
using BB.QueueManager;
using BB.Security;
using BB.Utilities;
using BB.DocumentGeneration;
namespace BB.ServiceProcess.DocGen
{
/// <summary>
/// Process to generate bankruptcy documents.
/// </summary>
public class GenerateFCLDocuments : MarshalByRefObject, IProcess
{
#region Constructor
public GenerateFCLDocuments()
{
}
#endregion
#region Public Methods
/// <summary>
/// Retrieves a pre-processing status message
/// </summary>
/// <param name="item Item to process</param>
/// <param name="office Office Associated with Item</param>
/// <param name="itemParam Additional paremters for item to process</param>
/// <param name="processParam Additional Process Parameters</param>
/// <returns>Status string, or empty string if no status found</returns>
public string GetPreProcessStatus(string item, string office, object itemParam, object processParam)
{
return string.Empty;
}
/// <summary>
/// Excecutes the associated process for a batch of items
/// </summary>
/// <param name="items Items to process</param>
/// <param name="office Office Associated with Item</param>
/// <param name="itemParam Additional Item Parameters</param>
/// <param name="processParam Additional Process Parameters</param>
/// <returns>Result of process</returns>
public ProcessResult Execute(string[] items, string office, object itemParam, object processParam)
{
ProcessResult result = new ProcessResult();
result.ExtendedData = new ProcessResult[items.Length];
try
{
for (int i = 0; i < items.Length; i++)
{
string item = items;
((ProcessResult[])result.ExtendedData) = this.Execute(item, office, itemParam, processParam);
}
result.Status = ProcessStatus.Success;
result.Message = "Processed " + items.Length.ToString() + " items";
}
catch (Exception ex)
{
result.Status = ProcessStatus.Error;
result.Message = ex.Message;
}
return result;
}
/// <summary>
/// Excecutes the associated process for a single item
/// </summary>
/// <param name="item Item to process</param>
/// <param name="office Office Associated with Item</param>
/// <param name="itemParam Additional Item Parameters</param>
/// <param name="processParam Additional Process Parameters</param>
/// <returns>Result of process</returns>
public ProcessResult Execute(string item, string office, object itemParam, object processParam)
{
QueueItem queueItem = itemParam as QueueItem;
string lockMessage = string.Empty;
ProcessResult result = new ProcessResult();
BBBankruptcy bbBankruptcy = null;
BBCase bbCase = null;
Hashtable parameters = new Hashtable();
try
{
// Check and attempt to lock case
if (BBCase.LockCase(queueItem.CaseKey, queueItem.Office, User.Current.Key, false, out lockMessage))
{
// Open the associated case
bbCase = new BBCase(queueItem.CaseKey, queueItem.Office);
ReportParameters dsRptParameters = new ReportParameters();

string paramVal = string.Empty;
DocumentPackage docPkg = null;
//populate the dataset with the xml from queueItem

System.IO.StringReader sr = new System.IO.StringReader(queueItem.Xml);
dsRptParameters.ReadXml(sr);
//add the ReportDocuments key to hold the crystal report documents in memory for all the mailings
parameters.Add("ReportDocuments", new Hashtable());
//check to see if any case parameters are being set, if not throw an error
if (dsRptParameters.Parameters.Rows.Count > 0)
{
//loop through each row in caseparameters table, typically, there is only one row
foreach(ReportParameters.ParametersRow paramRow in dsRptParameters.Parameters.Rows)
{
foreach(System.Data.DataColumn col in dsRptParameters.Parameters.Columns)
{
//populate the hashtable with parameter name and its value
paramVal = paramRow[col].ToString().Trim();
//if the value is not set in the datatable, skip it
if (paramVal.Length > 0)
{
parameters.Add(col.ColumnName.ToLower(), paramVal);
}
}
//get the document package object from the caseParamRow
docPkg = paramRow.Document_Package.Length > 0 ? BBCommon.Current.Packages[int.Parse(paramRow.Document_Package.ToString())] as DocumentPackage : null;

//if the package is not valid, throw an error
if (docPkg == null)
{
throw new ApplicationException("Document Package is not valid or specified.");
}
//check to see if personinfo table has any rows for mailings
if (dsRptParameters.Mailings.Rows.Count > 0)
{
//loop through each row in the person info table
foreach(ReportParameters.MailingsRow mailingRow in dsRptParameters.Mailings.Rows)
{
//populate the hashtable with parameter name and its values for mailings
foreach(System.Data.DataColumn col in dsRptParameters.Mailings.Columns)
{
paramVal = mailingRow[col].ToString().Trim();
if (paramVal.Length > 0)
{
//remove any pre-existing key
parameters.Remove(col.ColumnName.ToLower());
//add the key
parameters.Add(col.ColumnName.ToLower(), paramVal);
}
}
//generate the package image
BB.DocumentGeneration.PackageUtility.GenerateIndexedImage(bbCase, parameters);

}
}
else if (paramRow.Print_Job_Num.Length > 0 && (docPkg.RequiresCertifiedMail || docPkg.RequiresFirstClassMail))
{
ArrayList processedMailing = new ArrayList();
//get the mailings info from the mailing history table
foreach(Person person in bbCase.Persons)
{
foreach(PersonAddress personAddress in person.Address)
{
foreach(MailingItem mailing in personAddress.MailingsByPrintJobNum(int.Parse(paramRow.Print_Job_Num.ToString())))
{
if (mailing.PersonSequence == person.Sequence && mailing.PersonAddressSequence == personAddress.AddressSequence)
{
if (mailing.Inactive || processedMailing.Contains(mailing.Id.ToString())) continue;
//add the mailing id to the arraylist indicating its been processed
processedMailing.Add(mailing.Id.ToString());

//remove any pre-existing items in the hashtable
parameters.Remove("person_id");
parameters.Remove("person_addr_seq");
parameters.Remove("mailing_history_id");
parameters.Add("person_id", person.Id.ToString());
parameters.Add("person_addr_seq", personAddress.AddressSequence.ToString());
parameters.Add("mailing_history_id", mailing.Id.ToString());

//generate the package image
Image image = BB.DocumentGeneration.PackageUtility.GenerateIndexedImage(bbCase, parameters);

//associate the image id to the mailing item
mailing.Image = image;
}
}
}
}
}
else
{
//generate the package image
BB.DocumentGeneration.PackageUtility.GenerateIndexedImage(bbCase, parameters);

}

//generate the 3877 document
//if docpkg requires certified mail, generate USPS3877 letter
if (docPkg.RequiresCertifiedMail && bbCase.CaseType.Id != BBCommon.Current.CaseTypes.Eviction.Id)
{
//get the document package for usps3877
DocumentPackage docPkg3877 = BBCommon.Current.Packages[(int)Ndts.DocumentPackage.USPS3877];
parameters.Clear();
parameters.Add("document_package" , docPkg3877.Id.ToString());
parameters.Add("image_doc_type" , docPkg3877.ImageDocType != null ? docPkg3877.ImageDocType.Id.ToString() : "0");
parameters.Add("report_path" , Configuration.GetSetting((int)Ndts.System.Ndts, "CRYSTAL_REPORT_FORECLOSURE_DIRECTORY"));
parameters.Add("indexing_department", BBCommon.Current.CaseTypes.Foreclosure.Id.ToString());
parameters.Add("print_job_num" , paramRow.Print_Job_Num.ToString());

// Insert mailing history record
MailingItem mailing = bbCase.Mailings.CreateWithEmptyPerson() as MailingItem;
mailing.VerifiedMailed = true;
mailing.ImageDocType = docPkg3877.ImageDocType;
mailing.DocPkgId = docPkg.Id;
//genereate the 3877 document package
Image image = BB.DocumentGeneration.PackageUtility.GenerateIndexedImage(bbCase, parameters);

mailing.Image = image;
}

//******************************************
//update any associated single event specified in the ecf_event_key column in doc_pkg
if (docPkg.EcfEvent != null && paramRow.Schedule_Event)
{
bbCase.GetEvents(bbCase.CaseType).ClearCompletedDate(docPkg.EcfEvent.Key, false, true);
bbCase.GetEvents(bbCase.CaseType).SetScheduledDate(docPkg.EcfEvent.Key, BB.Data.Utilities.GetServerDateTime(), true, true);
}
// Recalculate events if this package requires it.
if (docPkg.EcfEvent != null && docPkg.RecalculateEvents)
{
bbCase.GetEvents(bbCase.CaseType).Reschedule(0, true);
}
}
}
else
{
throw new ApplicationException("Report Parameters are not set");
}

// Save any pending changes to the case
bbCase.Save();
// set the process result to success
result.Status = ProcessStatus.Success;
}
else // Case was locked
{
result.Status = ProcessStatus.Error;
result.Message = lockMessage;
}
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
if (result == null) result = new ProcessResult();
result.Status = ProcessStatus.Error;
result.Message = ex.Message;
}
finally
{
if (bbBankruptcy != null) bbBankruptcy.UnSubscribeEvents();
bbBankruptcy = null;
//close case
if (bbCase != null)
{
bbCase.Close();
bbCase = null;
}
else if (lockMessage == string.Empty)
{
// Remove the lock
BB.Case.Data.LockCase.RemoveLock(queueItem.Office, queueItem.CaseKey);
}
//dispose out any report documents saved in the hashtable
if (parameters.ContainsKey("ReportDocuments") && ((Hashtable)parameters["ReportDocuments"]).Count > 0)
{
//get the enumerator of the hashtable
IDictionaryEnumerator enumerator = ((Hashtable)parameters["ReportDocuments"]).GetEnumerator();
//loop through the hashtable items and dispose all the objects
while (enumerator.MoveNext())
{
IDisposable disposableObject = enumerator.Value as IDisposable;
if (disposableObject != null) disposableObject.Dispose();
}
}

}
return result;
}
#endregion
}
}

View the full article
 
Back
Top