예제 #1
0
 static public SiteEvent CreateNewUserEventActivity(IDnaDataReader dataReader, IDnaDataReaderCreator creator)
 {
     SiteEvent siteEvent = null;
     try
     {
         siteEvent = new SiteEvent();
         siteEvent.SiteId = dataReader.GetInt32NullAsZero("siteid");
         siteEvent.Date = new Date(dataReader.GetDateTime("DateCreated"));
         siteEvent.Type = SiteActivityType.NewUserToSite;
         siteEvent.ActivityData = XElement.Parse(
                    string.Format(DataFormat,
                     dataReader.GetInt32NullAsZero("user_userid"), dataReader.GetStringNullAsEmpty("user_username"),
                     dataReader.GetInt32NullAsZero("siteid"))
                     );
         siteEvent.UserId = dataReader.GetInt32NullAsZero("user_userid");
         siteEvent.SaveEvent(creator);
         
     }
     catch(Exception e)
     {
         siteEvent = null;
         SiteEventsProcessor.SiteEventLogger.LogException(e);
     }
     return siteEvent;
 }
예제 #2
0
        static public SiteEvent CreateComplaintArticleEventActivity(IDnaDataReader dataReader, IDnaDataReaderCreator creator)
        {
            SiteEvent siteEvent = null;
            try
            {
                siteEvent = new SiteEvent();
                siteEvent.SiteId = dataReader.GetInt32NullAsZero("siteid");
                siteEvent.Date = new Date(dataReader.GetDateTime("DateCreated"));
                siteEvent.Type = SiteActivityType.ComplaintArticle;

                var complainantUserName = dataReader.GetStringNullAsEmpty("complainantUserName");
                if (String.IsNullOrEmpty(complainantUserName))
                {
                    complainantUserName = "******";
                }

                siteEvent.ActivityData = XElement.Parse(
                           string.Format(DataFormat,
                            dataReader.GetInt32NullAsZero("complaintantID_userid"), complainantUserName,
                            dataReader.GetInt32NullAsZero("h2g2id"), dataReader.GetStringNullAsEmpty("subject"),
                            dataReader.GetStringNullAsEmpty("complainttext"))
                            );
                siteEvent.UserId = 0;
                siteEvent.SaveEvent(creator);
            }
            catch(Exception e)
            {
                siteEvent = null;
                SiteEventsProcessor.SiteEventLogger.LogException(e);
            }

            return siteEvent;
        }
예제 #3
0
        static public SiteEvent CreateArticleModerationDecisionActivity(IDnaDataReader dataReader, IDnaDataReaderCreator creator)
        {
            SiteEvent siteEventArticleModerationDecision = null;
            try
            {
                siteEventArticleModerationDecision = new SiteEvent();
                siteEventArticleModerationDecision.SiteId = dataReader.GetInt32NullAsZero("siteid");
                siteEventArticleModerationDecision.Date = new Date(dataReader.GetDateTime("DateCreated"));
            
                var statusId = dataReader.GetInt32NullAsZero("statusid");

                
                switch ((ModerationDecisionStatus)statusId)
                {
                    case ModerationDecisionStatus.Fail:
                        siteEventArticleModerationDecision.Type = SiteActivityType.ModerateArticleFailed;
                        siteEventArticleModerationDecision.ActivityData = XElement.Parse(
                            string.Format(DataFormatFailed, dataReader.GetInt32NullAsZero("h2g2id"),
                            dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                            dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                            dataReader.GetStringNullAsEmpty("ModReason")
                            ));

                        break;


                    case ModerationDecisionStatus.Referred:
                        siteEventArticleModerationDecision.Type = SiteActivityType.ModerateArticleReferred;
                        siteEventArticleModerationDecision.ActivityData = XElement.Parse(
                            string.Format(DataFormatReferred, dataReader.GetInt32NullAsZero("h2g2id"),
                            dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                            dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                            dataReader.GetStringNullAsEmpty("Notes"))
                            );
                        break;

                    default:
                        siteEventArticleModerationDecision = null;
                        break;
                }
                siteEventArticleModerationDecision.UserId = 0;
                siteEventArticleModerationDecision.SaveEvent(creator);
            }
            catch(Exception e)
            {
                siteEventArticleModerationDecision = null;
                SiteEventsProcessor.SiteEventLogger.LogException(e);
            }

            return siteEventArticleModerationDecision;
        }
예제 #4
0
        static public SiteEvent CreateUserModatedEventActivity(IDnaDataReader dataReader, IDnaDataReaderCreator creator)
        {
            SiteEvent siteEvent = null;
            try
            {
                siteEvent = new SiteEvent();
                siteEvent.SiteId = dataReader.GetInt32NullAsZero("siteid");
                siteEvent.Date = new Date(dataReader.GetDateTime("DateCreated"));

                var duration = "";
                var moderationStatus = "";
                switch ((ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("status"))
                {
                    case ModerationStatus.UserStatus.Postmoderated:
                        siteEvent.Type =  SiteActivityType.UserModeratedPostMod;
                        moderationStatus = "postmoderated";
                        break;

                    case ModerationStatus.UserStatus.Premoderated:
                        siteEvent.Type =  SiteActivityType.UserModeratedPremod;
                        moderationStatus = "premoderated";
                        break;

                    case ModerationStatus.UserStatus.Restricted:
                        siteEvent.Type =  SiteActivityType.UserModeratedBanned;
                        moderationStatus = "banned";
                        break;

                     case ModerationStatus.UserStatus.Deactivated:
                        siteEvent.Type =  SiteActivityType.UserModeratedDeactivated;
                        moderationStatus = "deactivated";
                        break;

                     case ModerationStatus.UserStatus.Standard:
                        siteEvent.Type = SiteActivityType.UserModeratedStandard;
                        moderationStatus = "returned to normal";
                        break;

                     case ModerationStatus.UserStatus.Trusted:
                        siteEvent.Type = SiteActivityType.UserModeratedTrusted;
                        moderationStatus = "trusted";
                        break;

                    default:
                        throw new Exception("Unknown moderation status: " + ((ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("status")).ToString());
                }

                switch(dataReader.GetInt32NullAsZero("prefduration"))
                {
                    case 1440: duration = " for 1 day";break;
                    case 10080: duration = " for 1 week";break;
                    case 20160: duration = " for 2 weeks";break;
                    case 40320: duration = " for 1 month";break;
                    default:
                        if (dataReader.GetInt32NullAsZero("prefduration") > 0)
                        {
                            duration = " for " + dataReader.GetInt32NullAsZero("prefduration").ToString() + " hours"; 
                        }
                        break;
                }

                siteEvent.ActivityData = XElement.Parse(
                          string.Format(DataFormat,
                            dataReader.GetInt32NullAsZero("user_userid"), dataReader.GetStringNullAsEmpty("user_username"),
                            dataReader.GetInt32NullAsZero("status"), moderationStatus, dataReader.GetInt32NullAsZero("siteid"),
                            dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                            duration, dataReader.GetStringNullAsEmpty("modreason"))
                           );
                siteEvent.UserId = dataReader.GetInt32NullAsZero("user_userid");

                if (siteEvent != null)
                {
                    siteEvent.SaveEvent(creator);
                }
                
            }
            catch(Exception e)
            {
                siteEvent = null;
                SiteEventsProcessor.SiteEventLogger.LogException(e);
            }

            return siteEvent;
        }
예제 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="siteIds"></param>
        /// <param name="typeIds"></param>
        /// <param name="startIndex"></param>
        /// <param name="itemsPerPage"></param>
        /// <param name="startDate"></param>
        /// <param name="readerCreator"></param>
        /// <returns></returns>
        static public SiteEventList GetSiteEventList(int[] siteIds, int[] typeIds, int startIndex, int itemsPerPage,
            DateTime startDate, DateTime endDate, IDnaDataReaderCreator readerCreator, bool isSuperUser, SiteType siteType)
        {
            var siteEventList = new SiteEventList()
            {
                Sites = siteIds,
                Types = typeIds
            };

            if (siteIds.Length == 0 && !isSuperUser)
            {
                throw new Exception("Missing site list for non-super user");
            }

            var typeIdsDelimited = String.Join("|", typeIds.Select(p => p.ToString()).ToArray());
            var siteIdsDelimited = String.Join("|", siteIds.Select(p => p.ToString()).ToArray());

            using(var reader = readerCreator.CreateDnaDataReader("getsiteevents"))
            {
                reader.AddParameter("itemsperpage", itemsPerPage);
                reader.AddParameter("startindex", startIndex);
                reader.AddParameter("sitetype", siteType);
                if(startDate != DateTime.MinValue)
                {
                    reader.AddParameter("startdate", startDate);
                }
                if(endDate != DateTime.MaxValue)
                {
                    reader.AddParameter("enddate", endDate);
                }
            
                if (siteIds.Length > 0)
                {
                    reader.AddParameter("siteids", siteIdsDelimited);
                }
                if (typeIds.Length > 0)
                {
                    reader.AddParameter("typeids", typeIdsDelimited);
                }

                reader.Execute();

                if (reader.Read())
                {
                    siteEventList.TotalItems = reader.GetInt32NullAsZero("total");
                    siteEventList.StartIndex = reader.GetLongNullAsZero("n")-1;
                    siteEventList.ItemsPerPage = itemsPerPage;
                    if (startDate != DateTime.MinValue)
                    {
                        siteEventList.StartDate = new DateElement(startDate);
                    }
                    if (endDate != DateTime.MaxValue)
                    {
                        siteEventList.EndDate = new DateElement(endDate);
                    }

                    do
                    {
                        var siteEvent = new SiteEvent();
                        try
                        {
                            siteEvent.ActivityData = XElement.Parse(reader.GetXmlAsString("activitydata"));
                            
                        }
                        catch
                        {//skip a badly formatted element
                            continue;
                        }
                        siteEvent.Date = new Date(reader.GetDateTime("datetime"));
                        siteEvent.SiteId = reader.GetInt32NullAsZero("siteid");
                        siteEvent.Type = (SiteActivityType)reader.GetInt32NullAsZero("type");

                        siteEventList.SiteEvents.Add(siteEvent);
                    }
                    while (reader.Read());

                }
            }

            return siteEventList;
        }
예제 #6
0
        static public List<SiteEvent> CreatePostModerationDecisionActivity(IDnaDataReader dataReader, IDnaDataReaderCreator creator)
        {
            List<SiteEvent> siteEventList = new List<SiteEvent>();
            try
            {
                SiteEvent siteEvent1 = null;    
                siteEvent1 = new SiteEvent();
                siteEvent1.SiteId = dataReader.GetInt32NullAsZero("siteid");
                siteEvent1.Date = new Date(dataReader.GetDateTime("DateCreated"));
            
                var statusId = dataReader.GetInt32NullAsZero("status");

                var type = "post";
                if (!string.IsNullOrEmpty(dataReader.GetStringNullAsEmpty("parenturl")))
                {
                    type = "comment";
                }
                
                switch ((ModerationDecisionStatus)statusId)
                {
                    case ModerationDecisionStatus.Fail:
                        siteEvent1.Type = SiteActivityType.ModeratePostFailed;
                        siteEvent1.ActivityData = XElement.Parse(
                          string.Format(DataFormatFailed,
                            dataReader.GetInt32NullAsZero("forumid"), dataReader.GetInt32NullAsZero("postid"),
                            dataReader.GetInt32NullAsZero("threadid"), dataReader.GetStringNullAsEmpty("parenturl"), type,
                            dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                            dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                            dataReader.GetStringNullAsEmpty("ModReason"))
                            );
                        siteEvent1.UserId = dataReader.GetInt32NullAsZero("author_userid");
                        siteEventList.Add(siteEvent1);

                        if (dataReader.GetInt32NullAsZero("complainantid") != 0)
                        {//complaint upheld event
                            var siteEvent2 = new SiteEvent();
                            siteEvent2.SiteId = dataReader.GetInt32NullAsZero("siteid");
                            siteEvent2.Date = new Date(dataReader.GetDateTime("DateCreated"));
                            siteEvent2.Type = SiteActivityType.ComplaintPostUpHeld;
                            siteEvent2.ActivityData = XElement.Parse(
                              string.Format(DataFormatUpHeld,
                                dataReader.GetInt32NullAsZero("forumid"), dataReader.GetInt32NullAsZero("postid"),
                                dataReader.GetInt32NullAsZero("threadid"), dataReader.GetStringNullAsEmpty("parenturl"), type,
                                dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                                dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                                dataReader.GetStringNullAsEmpty("ModReason"))
                                );
                            siteEvent2.UserId = dataReader.GetInt32NullAsZero("complainantid");
                            siteEventList.Add(siteEvent2);
                        }
                        break;


                    case ModerationDecisionStatus.Referred:
                        siteEvent1.Type = SiteActivityType.ModeratePostReferred;
                        siteEvent1.ActivityData = XElement.Parse(
                         string.Format(DataFormatReferred,
                            dataReader.GetInt32NullAsZero("forumid"), dataReader.GetInt32NullAsZero("postid"),
                            dataReader.GetInt32NullAsZero("threadid"), dataReader.GetStringNullAsEmpty("parenturl"), type,
                            dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                            dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                            dataReader.GetStringNullAsEmpty("Notes"))
                           );
                        siteEvent1.UserId = dataReader.GetInt32NullAsZero("author_userid");
                        siteEventList.Add(siteEvent1);
                        break;

                    case ModerationDecisionStatus.Passed:
                        if (dataReader.GetInt32NullAsZero("complainantid") != 0)
                        {//complaint rejected
                            if (dataReader.GetStringNullAsEmpty("complainttext").IndexOf(ComplaintStringPrefix) < 0)
                            {
                                siteEvent1.Type = SiteActivityType.ComplaintPostRejected;
                                siteEvent1.ActivityData = XElement.Parse(
                                 string.Format(DataFormatReject,
                                    dataReader.GetInt32NullAsZero("forumid"), dataReader.GetInt32NullAsZero("postid"),
                                    dataReader.GetInt32NullAsZero("threadid"), dataReader.GetStringNullAsEmpty("parenturl"), type,
                                    dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                                    dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                                    dataReader.GetStringNullAsEmpty("Notes"))
                                   );
                                siteEvent1.UserId = dataReader.GetInt32NullAsZero("complainantid");
                                siteEventList.Add(siteEvent1);
                            }
                            else
                            {//is a reinstate so add that event
                                siteEvent1.Type = SiteActivityType.ModeratePostFailedReversal;
                                siteEvent1.ActivityData = XElement.Parse(string.Format(DataFormatReversed,
                                    dataReader.GetInt32NullAsZero("forumid"), dataReader.GetInt32NullAsZero("postid"),
                                    dataReader.GetInt32NullAsZero("threadid"), dataReader.GetStringNullAsEmpty("parenturl"), type,
                                    dataReader.GetInt32NullAsZero("author_userid"), dataReader.GetStringNullAsEmpty("author_username"),
                                    dataReader.GetInt32NullAsZero("mod_userid"), dataReader.GetStringNullAsEmpty("mod_username"),
                                    dataReader.GetStringNullAsEmpty("Notes"))
                                    );
                                siteEvent1.UserId = dataReader.GetInt32NullAsZero("author_userid");
                                siteEventList.Add(siteEvent1);
                            }
                            
                        }
                        break;
                    default:
                        siteEventList = null;
                        break;
                }

                if (siteEventList != null)
                {
                    foreach (var siteEvent in siteEventList)
                    {
                        siteEvent.SaveEvent(creator);
                    }
                }
            }
            catch(Exception e)
            {
                siteEventList = null;
                SiteEventsProcessor.SiteEventLogger.LogException(e);
            }



            return siteEventList;
        }