Esempio n. 1
0
        /// <summary>
        /// Callback Method that gets called from the 'FirstChanceException' Event if the Exception meant that
        /// a DB Connection got broken and hence attempts to restore it automatically should be performed.
        /// </summary>
        /// <param name="ASource">Provided automatically by .NET - not used.</param>
        /// <param name="AException">Provided automatically by .NET (holds the Exception that just occurred)
        ///  - not used.</param>
        public void ExceptionHandling_DBConnectionBrokenCallback(object ASource, Exception AException)
        {
            bool   FlagWasntSet = false;
            Thread PerformDBReconnectionThread;

            lock (FDBConnectionBrokenLock)
            {
                if (!FDBConnectionBroken)
                {
                    FDBConnectionBroken = true;

                    FlagWasntSet = true;
                }
            }

            // Guard against reentry (this callback can be called numerous times [possibly in very quick succession]!):
            // --> Only take measures if this is the first call in a row!
            if (FlagWasntSet)
            {
                // Ensure we are starting a Thread for DB re-connection attempts only if the Server's DB Polling
                // DB Connection is actually broken. (Reason for this check: This Event Handler can get called because a
                // Client's AppDomain has come across a broken DB Connection *which since has been automatically restored*...
                // if we wouldn't do this check here then we would in this case start re-connection attempts on a perfectly
                // fine Server's DB Polling connection, which could have adverse side effects if DB commands are getting
                // executed on it while this would happen!)
                if (!IsDBConnectionOK())
                {
                    StopCheckDBConnectionTimer();

                    QueueClientTaskForAllClientsRegardingBrokenDBConnection(true);

                    TDBReconnectionThread ParameterisedThreadWithCallback = new TDBReconnectionThread(this,
                                                                                                      FDBConnectionEstablishmentAtStartup,
                                                                                                      new TDBReconnectionThreadCallback(DBReconnectionCallback));
                    PerformDBReconnectionThread = new Thread(
                        new ThreadStart(ParameterisedThreadWithCallback.PerformDBReconnection));
                    PerformDBReconnectionThread.Name = UserInfo.GUserInfo.UserID + "__DBReconnectionThread";
                    TLogging.LogAtLevel(7, PerformDBReconnectionThread.Name + " starting.");

                    PerformDBReconnectionThread.Start();
                }
            }
        }
Esempio n. 2
0
        public static Boolean VerifyPartner(Int64 APartnerKey)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;
            PPartnerTable  PartnerTable;
            Boolean        ReturnValue = true;

            // initialise outout Arguments
            if (APartnerKey != 0)
            {
                ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                    TEnforceIsolationLevel.eilMinimum,
                                                                                    out NewTransaction);
                try
                {
                    PartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction);
                }
                finally
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TPartnerServerLookups.VerifyPartner: committed own transaction.");
                    }
                }

                if (PartnerTable.Rows.Count == 0)
                {
                    ReturnValue = false;
                }
                else
                {
                    ReturnValue = true;
                }
            }
            else
            {
                // Return result as valid if Partner Key is 0.
                ReturnValue = true;
            }

            return(ReturnValue);
        }
        /// <summary>
        /// Passes data as a Typed DataSet to the Screen, containing multiple DataTables.
        ///
        /// </summary>
        /// <returns>void</returns>
        public OfficeSpecificDataLabelsTDS GetData()
        {
            OfficeSpecificDataLabelsTDS ReturnValue;
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);
            ReturnValue = GetData(ReadTransaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.CommitTransaction();
                TLogging.LogAtLevel(7, "TOfficeSpecificDataLabelsUIConnector.GetData: committed own transaction.");
            }

            return(ReturnValue);
        }
Esempio n. 4
0
        public static System.Boolean GetInstalledPatches(out Ict.Petra.Shared.MSysMan.Data.SPatchLogTable APatchLogDT)
        {
            SPatchLogTable TmpTable = new SPatchLogTable();

            APatchLogDT = new SPatchLogTable();
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction = false;

            TLogging.LogAtLevel(9, "TSysManServerLookups.GetInstalledPatches called!");

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);

            try
            {
                // Load data
                TmpTable = SPatchLogAccess.LoadAll(ReadTransaction);
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TSysManServerLookups.GetInstalledPatches: committed own transaction.");
                }
            }

            /* Sort the data...
             */
            TmpTable.DefaultView.Sort = SPatchLogTable.GetDateRunDBName() + " DESC, " +
                                        SPatchLogTable.GetPatchNameDBName() + " DESC";

            /* ...and put it in the output table.
             */
            for (int Counter = 0; Counter < TmpTable.DefaultView.Count; ++Counter)
            {
                TLogging.LogAtLevel(7, "Patch: " + TmpTable.DefaultView[Counter][0]);
                APatchLogDT.ImportRow(TmpTable.DefaultView[Counter].Row);
            }

            return(true);
        }
Esempio n. 5
0
        public static PBankingDetailsTable GetPartnerBankingDetails(long AFromPartnerKey, long AToPartnerKey)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            PBankingDetailsTable ReturnTable = new PBankingDetailsTable();

            try
            {
                PBankingDetailsTable FromBankingDetailsTable = PBankingDetailsAccess.LoadViaPPartner(AFromPartnerKey, Transaction);
                PBankingDetailsTable ToBankingDetailsTable   = PBankingDetailsAccess.LoadViaPPartner(AToPartnerKey, Transaction);

                // clone the data in each table and add them to a new table to combine the data

                foreach (DataRow Row in FromBankingDetailsTable.Rows)
                {
                    object[] RowArray      = Row.ItemArray;
                    object[] RowArrayClone = (object[])RowArray.Clone();
                    DataRow  RowClone      = ReturnTable.NewRowTyped(false);
                    RowClone.ItemArray = RowArrayClone;
                    ReturnTable.Rows.Add(RowClone);
                }

                foreach (DataRow Row in ToBankingDetailsTable.Rows)
                {
                    object[] RowArray      = Row.ItemArray;
                    object[] RowArrayClone = (object[])RowArray.Clone();
                    DataRow  RowClone      = ReturnTable.NewRowTyped(false);
                    RowClone.ItemArray = RowArrayClone;
                    ReturnTable.Rows.Add(RowClone);
                }
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
                TLogging.LogAtLevel(7, "TMergePartnersWebConnector.GetPartnerBankingDetails: rollback own transaction.");
            }

            return(ReturnTable);
        }
        public static BankTDS GetPBankRecords()
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            BankTDS ReturnValue = new BankTDS();

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum, out NewTransaction);
            try
            {
                string QueryBankRecords =
                    "SELECT PUB_p_bank.*, PUB_p_partner.p_status_code_c, PUB_p_location.* " +
                    "FROM PUB_p_bank JOIN PUB_p_partner ON PUB_p_partner.p_partner_key_n = PUB_p_bank.p_partner_key_n " +
                    "LEFT OUTER JOIN PUB_p_partner_location ON PUB_p_bank.p_partner_key_n = PUB_p_partner_location.p_partner_key_n " +
                    "AND (PUB_p_partner_location.p_date_good_until_d IS NULL OR PUB_p_partner_location.p_date_good_until_d >= DATE(NOW())) " +
                    "JOIN PUB_p_location ON PUB_p_partner_location.p_site_key_n = PUB_p_location.p_site_key_n " +
                    "AND PUB_p_partner_location.p_location_key_i = PUB_p_location.p_location_key_i";

                DBAccess.GDBAccessObj.Select(ReturnValue,
                                             QueryBankRecords,
                                             ReturnValue.PBank.TableName, ReadTransaction, null);

                foreach (BankTDSPBankRow Row in ReturnValue.PBank.Rows)
                {
                    // mark inactive bank accounts
                    if (Row.StatusCode != SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE))
                    {
                        Row.BranchCode = SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " " + Row.BranchCode;
                    }
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                    TLogging.LogAtLevel(7, "TPartnerDataReaderWebConnector.GetPBankRecords: committed own transaction.");
                }
            }

            return(ReturnValue);
        }
Esempio n. 7
0
        public static IndividualDataTDS GetData(Int64 APartnerKey, TIndividualDataItemEnum AIndivDataItem)
        {
            IndividualDataTDS ReturnValue;
            TDBTransaction    ReadTransaction;
            Boolean           NewTransaction;

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);
            ReturnValue = GetData(APartnerKey, AIndivDataItem, ReadTransaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.CommitTransaction();
                TLogging.LogAtLevel(7, "TIndividualDataWebConnector.GetData: committed own transaction.");
            }

            return(ReturnValue);
        }
Esempio n. 8
0
        private static String GetConferencePrefix(long AConferenceKey)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction   = false;
            String         ConferencePrefix = "-----";
            PUnitTable     UnitTable;

            TLogging.LogAtLevel(9, "TConferenceOptions.GetOutreachPrefix: called.");

            TDataBase db = DBAccess.Connect("GetConferencePrefix");

            ReadTransaction = db.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                             out NewTransaction);

            try
            {
                UnitTable = PUnitAccess.LoadByPrimaryKey(AConferenceKey, ReadTransaction);

                if (UnitTable.Rows.Count > 0)
                {
                    if (UnitTable.Rows[0][PUnitTable.GetOutreachCodeDBName()] != System.DBNull.Value)
                    {
                        ConferencePrefix = (string)UnitTable.Rows[0][PUnitTable.GetOutreachCodeDBName()];

                        if (ConferencePrefix.Length > 5)
                        {
                            ConferencePrefix = ConferencePrefix.Substring(0, 5);
                        }
                    }
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    ReadTransaction.Commit();
                    TLogging.LogAtLevel(7, "TConferenceOptions.GetOutreachPrefix: committed own transaction.");
                }
            }

            return(ConferencePrefix);
        }
Esempio n. 9
0
        /// <summary>
        /// Checks whether an Extract with a certain Extract Name exists.
        /// </summary>
        /// <param name="AExtractName">Name of the Extract to check for.</param>
        /// <returns>True if an Extract with the specified Extract Name exists,
        /// otherwise false.</returns>
        public static bool CheckExtractExists(string AExtractName)
        {
            TDBTransaction    ReadTransaction;
            Boolean           NewTransaction;
            Boolean           ReturnValue = false;
            MExtractMasterRow TemplateRow;

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum, out NewTransaction);

            // Check if there is already an extract with the extract name
            try
            {
                TemplateRow             = new MExtractMasterTable().NewRowTyped(false);
                TemplateRow.ExtractName = AExtractName;

                if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, ReadTransaction) > 0)
                {
                    ReturnValue = true;
                }

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();

                    TLogging.LogAtLevel(8, "TExtractsHandling.CheckExtractExists: committed own transaction!");
                }
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the checking whether an Extract exists:" + Environment.NewLine + Exc.ToString());

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }

                throw;
            }

            return(ReturnValue);
        }
Esempio n. 10
0
            /// <summary>
            /// Constructor for passing in parameters.
            /// </summary>
            public TClientStillAliveCheck(TConnectedClient AConnectedClient,
                                          TClientServerConnectionType AClientServerConnectionType,
                                          TDelegateTearDownAppDomain ATearDownAppDomain)
            {
                FClientObject = AConnectedClient;
                ClientName    = FClientObject.ClientName;
                Int32 ClientStillAliveTimeout;

                TLogging.LogAtLevel(2, "TClientStillAliveCheck (for ClientName '" + ClientName + "'') created");

                // Determine timeout limit (different for Clients connected via LAN or Remote)
                if (AClientServerConnectionType == TClientServerConnectionType.csctRemote)
                {
                    ClientStillAliveTimeout = TSrvSetting.ClientKeepAliveTimeoutAfterXSecondsRemote;
                }
                else if (AClientServerConnectionType == TClientServerConnectionType.csctLAN)
                {
                    ClientStillAliveTimeout = TSrvSetting.ClientKeepAliveTimeoutAfterXSecondsLAN;
                }
                else
                {
                    ClientStillAliveTimeout = TSrvSetting.ClientKeepAliveTimeoutAfterXSecondsLAN;
                }

                UClientStillAliveTimeout       = ClientStillAliveTimeout;
                UClientStillAliveCheckInterval = TSrvSetting.ClientKeepAliveCheckIntervalInSeconds;
                UTearDownAppDomain             = ATearDownAppDomain;
//                UTearDownAppDomainToken = ATearDownAppDomainToken;


                TLogging.LogAtLevel(2, "ClientStillAliveTimeout: " + ClientStillAliveTimeout.ToString() + "; " +
                                    "ClientKeepAliveCheckIntervalInSeconds: " + UClientStillAliveCheckInterval.ToString());

                // Start ClientStillAliveCheckThread
                UKeepServerAliveCheck                     = true;
                UClientStillAliveCheckThread              = new Thread(new ThreadStart(ClientStillAliveCheckThread));
                UClientStillAliveCheckThread.Name         = "ClientStillAliveCheckThread" + Guid.NewGuid().ToString();
                UClientStillAliveCheckThread.IsBackground = true;
                UClientStillAliveCheckThread.Start();

                TLogging.LogAtLevel(2, "TClientStillAliveCheck (for ClientName '" + ClientName + "'): started ClientStillAliveCheckThread.");
            }
        /// <summary>
        /// Procedure to execute a Find query. Although the full
        /// query results are retrieved from the DB and stored internally in an object,
        /// data will be returned in 'pages' of data, each page holding a defined number
        /// of records.
        /// </summary>
        /// <param name="ACriteriaData">HashTable containing non-empty Partner Find parameters</param>
        public void PerformSearch(DataTable ACriteriaData)
        {
            String CustomWhereCriteria;

            OdbcParameter[] ParametersArray;

            FPagedDataSetObject = new TPagedDataSet(new PartnerFindTDSSearchResultTable());

            // Pass the TAsynchronousExecutionProgress object to FPagedDataSetObject so that it

            // Build WHERE criteria string based on AFindCriteria
            CustomWhereCriteria = BuildCustomWhereCriteria(ACriteriaData, out ParametersArray);

            TLogging.LogAtLevel(6, "WHERE CLAUSE: " + CustomWhereCriteria);

            FPagedDataSetObject.FindParameters = new TPagedDataSet.TAsyncFindParameters(
                " p_city_c, p_postal_code_c,  p_locality_c, p_street_name_c, p_address_3_c, p_county_c, p_country_code_c, p_location_key_i, p_site_key_n ",
                "PUB_p_location ",
                " p_location_key_i<>-1 " + CustomWhereCriteria + ' ',
                "p_city_c ",
                null,
                ParametersArray);

            // fields
            // table
            // where
            // order by
            // both empty for now

            string session        = TSession.GetSessionID();
            string configfilename = TAppSettingsManager.ConfigFileName;

            //
            // Start the Find Thread
            //
            ThreadStart myThreadStart = delegate {
                FPagedDataSetObject.ExecuteQuery(configfilename, session);
            };

            FFindThread      = new Thread(myThreadStart);
            FFindThread.Name = "PartnerLocationFind" + Guid.NewGuid().ToString();
        }
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AInspectDT"></param>
        public void SubmitChangesAsync(PSubscriptionTable AInspectDT)
        {
            Thread TheThread;

            // Cleanup (might be left in a certain state from a possible earlier call)
            FSubmitException    = null;
            FSubmissionDT       = null;
            FVerificationResult = null;
            FResponseDT         = null;
            FInspectDT          = null;
            FProgressID         = Guid.NewGuid().ToString();
            TProgressTracker.InitProgressTracker(FProgressID, string.Empty, 100.0m);
            FInspectDT = AInspectDT;
            ThreadStart ThreadStartDelegate = new ThreadStart(SubmitChangesInternal);

            TheThread      = new Thread(ThreadStartDelegate);
            TheThread.Name = "ExtractsAddSubscriptionsSubmitChanges" + Guid.NewGuid().ToString();
            TheThread.Start();
            TLogging.LogAtLevel(6, "TExtractsAddSubscriptionsUIConnector.SubmitChangesAsync thread started.");
        }
Esempio n. 13
0
        private static BankImportTDS LoadData(Int32 ALedgerNumber, Int32 AStatementKey)
        {
            TDBTransaction dbtransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            BankImportTDS MatchDS = new BankImportTDS();

            // TODO: would it help not to load all? use a_recent_match_d?
            AEpMatchAccess.LoadViaALedger(MatchDS, ALedgerNumber, dbtransaction);

            TLogging.LogAtLevel(1, "loaded " + MatchDS.AEpMatch.Rows.Count.ToString() + " a_ep_match rows");

            AEpTransactionAccess.LoadViaAEpStatement(MatchDS, AStatementKey, dbtransaction);

            DBAccess.GDBAccessObj.RollbackTransaction();

            MatchDS.AEpMatch.AcceptChanges();
            MatchDS.AEpTransaction.AcceptChanges();

            return(MatchDS);
        }
Esempio n. 14
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AInspectDT"></param>
        public void SubmitChangesAsync(PSubscriptionTable AInspectDT)
        {
            Thread TheThread;

            // Cleanup (might be left in a certain state from a possible earlier call)
            FSubmitException        = null;
            FSubmissionDT           = null;
            FAsyncExecProgress      = null;
            FVerificationResult     = null;
            FResponseDT             = null;
            FInspectDT              = null;
            this.FAsyncExecProgress = new TAsynchronousExecutionProgress();
            this.FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_ReadyToStart;
            FInspectDT = AInspectDT;
            ThreadStart ThreadStartDelegate = new ThreadStart(SubmitChangesInternal);

            TheThread = new Thread(ThreadStartDelegate);
            TheThread.Start();
            TLogging.LogAtLevel(6, "TExtractsAddSubscriptionsUIConnector.SubmitChangesAsync thread started.");
        }
Esempio n. 15
0
        private static void StoreSessionCookie(CookieContainer AContainer, string AUrl)
        {
            // store the session cookie only if we don't have one
            if (OverallCookie == null)
            {
                foreach (Cookie c in AContainer.GetCookies(new Uri(AUrl)))
                {
                    if (c.Name == "OpenPetraSessionID")
                    {
                        TLogging.LogAtLevel(1, "returned cookie\r\n" +
                                            "Name: " + c.Name + "\r\n" +
                                            "Value: " + c.Value + "\r\n" +
                                            "Path: " + c.Path + "\r\n" +
                                            "Domain: " + c.Domain);

                        OverallCookie = new Cookie(c.Name, c.Value, c.Path, c.Domain);
                    }
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// clear the current session
        /// </summary>
        static public void Clear()
        {
            // HttpContext.Current.Session.Clear();

            TLogging.LogAtLevel(1, "TSession.Clear got called");

            string sessionId = GetSessionID();

            TLogging.LogAtLevel(1, "TSession.Clear: sessionID = " + sessionId);

            if (sessionId.Length > 0)
            {
                FSessionObjects.Remove(sessionId);
                HttpContext.Current.Request.Cookies.Remove("OpenPetraSessionID");
                HttpContext.Current.Response.Cookies.Remove("OpenPetraSessionID");
                // thread might be reused???
                FSessionID = null;
                TLogging.LogAtLevel(1, "TSession.Clear: cleared session with sessionID = " + sessionId);
            }
        }
Esempio n. 17
0
        public static System.Boolean GetDBVersion(out System.String APetraDBVersion)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            APetraDBVersion = "Can not retrieve DB version";
            TLogging.LogAtLevel(9, "TSysManServerLookups.GetDatabaseVersion called!");

            SSystemDefaultsTable SystemDefaultsDT = new SSystemDefaultsTable();

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);

            // Load data
            SystemDefaultsDT = SSystemDefaultsAccess.LoadByPrimaryKey("CurrentDatabaseVersion", ReadTransaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.CommitTransaction();
                TLogging.LogAtLevel(7, "TSysManServerLookups.GetDatabaseVersion: committed own transaction.");
            }

            if (SystemDefaultsDT.Rows.Count < 1)
            {
                throw new EOPAppException(
                          "TSysManServerLookups.GetDBVersion: s_system_defaults DB Table is empty; this is unexpected and can lead to sever malfunction of OpenPetra. Contact your Support Team.");
            }

            SSystemDefaultsRow sysrow = SystemDefaultsDT.Rows[0] as SSystemDefaultsRow;

            if (sysrow == null)
            {
                throw new EOPAppException(
                          "TSysManServerLookups.GetDBVersion: s_system_defaults DB Table is empty; this is unexpected and can lead to sever malfunction of OpenPetra. Contact your Support Team.");
            }

            APetraDBVersion = sysrow.DefaultValue;

            return(true);
        }
Esempio n. 18
0
        /// <summary>
        /// Displays a general error message in a MessageBox.
        /// </summary>
        /// <param name="AErrorText">Error text to be displayed.</param>
        /// <param name="ATitle">Title of the MessageBox.</param>
        /// <param name="AMessageNumber">Message Number.</param>
        /// <param name="ATypeWhichRaisesError">Instance of an object which raises the Error.</param>
        /// <param name="AIcon">Icon to show in the MessageBox.</param>
        public static void MsgGeneralError(String AErrorText, String ATitle, String AMessageNumber, System.Type ATypeWhichRaisesError,
                                           MessageBoxIcon AIcon)
        {
            if (ATypeWhichRaisesError == null)
            {
                ATypeWhichRaisesError = new StackTrace(false).GetFrame(2).GetMethod().DeclaringType;
            }

            // Remove possible trailing double Environment.NewLines
            // (Double Environment.NewLines happen if several error messages are concatenated and they are each separated by double Environment.NewLines)
            if (AErrorText.EndsWith(Environment.NewLine + Environment.NewLine))
            {
                AErrorText = AErrorText.Substring(0, AErrorText.Length - Environment.NewLine.Length);
            }

            string message = AErrorText + BuildMessageFooter(AMessageNumber,
                                                             ATypeWhichRaisesError.Name);

            TLogging.LogAtLevel(1, ATitle + ": " + message);
            MessageBox.Show(message, ATitle, MessageBoxButtons.OK, AIcon);
        }
Esempio n. 19
0
        private void CopyRowsInPage(Int16 APage, Int16 APageSize)
        {
            TLogging.LogAtLevel(7, String.Format("TPagedDataSet.CopyRowsInPage called (APage: {0}, APageSize={1})", APage, APageSize));

            Int32 RowInPage;
            Int32 MaxRowInPage;

            MaxRowInPage = (APageSize * APage) + APageSize;

            if (MaxRowInPage > FTotalRecords)
            {
                MaxRowInPage = FTotalRecords;
            }

            for (RowInPage = (APageSize * APage); RowInPage <= MaxRowInPage - 1; RowInPage += 1)
            {
                FPageDataTable.ImportRow(FTmpDataTable.Rows[RowInPage]);
            }

            TLogging.LogAtLevel(7, String.Format("TPagedDataSet.CopyRowsInPage imported {0} rows into FPageDataTable", RowInPage));
        }
Esempio n. 20
0
        /// <summary>
        /// Closes the Database connection for this AppDomain.
        ///
        /// @comment WARNING: If you need to rename this method or change its parameters,
        /// you also need to change the String with its name and the parameters in the
        /// .NET Reflection call in TClientAppDomainConnection!
        ///
        /// </summary>
        /// <returns>void</returns>
        public void CloseDBConnection()
        {
            // Console.WriteLine('TClientDomainManager.CloseDBConnection in AppDomain: ' + Thread.GetDomain().FriendlyName);
            TLogging.LogAtLevel(9, "TClientDomainManager.CloseDBConnection: before calling GDBAccessObj.CloseDBConnection");

            try
            {
                DBAccess.GDBAccessObj.CloseDBConnection();
            }
            catch (EDBConnectionNotAvailableException)
            {
                // The DB connection was never opened. Since this is no problem here, ignore this Exception.
                TLogging.LogAtLevel(9, "TClientDomainManager.CloseDBConnection: Info: DB Connection was never opened, so can't close.");
            }
            catch (Exception)
            {
                throw;
            }

            TLogging.LogAtLevel(9, "TClientDomainManager.CloseDBConnection: after calling GDBAccessObj.CloseDBConnection");
        }
        public static PUnitTable GetActiveFieldUnits()
        {
            PUnitTable UnitTable = new PUnitTable();
            PUnitRow   UnitRow;

            TLogging.LogAtLevel(9, "TPartnerDataReaderWebConnector.GetActiveFieldUnits called!");

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                           ref Transaction,
                                                           delegate
            {
                // Load data
                string SqlStmt = "SELECT pub_" + PUnitTable.GetTableDBName() + "." + PUnitTable.GetPartnerKeyDBName() +
                                 ", pub_" + PUnitTable.GetTableDBName() + "." + PUnitTable.GetUnitNameDBName() +
                                 " FROM " + PUnitTable.GetTableDBName() + ", " + PPartnerTable.GetTableDBName() +
                                 " WHERE ((" + PUnitTable.GetOutreachCodeDBName() + " IS NULL)" +
                                 "        OR(" + PUnitTable.GetOutreachCodeDBName() + " = ''))" +
                                 " AND " + PUnitTable.GetUnitTypeCodeDBName() + " <> 'KEY-MIN'" +
                                 " AND pub_" + PUnitTable.GetTableDBName() + "." + PUnitTable.GetPartnerKeyDBName() +
                                 " = pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerKeyDBName() +
                                 " AND " + PPartnerTable.GetStatusCodeDBName() + " = 'ACTIVE'";

                // sort rows according to name
                SqlStmt = SqlStmt + " ORDER BY " + PUnitTable.GetUnitNameDBName();

                DataTable events = DBAccess.GDBAccessObj.SelectDT(SqlStmt, "fields", Transaction);

                foreach (DataRow eventRow in events.Rows)
                {
                    UnitRow            = (PUnitRow)UnitTable.NewRow();
                    UnitRow.PartnerKey = Convert.ToInt64(eventRow[0]);
                    UnitRow.UnitName   = Convert.ToString(eventRow[1]);
                    UnitTable.Rows.Add(UnitRow);
                }
            });

            return(UnitTable);
        }
        public static DataTable GetOutreachTypes(long APartnerKey)
        {
            TDBTransaction ReadTransaction;

            ReadTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            DataTable Table = new PUnitTable();

            try
            {
                string OutreachPrefixCode =
                    ((PcConferenceRow)PcConferenceAccess.LoadByPrimaryKey(APartnerKey, ReadTransaction).Rows[0]).OutreachPrefix;

                PUnitTable UnitTable = PUnitAccess.LoadAll(ReadTransaction);

                // add PUnit rows with matching OutreachPrefixCode to the new DataTable
                foreach (PUnitRow Row in UnitTable.Rows)
                {
                    if ((Row.OutreachCode.Length == 13) && (Row.OutreachCode.Substring(0, 5) == OutreachPrefixCode))
                    {
                        DataRow CopyRow = Table.NewRow();
                        ((PUnitRow)CopyRow).PartnerKey   = Row.PartnerKey;
                        ((PUnitRow)CopyRow).OutreachCode = Row.OutreachCode.Substring(5, 6);
                        ((PUnitRow)CopyRow).UnitName     = Row.UnitName;
                        Table.Rows.Add(CopyRow);
                    }
                }
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
                TLogging.LogAtLevel(7, "TConferenceDataReaderWebConnector.GetOutreachTypes: commit own transaction.");
            }

            return(Table);
        }
        /// <summary>
        /// Stops the query execution.
        /// <remarks>It might take some time until the executing query is cancelled by the DB, but this procedure returns
        /// immediately. The reason for this is that we consider the query cancellation as done since the application can
        /// 'forget' about the result of the cancellation process (but beware of executing another query while the other is
        /// stopping - this leads to ADO.NET errors that state that a ADO.NET command is still executing!).
        /// </remarks>
        /// </summary>
        public void StopSearch()
        {
            Thread StopQueryThread;

            /* Start a separate Thread that should cancel the executing query
             * (Microsoft recommends doing it this way!)
             */
            TLogging.LogAtLevel(7, "TPartnerLocationFindUIConnector.StopSearch: Starting StopQuery thread...");

            StopQueryThread      = new Thread(new ThreadStart(FPagedDataSetObject.StopQuery));
            StopQueryThread.Name = UserInfo.GUserInfo.UserID + "__ParnterFind_StopSearch_Thread";
            StopQueryThread.Start();

            /* It might take some time until the executing query is cancelled by the DB,
             * but we consider it as done since the application can 'forget' about the
             * result of the cancellation process (but beware of executing another query
             * while the other is stopping - this leads to ADO.NET errors that state that
             * a ADO.NET command is still executing!
             */

            TLogging.LogAtLevel(7, "TPartnerLocationFindUIConnector.StopSearch: Query cancelled!");
        }
Esempio n. 24
0
        public TSubmitChangesResult PrepareChangesServerSide(
            DataTable AInspectDT,
            TDBTransaction AReadTransaction)
        {
            TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrOK;

            // TODO: once we have centrally cached data tables on the server then get the data
            // from there. Until then just load it on the spot here!
            PDataLabelTable DataLabelDT = PDataLabelAccess.LoadAll(AReadTransaction);

            if (AInspectDT != null)
            {
                // Run through all rows of the value table and see if the significant column is empty/null. If so
                // then delete the row from the table (these rows are not needed any longer in order to save space
                // in the database)
                int NumRows = AInspectDT.Rows.Count;

                for (int RowIndex = NumRows - 1; RowIndex >= 0; RowIndex -= 1)
                {
                    DataRow InspectedDataRow = AInspectDT.Rows[RowIndex];

                    // only check modified or added rows because the deleted ones are deleted anyway
                    if ((InspectedDataRow.RowState == DataRowState.Modified) || (InspectedDataRow.RowState == DataRowState.Added))
                    {
                        if (IsRowObsolete(DataLabelDT, InspectedDataRow, (AInspectDT.TableName == PDataLabelValuePartnerTable.GetTableName())))
                        {
                            InspectedDataRow.Delete();
                        }
                    }
                }
            }
            else
            {
                TLogging.LogAtLevel(8, "AInspectDS = null!");
                SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved;
            }

            return(SubmissionResult);
        }
Esempio n. 25
0
        public static int CanFamilyMergeIntoDifferentClass(long APartnerKey)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                PPersonTable PersonTable = PPersonAccess.LoadViaPFamily(APartnerKey, Transaction);

                if (PersonTable.Rows.Count > 0)
                {
                    return(1);
                }

                AGiftDetailTable GiftDetailTable = AGiftDetailAccess.LoadViaPPartnerRecipientKey(APartnerKey, Transaction);

                if (GiftDetailTable.Rows.Count > 0)
                {
                    return(2);
                }

                PBankingDetailsTable BankingDetailsTable = PBankingDetailsAccess.LoadViaPPartner(APartnerKey, Transaction);

                if (BankingDetailsTable.Rows.Count > 0)
                {
                    return(3);
                }
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
                TLogging.LogAtLevel(7, "TMergePartnersWebConnector.CanFamilyMergeIntoDifferentClass: rollback own transaction.");
            }

            return(0);
        }
Esempio n. 26
0
        /// <summary>
        /// Loads the System Defaults into the cached Typed DataTable.
        ///
        /// The System Defaults are retrieved from the s_system_defaults table and are
        /// put into a Typed DataTable that has the structure of this table.
        ///
        /// </summary>
        /// <returns>void</returns>
        private void LoadSystemDefaultsTable()
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction = false;

            // Prevent other threads from obtaining a read lock on the cache table while we are (re)loading the cache table!
            FReadWriteLock.AcquireWriterLock(SharedConstants.THREADING_WAIT_INFINITE);

            try
            {
                if (FSystemDefaultsDT != null)
                {
                    FSystemDefaultsDT.Clear();
                }

                try
                {
                    ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                        TEnforceIsolationLevel.eilMinimum,
                                                                                        out NewTransaction);
                    FSystemDefaultsDT = SSystemDefaultsAccess.LoadAll(ReadTransaction);
                }
                finally
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TSystemDefaultsCache.LoadSystemDefaultsTable: commited own transaction.");
                    }
                }

                // Thread.Sleep(5000);     uncomment this for debugging. This allows checking whether read access to FSystemDefaultsDT actually waits until we release the WriterLock in the finally block.
            }
            finally
            {
                // Other threads are now free to obtain a read lock on the cache table.
                FReadWriteLock.ReleaseWriterLock();
            }
        }
        public static PPartnerTable SharedBankAccountPartners(int ABankingDetailsKey, long APartnerKey)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            PPartnerTable PartnerTable = new PPartnerTable();

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum, out NewTransaction);
            try
            {
                PPartnerBankingDetailsTable PartnerBankingDetailsTable = PPartnerBankingDetailsAccess.LoadViaPBankingDetails(ABankingDetailsKey,
                                                                                                                             ReadTransaction);

                foreach (PPartnerBankingDetailsRow Row in PartnerBankingDetailsTable.Rows)
                {
                    // if record exists with a different partner key then the Bank Account is shared
                    if (Row.PartnerKey != APartnerKey)
                    {
                        PPartnerRow PartnerRow = (PPartnerRow)PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, ReadTransaction).Rows[0];

                        PPartnerRow NewRow = PartnerTable.NewRowTyped(false);
                        NewRow.PartnerKey       = Row.PartnerKey;
                        NewRow.PartnerShortName = PartnerRow.PartnerShortName;
                        PartnerTable.Rows.Add(NewRow);
                    }
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TPartnerDataReaderWebConnector.IsBankingDetailsRowShared: committed own transaction.");
                }
            }

            return(PartnerTable);
        }
Esempio n. 28
0
        /// <summary>
        /// Cancels an asynchronously executing query. This might take some time;
        /// therefore always execute this procedure in a separate Thread!
        ///
        /// </summary>
        /// <returns>void</returns>
        public void StopQuery()
        {
            TLogging.LogAtLevel(7,
                                (this.GetType().FullName + ".StopQuery: ProgressState = " +
                                 Enum.GetName(typeof(TAsyncExecProgressState), FAsyncExecProgress.ProgressState)));

            try
            {
                if (FAsyncExecProgress.ProgressState == TAsyncExecProgressState.Aeps_Stopping)
                {
                    // Cancel the executing query.
                    TLogging.LogAtLevel(7, "TPagedDataSet.StopQuery called...");
                    FDataAdapter.SelectCommand.Cancel();
                    TLogging.LogAtLevel(7, "TPagedDataSet.StopQuery finished.");
                }
                else
                {
                    TLogging.LogAtLevel(7, this.GetType().FullName + ".StopQuery: Query got cancelled after returning records.");
                }

                FAsyncExecProgress.ProgressInformation = "Query cancelled!";
                FAsyncExecProgress.ProgressState       = TAsyncExecProgressState.Aeps_Stopped;
            }
            catch (Exception exp)
            {
                TLogging.Log(this.GetType().FullName + ".StopQuery:  Exception occured: " + exp.ToString());

                /*
                 *     WE MUST 'SWALLOW' ANY EXCEPTION HERE, OTHERWISE THE WHOLE
                 *     PETRASERVER WILL GO DOWN!!! (THIS BEHAVIOUR IS NEW WITH .NET 2.0.)
                 *
                 * --> ANY EXCEPTION THAT WOULD LEAVE THIS METHOD WOULD BE SEEN AS AN   <--
                 * --> UNHANDLED EXCEPTION IN A THREAD, AND THE .NET/MONO RUNTIME       <--
                 * --> WOULD BRING DOWN THE WHOLE PETRASERVER PROCESS AS A CONSEQUENCE! <--
                 *
                 */
            }
        }
Esempio n. 29
0
        private static bool GetReceivingFieldsForOneConference(long AConferenceKey, ref DataTable AFieldsTable)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction = false;

            TLogging.LogAtLevel(9, "TConferenceOptions.GetReceivingFieldsForOneConference called!");

            TDataBase db = DBAccess.Connect("GetReceivingFieldsForOneConference");

            ReadTransaction = db.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                             out NewTransaction);

            try
            {
                String           PartnerKeyDBName = PcAttendeeTable.GetPartnerKeyDBName();
                PcAttendeeTable  AttendeeTable;
                StringCollection FieldList = new StringCollection();
                FieldList.Add(PartnerKeyDBName);
                AttendeeTable = PcAttendeeAccess.LoadViaPcConference(AConferenceKey, FieldList, ReadTransaction);

                foreach (DataRow Row in AttendeeTable.Rows)
                {
                    long PartnerKey = (long)Row[PartnerKeyDBName];

                    GetReceivingFieldFromGiftDestination(PartnerKey, ref AFieldsTable);
                    GetReceivingFieldFromShortTermTable(PartnerKey, ref AFieldsTable);
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    ReadTransaction.Commit();
                    TLogging.LogAtLevel(7, "TConferenceOptions.GetReceivingFieldsForOneConference: committed own transaction.");
                }
            }
            return(true);
        }
Esempio n. 30
0
        private static SortedList <string, string> FSessionValues; // STATIC_OK: will be set for each request

        /// <summary>
        /// Set the session id for this current thread.
        /// Each request has its own thread.
        /// Threads can be reused for different users.
        /// </summary>
        /// <param name="ASessionID"></param>
        public static void InitThread(string ASessionID = null)
        {
            TLogging.LogAtLevel(1, "Running InitThread for thread id " + Thread.CurrentThread.ManagedThreadId.ToString());

            FSessionID     = ASessionID;
            FSessionValues = null;

            string sessionID;

            if (ASessionID == null)
            {
                sessionID = FindSessionID();
            }
            else
            {
                sessionID = ASessionID;
            }

            TDataBase db = ConnectDB("SessionInitThread");

            TDBTransaction t            = new TDBTransaction();
            bool           SubmissionOK = false;

            db.WriteTransaction(ref t,
                                ref SubmissionOK,
                                delegate
            {
                // get the session ID, or start a new session
                // load the session values from the database
                // update the session last access in the database
                // clean old sessions
                InitSession(sessionID, t);

                SubmissionOK = true;
            });

            db.CloseDBConnection();
        }