Esempio n. 1
0
File: Audit.cs Progetto: pcstx/OA
        public static int[] GetUserAuditCounters(AuditSummary summary)
        {
            if (summary == null)
                return null;

            int[] counters = new int[4];
            int maxForumCounterValue = 0;
            int maxMessageCounterValue = 0;

            counters[0] = 0; // Message Action counter
            counters[1] = -1; // Message Action selected counter with the most entries
            counters[2] = 0; // Forum Action counter
            counters[3] = -1; // Forum Action selected counter with the most entries

            IDictionaryEnumerator iterator = summary.Collection.GetEnumerator();

            while (iterator.MoveNext()) {

                switch (((ModeratorActions) iterator.Key)) {
                    case ModeratorActions.ApprovePost:
                    case ModeratorActions.EditPost:
                    case ModeratorActions.MovePost:
                    case ModeratorActions.DeletePost:
                    case ModeratorActions.LockPost:
                    case ModeratorActions.UnlockPost:
                    case ModeratorActions.MergePost:
                    case ModeratorActions.SplitPost:
                        if (iterator.Value != null) {
                            counters[0] += (int) iterator.Value;

                            if (maxMessageCounterValue < (int) iterator.Value) {
                                maxMessageCounterValue = (int) iterator.Value;
                                counters[1] = (int) iterator.Key;
                            }
                        }
                        break;

                    case ModeratorActions.EditUser:
                    case ModeratorActions.BanUser:
                    case ModeratorActions.UnbanUser:
                    case ModeratorActions.ModerateUser:
                    case ModeratorActions.UnmoderateUser:
                    case ModeratorActions.ResetPassword:
                    case ModeratorActions.ChangePassword:
                        if (iterator.Value != null) {
                            counters[2] += (int) iterator.Value;

                            if (maxForumCounterValue < (int) iterator.Value) {
                                maxForumCounterValue = (int) iterator.Value;
                                counters[3] = (int) iterator.Key;
                            }
                        }
                        break;
                }
            }

            return counters;
        }
Esempio n. 2
0
        public static AuditSummary PopulateAuditSummaryFromIDataReader(IDataReader reader)
        {
            AuditSummary summary = new AuditSummary();

            try {
                summary[ModeratorActions.ApprovePost] = (reader["ApprovePost"] != DBNull.Value) ? (int) reader["ApprovePost"] : 0;
                summary[ModeratorActions.BanUser] = (reader["BanUser"] != DBNull.Value) ? (int) reader["BanUser"] : 0;
                summary[ModeratorActions.ChangePassword] = (reader["ChangePassword"] != DBNull.Value) ? (int) reader["ChangePassword"] : 0;
                summary[ModeratorActions.DeletePost] = (reader["DeletePost"] != DBNull.Value) ? (int) reader["DeletePost"] : 0;
                summary[ModeratorActions.EditPost] = (reader["EditPost"] != DBNull.Value) ? (int) reader["EditPost"] : 0;
                summary[ModeratorActions.EditUser] = (reader["EditUser"] != DBNull.Value) ? (int) reader["EditUser"] : 0;
                summary[ModeratorActions.LockPost] = (reader["LockPost"] != DBNull.Value) ? (int) reader["LockPost"] : 0;
                summary[ModeratorActions.MergePost] = (reader["MergePost"] != DBNull.Value) ? (int) reader["MergePost"] : 0;
                summary[ModeratorActions.ModerateUser] = (reader["ModerateUser"] != DBNull.Value) ? (int) reader["ModerateUser"] : 0;
                summary[ModeratorActions.MovePost] = (reader["MovePost"] != DBNull.Value) ? (int) reader["MovePost"] : 0;
                summary[ModeratorActions.PostIsAnnouncement] = (reader["PostIsAnnouncement"] != DBNull.Value) ? (int) reader["PostIsAnnouncement"] : 0;
                summary[ModeratorActions.PostIsNotAnnoucement] = (reader["PostIsNotAnnoucement"] != DBNull.Value) ? (int) reader["PostIsNotAnnoucement"] : 0;
                summary[ModeratorActions.ResetPassword] = (reader["ResetPassword"] != DBNull.Value) ? (int) reader["ResetPassword"] : 0;
                summary[ModeratorActions.SplitPost] = (reader["SplitPost"] != DBNull.Value) ? (int) reader["SplitPost"] : 0;
                summary[ModeratorActions.UnApprovePost] = (reader["UnApprovePost"] != DBNull.Value) ? (int) reader["UnApprovePost"] : 0;
                summary[ModeratorActions.UnbanUser] = (reader["UnbanUser"] != DBNull.Value) ? (int) reader["UnbanUser"] : 0;
                summary[ModeratorActions.UnlockPost] = (reader["UnlockPost"] != DBNull.Value) ? (int) reader["UnlockPost"] : 0;
                summary[ModeratorActions.UnmoderateUser] = (reader["UnmoderateUser"] != DBNull.Value) ? (int) reader["UnmoderateUser"] : 0;
            }
            catch {
                // this should happen if one of the query column is missing
                //
                summary = null;
            }

            return summary;
        }
Esempio n. 3
0
        /// <summary>
        /// Formats user moderation counters following this pattern "[message_actions] / [forum_actions]".
        /// If one of the ingredients are 0 then we will display a '-' character instead. 
        /// </summary>
        public static string FormatUserAuditCounters(int userID, AuditSummary summary)
        {
            string outString = "{0} / {1}";
            string counterLink = "<a href=\"{0}\">{1}</a>";
            int[] counters = Audit.GetUserAuditCounters( summary );

            if (counters == null) {
                return string.Format( outString, "-", "-" );
            }

            if (counters[0] > 0 && counters[2] > 0)
                return string.Format( outString, string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[1] ), counters[0] ), string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[3] ), counters[2] ) );
            else {
                if (counters[0] == 0 && counters[2] > 0)
                    return string.Format( outString, "-", string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[3] ), counters[2] ) );
                else
                    if (counters[0] > 0 && counters[2] == 0)
                        return string.Format( outString, string.Format( counterLink, SiteUrls.Instance().UserModerationHistory( userID, counters[1] ), counters[0] ), "-" );
                    else
                        return string.Format( outString, "-", "-" );
            }
        }