示例#1
0
        /// <summary>
        /// the client can cancel the job
        /// </summary>
        /// <param name="AClientID"></param>
        static public bool CancelJob(string AClientID)
        {
            if (TSession.HasVariable(PROGRESSTRACKER + AClientID))
            {
                TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>();

                TLogging.SetStatusBarProcedure(null);

                if (state.JobFinished == true)
                {
                    if (TLogging.DebugLevel >= DEBUG_PROGRESS)
                    {
                        TLogging.Log("Cannot cancel the job for " + AClientID + " because the job has already finished");
                    }
                }
                else
                {
                    state.CancelJob = true;

                    if (TLogging.DebugLevel >= DEBUG_PROGRESS)
                    {
                        TLogging.Log("Cancelled the job for " + AClientID);
                    }

                    TSession.SetVariable(PROGRESSTRACKER + AClientID, state);

                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        } // Select Gift Recipients

        /// <summary>
        /// Find all the gifts for a worker, presenting the results in four year columns.
        /// NOTE - the user can select the field of the donor.
        ///
        /// All the DB work was previously done by the Select Gift Recipients function above.
        /// I only need to filter the table by recipientKey.
        /// </summary>
        /// <returns></returns>
        public static DataTable SelectGiftDonors(TParameterList AParameters, TResultList AResults)
        {
            Int64 recipientKey = AParameters.Get("RecipientKey").ToInt64();

            // TotalGiftsPerRecipient must not be static.
            DataTable TotalGiftsPerRecipient = null;

            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("SelectGiftDonors");
            string         SqlQuery    = TSession.GetVariable("QueryFinanceReport_SelectGiftRecipients").ToString();

            SqlQuery = SqlQuery.Replace("GROUP by ", "AND recipient.p_partner_key_n = " + recipientKey + " GROUP by ");
            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                TotalGiftsPerRecipient = db.SelectDT(SqlQuery, "result", Transaction);
            });

            TotalGiftsPerRecipient.DefaultView.RowFilter = "RecipientKey = " + recipientKey.ToString();
            DataTable resultTable = TotalGiftsPerRecipient.DefaultView.ToTable(true,
                                                                               new String[] { "DonorKey", "DonorName", "DonorClass", "YearTotal0", "YearTotal1", "YearTotal2", "YearTotal3" });

            return(resultTable);
        }
示例#3
0
        static private TDataBase GetDatabaseFromSession(bool AOpenConnection = true)
        {
            // if another thread gets called, then the session object is null
            if (HttpContext.Current == null)
            {
                if (Thread.CurrentThread.Name == null)
                {
                    throw new Exception(
                              "TOpenPetraOrgSessionManager.GetDatabaseFromSession: we do need a name for the thread for managing the database connection");
                }

                if (!FDatabaseObjects.ContainsKey(Thread.CurrentThread.Name))
                {
                    TDataBase db = new TDataBase();

                    if (AOpenConnection)
                    {
                        db.EstablishDBConnection(TSrvSetting.RDMBSType,
                                                 TSrvSetting.PostgreSQLServer,
                                                 TSrvSetting.PostgreSQLServerPort,
                                                 TSrvSetting.PostgreSQLDatabaseName,
                                                 TSrvSetting.DBUsername,
                                                 TSrvSetting.DBPassword,
                                                 "");
                    }

                    FDatabaseObjects.Add(Thread.CurrentThread.Name, db);
                }

                return(FDatabaseObjects[Thread.CurrentThread.Name]);
            }

            if (TSession.GetVariable("DBAccessObj") == null)
            {
                if (TServerManager.TheServerManager == null)
                {
                    TLogging.Log("GetDatabaseFromSession : TheServerManager is null");
                }
                else
                {
                    // disconnect web user after 2 minutes of inactivity. should disconnect itself already earlier
                    TServerManager.TheCastedServerManager.DisconnectTimedoutDatabaseConnections(2 * 60, "ANONYMOUS");

                    // disconnect normal users after 3 hours of inactivity
                    TServerManager.TheCastedServerManager.DisconnectTimedoutDatabaseConnections(3 * 60 * 60, "");

                    if (AOpenConnection)
                    {
                        TServerManager.TheCastedServerManager.EstablishDBConnection();
                    }
                }
            }

            return((TDataBase)TSession.GetVariable("DBAccessObj"));
        }
示例#4
0
        public string GetVersion()
        {
            object loggedIn = TSession.GetVariable("LoggedIn");

            if ((null != loggedIn) && ((bool)loggedIn == true))
            {
                return(TFileVersionInfo.GetApplicationVersion().ToVersion().ToString());
            }

            return("0.0.0.0");
        }
示例#5
0
        public bool IsUserLoggedIn()
        {
            object loggedIn = TSession.GetVariable("LoggedIn");

            if ((null != loggedIn) && ((bool)loggedIn == true))
            {
                return(true);
            }

            return(false);
        }
示例#6
0
        public string IsUserLoggedIn()
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            object loggedIn = TSession.GetVariable("LoggedIn");

            if ((null != loggedIn) && ((bool)loggedIn == true))
            {
                result.Add("resultcode", "success");
            }
            else
            {
                result.Add("resultcode", "error");
            }

            return(JsonConvert.SerializeObject(result));
        }
示例#7
0
        public string IsUserLoggedIn()
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            object loggedIn = TSession.GetVariable("LoggedIn");

            if ((null != loggedIn) && ((bool)loggedIn == true))
            {
                result.Add("resultcode", "success");
            }
            else
            {
                result.Add("selfsignupEnabled", TMaintenanceWebConnector.SignUpSelfServiceEnabled()?"true":"false");
                result.Add("resultcode", "error");
            }

            return(JsonConvert.SerializeObject(result));
        }
示例#8
0
        /// <summary>
        /// get the current state, by clientID
        /// </summary>
        /// <param name="AClientID"></param>
        /// <returns></returns>
        static public TProgressState GetCurrentState(string AClientID)
        {
            TSession.RefreshFromDatabase();

            if ((AClientID != null) && TSession.HasVariable(PROGRESSTRACKER + AClientID))
            {
                TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>();
                if (state.PercentageDone > 100)
                {
                    TLogging.Log("invalid percentage: " + state.PercentageDone.ToString());
                    state.PercentageDone = 99;
                }

                return(state);
            }

            return(new TProgressState());
        }
示例#9
0
        /// <summary>get user information from the session</summary>
        public static TPetraPrincipal GetUserInfo()
        {
            try
            {
                object value = TSession.GetVariable("UserInfo");

                if (value == null)
                {
                    TLogging.Log("UserInfo is null");
                    return(null);
                }

                return(JsonConvert.DeserializeObject <TPetraPrincipal>(TSession.GetVariant("UserInfo").ToJson()));
            }
            catch (Exception e)
            {
                TLogging.Log("Get user info " + e.ToString());
            }

            return(null);
        }
示例#10
0
        /// <summary>
        /// set the current state
        /// </summary>
        /// <param name="AClientID"></param>
        /// <param name="AStatusMessage"></param>
        /// <param name="ACurrentAbsoluteAmount"></param>
        static public void SetCurrentState(string AClientID, string AStatusMessage, Decimal ACurrentAbsoluteAmount)
        {
            if (TSession.HasVariable(PROGRESSTRACKER + AClientID))
            {
                TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>();

                if (AStatusMessage.Length > 0)
                {
                    state.StatusMessage = AStatusMessage;
                }

                state.PercentageDone = Convert.ToInt32((ACurrentAbsoluteAmount / state.AbsoluteOverallAmount) * 100.0m);

                if (TLogging.DebugLevel >= DEBUG_PROGRESS)
                {
                    // avoid recursive calls, especially during report calculation
                    Console.WriteLine(state.PercentageDone.ToString() + "%: " + state.StatusMessage);
                }

                TSession.SetVariable(PROGRESSTRACKER + AClientID, state);
            }
        }
示例#11
0
        /// <summary>
        /// the server will set the job to finished
        /// </summary>
        static public bool FinishJob(string AClientID)
        {
            if (TSession.HasVariable(PROGRESSTRACKER + AClientID))
            {
                TProgressState state = ((JObject)TSession.GetVariable(PROGRESSTRACKER + AClientID)).ToObject <TProgressState>();

                state.JobFinished = true;

                if (TLogging.DebugLevel >= DEBUG_PROGRESS)
                {
                    TLogging.Log("Finished the job for " + AClientID);
                }

                TSession.SetVariable(PROGRESSTRACKER + AClientID, state);

                TLogging.SetStatusBarProcedure(null);

                return(true);
            }

            return(false);
        }
示例#12
0
 static private TPetraPrincipal GetUserInfoFromSession()
 {
     return((TPetraPrincipal)TSession.GetVariable("UserInfo"));
 }
示例#13
0
        /// <summary>
        /// This method is called when clients access the Daily Exchange Rate data.
        /// The Daily Exchange Rate table is unusual in that it doesn't really need to hold any data because the DataSet that the client receives
        /// contains all the used rates from the GL/Gift tables whether or not those rates are in the DER table itself.  Any rates in the DER table
        /// that are NOT used are also returned, but, of course, because they are not used anywhere they are not very inetresting!
        /// Additionally, because the GL/Gift tables do not necessarily hold a time or a time that matches the same rate in the DER table, it is possible
        /// for the DER table to have a rate that is used on the date but at a different time.  As a result the client sometimes does not see all rows
        /// from the DER table - and so has no way of deleting them.
        ///
        /// That is the reason why we need to automatically clean the table.
        ///
        /// But there is some value in having some 'unused' rows that are work-in-progress.  So we delete everything in the DER table that
        /// applies to dates older than 30 days.  In the future this might become a configurable server option.
        /// </summary>
        private static void DoDailyExchangeRateClean()
        {
            DateTime PreviousDailyExchangeRateAccessTime = DateTime.UtcNow.AddHours(-24);

            if (TSession.HasVariable("PreviousDailyExchangeRateAccessTime"))
            {
                PreviousDailyExchangeRateAccessTime = (DateTime)TSession.GetVariable("PreviousDailyExchangeRateAccessTime");
            }

            DateTime PreviousDailyExchangeRateCleanTime = DateTime.UtcNow.AddDays(-30);

            if (TSession.HasVariable("PreviousDailyExchangeRateCleanTime"))
            {
                PreviousDailyExchangeRateCleanTime = (DateTime)TSession.GetVariable("PreviousDailyExchangeRateCleanTime");
            }

            if ((DateTime.UtcNow - PreviousDailyExchangeRateAccessTime).TotalHours > 8)
            {
                // Nobody has opened a DailyExchangeRate screen for 8 hours
                if ((DateTime.UtcNow - PreviousDailyExchangeRateCleanTime).TotalHours > 24)
                {
                    // It is more than 24 hours since our last clean
                    TDBTransaction t             = new TDBTransaction();
                    TDataBase      db            = DBAccess.Connect("DoDailyExchangeRateClean");
                    bool           bSubmissionOk = false;
                    db.WriteTransaction(ref t, ref bSubmissionOk,
                                        delegate
                    {
                        string logMsg        = String.Empty;
                        int affectedRowCount = 0;

                        // Standard is that we delete rows applicable to dates more than 60 days old
                        string criticalDate = DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd");

                        try
                        {
                            // Our deletion rule is to delete rows where
                            //  either the effective date is too old and we have no info about creation or modification
                            //  or     the creation date is too old and we have no info about any modification
                            //  or     the modification date is too old
                            // These rules ensure that if rates are added to a DB that is past its last accounting period (like SA-DB)
                            //  we can still continue to use the DER screen to add unused rates because they will have create/modify times
                            //  that can be long past the final accounting period because we will keep
                            //         any row that has been modified recently, whatever the effective date or creation date
                            //         any row that was created recently but not subsequently modified, whatever the effective date
                            //         any row where we don't have info about create/modify but where the effective date is recent
                            string sql = String.Format(
                                "DELETE FROM PUB_{0} WHERE (({1}<'{2}') and {3} is NULL and {4} is NULL) or (({3}<'{2}') and {4} is NULL) or ({4}<'{2}')",
                                ADailyExchangeRateTable.GetTableDBName(),
                                ADailyExchangeRateTable.GetDateEffectiveFromDBName(),
                                criticalDate,
                                ADailyExchangeRateTable.GetDateCreatedDBName(),
                                ADailyExchangeRateTable.GetDateModifiedDBName());
                            affectedRowCount = db.ExecuteNonQuery(sql, t);
                            bSubmissionOk    = true;
                            TSession.SetVariable("PreviousDailyExchangeRateCleanTime", DateTime.UtcNow);
                        }
                        catch (Exception ex)
                        {
                            logMsg  = "An error occurred while trying to purge the Daily Exchange Rate table of 'aged' rows.";
                            logMsg += String.Format("  The exception message was: {0}", ex.Message);
                        }

                        if ((affectedRowCount > 0) && (logMsg == String.Empty))
                        {
                            logMsg =
                                String.Format("The Daily Exchange Rate table was purged of {0} entries applicable prior to ",
                                              affectedRowCount) + criticalDate;
                        }

                        if (logMsg != String.Empty)
                        {
                            TLogging.Log(logMsg);
                        }
                    });
                }
            }

            TSession.SetVariable("PreviousDailyExchangeRateAccessTime", DateTime.UtcNow);
        }