public override WorkerResult Run(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { try { IDalSession session = factory.CreateSession(); if (session == null) throw new ApplicationException("The session cannot be null"); session.Close(); BatchExecutionResults results = new BatchExecutionResults(); if (NotaType == -1) PrintNotasAdapter.PrintNotas(results, ManagementCompanyID); else PrintNotasAdapter.PrintNotas(results, ManagementCompanyID, (NotaReturnClass)NotaType); string result = PrintNotasAdapter.FormatErrorsForPrintNotas(results, ManagementCompanyID.ToString()); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Ok, result, result); } catch (Exception ex) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured in the print notas worker", "", ex); } finally { worker.ReportProgress(100); } return (WorkerResult)e.Result; }
public override WorkerResult Run(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { try { IDalSession session = factory.CreateSession(); DataSet ds; if (session == null) throw new ApplicationException("The session can not be null"); if (QueryString == string.Empty) throw new ApplicationException("The query string can not be null"); if (UseSP) { Hashtable parameters = null; if (CommandParams != null && CommandParams.Count > 0) { foreach (ADOCommandWorkerParam p in CommandParams) { if (parameters == null) parameters = new Hashtable(CommandParams.Count); if (p.Value == string.Empty || p.Value == "NULL") parameters.Add(p.Name, null); else parameters.Add(p.Name, p.Value); } } ds = session.GetDataFromSP(QueryString, parameters); } else ds = session.GetDataFromQuery(QueryString); if (ds == null) throw new ApplicationException(string.Format("The query ({0}) could not be executed.", QueryString)); if ((NotificationOption == ADOQueryWorkerOptions.NotifyOnData) && (ds.Tables[0].Rows.Count > 0)) { string detailedMessage = string.Format("{0} transactions were found that are approved but did not allocate.", ds.Tables[0].Rows.Count.ToString()); e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Warning, "Data was found for: " + Name, detailedMessage); } else if ((NotificationOption == ADOQueryWorkerOptions.NotifyOnNoData) && (ds.Tables[0].Rows.Count == 0)) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Warning, "No Data was found for: " + Name); } } catch (Exception ex) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured in the query worker", "", ex); } finally { worker.ReportProgress(100); } return (WorkerResult)e.Result; }
public override WorkerResult Run(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { try { IDalSession session = factory.CreateSession(); if (session == null) throw new ApplicationException("The session can not be null"); if (CommandName == string.Empty) throw new ApplicationException("The command name can not be null"); Hashtable parameters = null; if (CommandParams != null && CommandParams.Count > 0) { foreach (ADOCommandWorkerParam p in CommandParams) { if (parameters == null) parameters = new Hashtable(CommandParams.Count); if (p.Value == string.Empty || p.Value == "NULL") parameters.Add(p.Name, null); else parameters.Add(p.Name, p.Value); } } int i = session.ExecuteNonQuery(CommandName, parameters); string result = string.Format("{0} records were affected by sp {1}", i.ToString(), CommandName); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Ok, result, result); } catch (Exception ex) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured in the command worker", "", ex); } finally { worker.ReportProgress(100); } return (WorkerResult)e.Result; }
public override WorkerResult Run(IDalSessionFactory factory, System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs e) { try { IDalSession session = factory.CreateSession(); DateTime startDate = DateTime.Now; if (LoadExRates(session)) { string result = "The exchangerates were imported successfully"; e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Ok, result); } } catch (Exception ex) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured during the retrieval of the exchangerates", "", ex); } finally { worker.ReportProgress(100); } return (WorkerResult)e.Result; }
public int RunValuationMutations(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { int counter = 0; int successCount = 0; int errCount = 0; Hashtable errors = new Hashtable(); DateTime maxDate = MaxValuationDate; try { IDalSession session = factory.CreateSession(); string result; int progress = 0; // set session timeout session.TimeOut = 0; session.LockMode = LockModes.None; if (RunSP_ResetValuations) { // Run TG_ResetValuations ResetValuations(session, null); } // Set MaxValuationMutationDate SetValuationMutationValidityDate(session, maxDate); IList<int> accountKeys = getAccountKeysForRunValuationMutations(session, maxDate); session.Close(); if (accountKeys != null && accountKeys.Count > 0) { foreach (int accountID in accountKeys) { session = factory.CreateSession(); Hashtable parameters2 = new Hashtable(); parameters2.Add("accountID", accountID); IList accounts = session.GetTypedListByNamedQuery<IAccountTypeCustomer>( "B4F.TotalGiro.Valuations.GetAccountForRunValuationMutations", parameters2); if (accounts != null && accounts.Count == 1) { string message; IAccountTypeCustomer account = (IAccountTypeCustomer)accounts[0]; bool success = runValuationMutationsForAccount(session, account, maxDate, out message); session.Close(); if (success) successCount++; else { if (errors.ContainsKey(message)) errors[message] = ((int)errors[message]) + 1; else errors.Add(message, 1); errCount++; } counter++; } if (worker != null) { if (worker.CancellationPending) { e.Cancel = true; result = string.Format("The Valuation Job was cancelled, {0} accounts were valuated successfully {1}", successCount.ToString(), getFailureMessage(errors, errCount)); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Cancelled, successCount.ToString(), result); return successCount; } else if (errCount > 99) { e.Cancel = true; result = string.Format("The Valuation Job was cancelled, to many failures, {0} accounts were valuated successfully {1}", successCount.ToString(), getFailureMessage(errors, errCount)); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Cancelled, successCount.ToString(), result); return successCount; } else { if (progress != ((counter * 100) / accountKeys.Count) && progress < 99) { progress = ((counter * 100) / accountKeys.Count); worker.ReportProgress(progress); } } } } } result = string.Format("{0} accounts were valuated successfully {1}", successCount.ToString(), getFailureMessage(errors, errCount)); if (e != null) e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Ok, successCount.ToString(), result); } catch (Exception ex) { successCount = 0; if (e != null) e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured during the valuation job", "", ex); else throw new ApplicationException(Util.GetMessageFromException(ex)); } finally { if (e != null && worker != null) { e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Ok, successCount.ToString(), string.Format("Successfully valuated {0} accounts.", successCount)); worker.ReportProgress(100); } } return successCount; }
public int RunDailyValuations(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { int successCount = 0; try { IDalSession session = factory.CreateSession(); valuationRunner = new ValuationRunner(MaxValuationDate, ConcurrentStoredProceduresCount, session); valuationRunner.HasFinished += new EventHandler(valuationRunner_HasFinished); valuationRunner.ReportProgress += new ValuationRunner.ReportProgressEventHandler(valuationRunner_ReportProgress); valuationRunner.Worker = worker; valuationRunner.WorkerEvent = e; valuationRunner.Run(); while (valuationRunner != null && valuationRunner.IsRunning) { Thread.Sleep(2000); } if (valuationRunner != null) { Debug.Print(string.Format("{0} - The end", DateTime.Now)); successCount = valuationRunner.TotalNrAccountsProcessed; valuationRunner.Dispose(); valuationRunner = null; } } catch (Exception ex) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured during the daily valuation job", "", ex); worker.ReportProgress(100); Debug.Print("Error in RunDailyValuations"); } //finally //{ // worker.ReportProgress(100); //} return successCount; }
public int RunCalculateFees(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { int counter = 0; int successCount = 0; int errCount = 0; Hashtable errors = new Hashtable(); try { IDalSession session = factory.CreateSession(); FeeFactory feeFactory = null; string result; int progress = 0; // set session timeout session.TimeOut = 0; session.LockMode = LockModes.None; IList<int> unitKeys = session.GetTypedListByNamedQuery<int>( "B4F.TotalGiro.Valuations.GetNotCalculatedManagementPeriodUnits"); session.Close(); if (unitKeys != null && unitKeys.Count > 0) { feeFactory = FeeFactory.GetInstance(factory.CreateSession(), FeeFactoryInstanceTypes.Fee, true); foreach (int unitID in unitKeys) { session = factory.CreateSession(); string hqlUnit = "from ManagementPeriodUnit U where U.Key = :unitID"; Hashtable parameters = new Hashtable(); parameters.Add("unitID", unitID); IList<ManagementPeriodUnit> units = session.GetTypedListByHQL<ManagementPeriodUnit>(hqlUnit, parameters); if (units != null && units.Count == 1) { string message; IManagementPeriodUnit unit = units[0]; bool success = runCalculateFeesForUnit(session, feeFactory, unit, out message); session.Close(); if (success) successCount++; else { if (errors.ContainsKey(message)) errors[message] = ((int)errors[message]) + 1; else errors.Add(message, 1); errCount++; } counter++; } if (worker.CancellationPending) { e.Cancel = true; result = string.Format("The Fee Calculation Job was cancelled, {0} units were calculated successfully {1}", successCount.ToString(), getFailureMessage(errors, errCount)); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Cancelled, successCount.ToString(), result); return successCount; } else if (errCount > 99) { e.Cancel = true; result = string.Format("The Fee Calculation Job was cancelled, to many failures, {0} units were calculated successfully {1}", successCount.ToString(), getFailureMessage(errors, errCount)); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Cancelled, successCount.ToString(), result); return successCount; } else { if (progress != ((counter * 100) / unitKeys.Count) && progress < 99) { progress = ((counter * 100) / unitKeys.Count); worker.ReportProgress(progress); } } } } result = string.Format("{0} units were calculated successfully {1}", successCount.ToString(), getFailureMessage(errors, errCount)); e.Result = new WorkerResult(WorkerResult.STATE_NORMAL, WorkerResultStatus.Ok, successCount.ToString(), result); } catch (Exception ex) { e.Result = new WorkerResult(WorkerResult.STATE_EXCEPTION, WorkerResultStatus.Exception, "An error occured during the average holdings fee job", "", ex); successCount = 0; } finally { worker.ReportProgress(100); } return successCount; }
public override WorkerResult Run(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e) { int i = 0; switch (Job) { case ValuationEngineJobs.ValuationMutations: i = RunValuationMutations(factory, worker, e); break; case ValuationEngineJobs.DailyValuations: i = RunDailyValuations(factory, worker, e); break; case ValuationEngineJobs.AverageHoldings: i = RunAverageHoldings(factory, worker, e); break; case ValuationEngineJobs.Fees: i = RunCalculateFees(factory, worker, e); break; } return (WorkerResult)e.Result; }
/// <summary> /// This is where the worker performs its work and returns a WorkResult.</summary> public abstract WorkerResult Run(IDalSessionFactory factory, BackgroundWorker worker, DoWorkEventArgs e);