Skip to content
Permalink
Browse files

refactor TSession to not use an existing database connection.

only use one database connection when initializing the thread, and for setting variables.
adjusting progress tracker.
  • Loading branch information...
tpokorra committed Aug 6, 2019
1 parent dcbf469 commit d3f04bfc4104aff88c2073a83ce71ce66e10e29a
@@ -4,7 +4,7 @@
// @Authors:
// christiank, timop
//
// Copyright 2004-2014 by OM International
// Copyright 2004-2019 by OM International
//
// This file is part of OpenPetra.org.
//
@@ -296,7 +296,7 @@ public void EndSession()
if (HttpContext.Current != null)
{
TLogging.Log("EndSession (for client '" + this.ClientName + "'): Clearing Session");
TSession.Clear();
TSession.CloseSession();
}

FClientDisconnectionFinishedTime = DateTime.Now;

Large diffs are not rendered by default.

@@ -48,16 +48,15 @@ public class TProgressTracker
/// <param name="AClientID"></param>
/// <param name="ACaption"></param>
/// <param name="AAbsoluteOverallAmount"></param>
/// <param name="ADataBase"></param>
/// <returns></returns>
static public TProgressState InitProgressTracker(string AClientID, string ACaption, decimal AAbsoluteOverallAmount = 100.0m, TDataBase ADataBase = null)
static public TProgressState InitProgressTracker(string AClientID, string ACaption, decimal AAbsoluteOverallAmount = 100.0m)
{
TProgressState state = new TProgressState();

state.AbsoluteOverallAmount = AAbsoluteOverallAmount;
state.Caption = ACaption;

TSession.SetVariable(PROGRESSTRACKER + AClientID, state, ADataBase);
TSession.SetVariable(PROGRESSTRACKER + AClientID, state);

return state;
}
@@ -66,13 +65,14 @@ static public TProgressState InitProgressTracker(string AClientID, string ACapti
/// get the current state, by clientID
/// </summary>
/// <param name="AClientID"></param>
/// <param name="ADataBase"></param>
/// <returns></returns>
static public TProgressState GetCurrentState(string AClientID, TDataBase ADataBase = null)
static public TProgressState GetCurrentState(string AClientID)
{
if ((AClientID != null) && TSession.HasVariable(PROGRESSTRACKER + AClientID, ADataBase))
TSession.RefreshFromDatabase();

if ((AClientID != null) && TSession.HasVariable(PROGRESSTRACKER + AClientID))
{
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID, ADataBase)).ToObject<TProgressState>();
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject<TProgressState>();
if (state.PercentageDone > 100)
{
TLogging.Log("invalid percentage: " + state.PercentageDone.ToString());
@@ -93,12 +93,11 @@ static public TProgressState GetCurrentState(string AClientID, TDataBase ADataBa
/// <param name="AClientID"></param>
/// <param name="AStatusMessage"></param>
/// <param name="ACurrentAbsoluteAmount"></param>
/// <param name="ADataBase"></param>
static public void SetCurrentState(string AClientID, string AStatusMessage, Decimal ACurrentAbsoluteAmount, TDataBase ADataBase = null)
static public void SetCurrentState(string AClientID, string AStatusMessage, Decimal ACurrentAbsoluteAmount)
{
if (TSession.HasVariable(PROGRESSTRACKER + AClientID, ADataBase))
if (TSession.HasVariable(PROGRESSTRACKER + AClientID))
{
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID, ADataBase)).ToObject<TProgressState>();
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject<TProgressState>();

if (AStatusMessage.Length > 0)
{
@@ -113,20 +112,19 @@ static public void SetCurrentState(string AClientID, string AStatusMessage, Deci
Console.WriteLine(state.PercentageDone.ToString() + "%: " + state.StatusMessage);
}

TSession.SetVariable(PROGRESSTRACKER + AClientID, state, ADataBase);
TSession.SetVariable(PROGRESSTRACKER + AClientID, state);
}
}

/// <summary>
/// the client can cancel the job
/// </summary>
/// <param name="AClientID"></param>
/// <param name="ADataBase"></param>
static public bool CancelJob(string AClientID, TDataBase ADataBase = null)
static public bool CancelJob(string AClientID)
{
if (TSession.HasVariable(PROGRESSTRACKER + AClientID, ADataBase))
if (TSession.HasVariable(PROGRESSTRACKER + AClientID))
{
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID, ADataBase)).ToObject<TProgressState>();
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject<TProgressState>();

TLogging.SetStatusBarProcedure(null);

@@ -146,7 +144,7 @@ static public bool CancelJob(string AClientID, TDataBase ADataBase = null)
TLogging.Log("Cancelled the job for " + AClientID);
}

TSession.SetVariable(PROGRESSTRACKER + AClientID, state, ADataBase);
TSession.SetVariable(PROGRESSTRACKER + AClientID, state);

return true;
}
@@ -158,11 +156,11 @@ static public bool CancelJob(string AClientID, TDataBase ADataBase = null)
/// <summary>
/// the server will set the job to finished
/// </summary>
static public bool FinishJob(string AClientID, TDataBase ADataBase = null)
static public bool FinishJob(string AClientID)
{
if (TSession.HasVariable(PROGRESSTRACKER + AClientID, ADataBase))
if (TSession.HasVariable(PROGRESSTRACKER + AClientID))
{
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID, ADataBase)).ToObject<TProgressState>();
TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject<TProgressState>();

state.JobFinished = true;

@@ -171,7 +169,7 @@ static public bool FinishJob(string AClientID, TDataBase ADataBase = null)
TLogging.Log("Finished the job for " + AClientID);
}

TSession.SetVariable(PROGRESSTRACKER + AClientID, state, ADataBase);
TSession.SetVariable(PROGRESSTRACKER + AClientID, state);

TLogging.SetStatusBarProcedure(null);

@@ -86,6 +86,8 @@ public TOpenPetraOrgSessionManager() : base()
/// </summary>
public static bool Init()
{
TSession.InitThread();

if (ConfigFileName == string.Empty)
{
// make sure the correct config file is used
@@ -127,7 +129,7 @@ public static bool Init()
// if the Login Method is called: reset cookie, ignore any old session
if ((HttpContext.Current != null) && (HttpContext.Current.Request.PathInfo == "/Login"))
{
TSession.Clear();
TSession.CloseSession();
}

if (TServerManager.TheServerManager == null)
@@ -162,7 +164,7 @@ public static bool Init()
if (HttpContext.Current.Request.PathInfo == "/IsUserLoggedIn")
{
// we want a clean json response saying the user is not logged in
TSession.Clear();
TSession.CloseSession();
return true;
}

@@ -230,7 +232,7 @@ public static bool Init()
TLogging.Log(e.StackTrace);
TSession.SetVariable("LoggedIn", false);

TSession.Clear();
TSession.CloseSession();
return TClientManager.LoginErrorFromException(e);
}
}
@@ -349,7 +351,7 @@ public string Logout()

if (DomainManager.CurrentClient == null)
{
TSession.Clear();
TSession.CloseSession();
}
else
{
@@ -365,11 +365,11 @@ public static BankImportTDS GetBankStatementTransactionsAndMatches(Int32 AStatem

TProgressTracker.InitProgressTracker(MyClientID,
Catalog.GetString("Load Bank Statement"),
100.0m, db);
100.0m);

TProgressTracker.SetCurrentState(MyClientID,
Catalog.GetString("loading statement"),
0, db);
0);

DataTable PartnerByDonorKey;

@@ -456,7 +456,7 @@ public static BankImportTDS GetBankStatementTransactionsAndMatches(Int32 AStatem
TProgressTracker.SetCurrentState(MyClientID,
Catalog.GetString("finding matches") +
" " + count + "/" + ResultDataset.AEpTransaction.Rows.Count.ToString(),
10.0m + (count * 80.0m / ResultDataset.AEpTransaction.Rows.Count), db);
10.0m + (count * 80.0m / ResultDataset.AEpTransaction.Rows.Count));
count++;

BankImportTDSAEpTransactionRow tempTransactionRow =
@@ -646,7 +646,7 @@ public static BankImportTDS GetBankStatementTransactionsAndMatches(Int32 AStatem

TProgressTracker.SetCurrentState(MyClientID,
Catalog.GetString("save matches"),
90.0m, db);
90.0m);

TempDataset.ThrowAwayAfterSubmitChanges = true;
// only store a_ep_transactions and a_ep_matches, but without additional typed fields (ie MatchAction)
@@ -720,7 +720,7 @@ public static BankImportTDS GetBankStatementTransactionsAndMatches(Int32 AStatem

Transaction.Commit();

TProgressTracker.FinishJob(MyClientID, db);
TProgressTracker.FinishJob(MyClientID);

return ResultDataset;
}
@@ -1121,7 +1121,7 @@ public static bool CommitMatches(BankImportTDS AMainDS)

TProgressTracker.InitProgressTracker(MyClientID,
Catalog.GetString("Creating gift batch"),
MainDS.AEpTransaction.DefaultView.Count + 10, db);
MainDS.AEpTransaction.DefaultView.Count + 10);

if (!TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber, ref BatchDateEffective, out DateEffectiveYearNumber,
out DateEffectivePeriodNumber,
@@ -1148,7 +1148,7 @@ public static bool CommitMatches(BankImportTDS AMainDS)
Catalog.GetString("Creating Gift Batch"),
String.Format(Catalog.GetString("There are no transactions for statement #{0}."), AStatementKey),
TResultSeverity.Resv_Info));
TProgressTracker.FinishJob(MyClientID, db);
TProgressTracker.FinishJob(MyClientID);
return false;
}

@@ -1172,7 +1172,7 @@ public static bool CommitMatches(BankImportTDS AMainDS)
transactionRow.Description);
AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Creating Gift Batch"), msg, TResultSeverity.Resv_Critical));
Transaction.Rollback();
TProgressTracker.FinishJob(MyClientID, db);
TProgressTracker.FinishJob(MyClientID);
return false;
}
}
@@ -1222,7 +1222,7 @@ public static bool CommitMatches(BankImportTDS AMainDS)
{
TProgressTracker.SetCurrentState(MyClientID,
Catalog.GetString("Preparing the gifts"),
counter++, db);
counter++);

AEpTransactionRow transactionRow = (AEpTransactionRow)dv.Row;

@@ -1316,11 +1316,11 @@ public static bool CommitMatches(BankImportTDS AMainDS)

TProgressTracker.SetCurrentState(MyClientID,
Catalog.GetString("Submit to database"),
counter++, db);
counter++);

if (AVerificationResult.HasCriticalErrors)
{
TProgressTracker.FinishJob(MyClientID, db);
TProgressTracker.FinishJob(MyClientID);
return false;
}

@@ -1333,7 +1333,7 @@ public static bool CommitMatches(BankImportTDS AMainDS)
TSubmitChangesResult result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref GiftDS,
out VerificationResultSubmitChanges);

TProgressTracker.FinishJob(MyClientID, db);
TProgressTracker.FinishJob(MyClientID);

if (result == TSubmitChangesResult.scrOK)
{
@@ -2372,7 +2372,7 @@ private static void SubmitChanges(GLPostingTDS AMainDS, TDataBase ADataBase)
{
TProgressTracker.InitProgressTracker(DomainManager.GClientID.ToString(),
Catalog.GetString("Posting GL batches"),
ABatchNumbers.Count * 3 + 1, db);
ABatchNumbers.Count * 3 + 1);

SortedList <string, TAmount>PostingLevel = new SortedList <string, TGLPosting.TAmount>();

@@ -2382,7 +2382,7 @@ private static void SubmitChanges(GLPostingTDS AMainDS, TDataBase ADataBase)
{
TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
Catalog.GetString("Posting GL batches"),
ABatchNumbers.IndexOf(BatchNumber) * 3, db);
ABatchNumbers.IndexOf(BatchNumber) * 3);

GLBatchTDS mainDS = null;

@@ -2403,7 +2403,7 @@ private static void SubmitChanges(GLPostingTDS AMainDS, TDataBase ADataBase)

TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
Catalog.GetString("Posting GL batches"),
ABatchNumbers.IndexOf(BatchNumber) * 3 + 1, db);
ABatchNumbers.IndexOf(BatchNumber) * 3 + 1);

mainDS.ThrowAwayAfterSubmitChanges = true;
GLBatchTDSAccess.SubmitChanges(mainDS, db);
@@ -2416,7 +2416,7 @@ private static void SubmitChanges(GLPostingTDS AMainDS, TDataBase ADataBase)

TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
Catalog.GetString("Posting GL batches"),
ABatchNumbers.Count * 3 - 1, db);
ABatchNumbers.Count * 3 - 1);

SubmissionOK = true;
});
@@ -2437,7 +2437,7 @@ private static void SubmitChanges(GLPostingTDS AMainDS, TDataBase ADataBase)
}
finally
{
TProgressTracker.FinishJob(DomainManager.GClientID.ToString(), db);
TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
}

AVerifications = VerificationResult;

0 comments on commit d3f04bf

Please sign in to comment.
You can’t perform that action at this time.