Exemple #1
0
        public static ISnesActivity CreateActivity(int activityType, IDnaDataReader currentRow)
        {
            CommentActivity activity;

            if (currentRow.IsDBNull("BlogUrl"))
            {
                activity = PolicyInjection.Create<MessageBoardPostActivity>();
            }
            else
            {
                activity = PolicyInjection.Create<CommentForumActivity>();
            }

            activity.Contents = new OpenSocialActivity();
            activity.ActivityId = currentRow.GetInt32("EventID");
            activity.Application = currentRow.GetString("AppId") ?? "";
            activity.ActivityType = GetActivityTypeVerb(activityType);
            activity.IdentityUserId = currentRow.GetInt32("IdentityUserId");

            activity.SetTitle(currentRow);
            activity.SetObjectTitle(currentRow);
            activity.SetObjectDescription(currentRow);
            activity.SetObjectUri(currentRow);

            activity.Contents.Type = "comment";
            activity.Contents.Body = currentRow.GetString("Body") ?? "";
            activity.Contents.PostedTime = currentRow.GetDateTime("ActivityTime").MillisecondsSinceEpoch();
            activity.Contents.DisplayName = currentRow.GetString("displayName") ?? "";
            activity.Contents.Username = currentRow.GetString("username") ?? "";

            return activity;
        }
        public SnesEventDataReaderAdapter(IDnaDataReader dataReader)
        {
            Rating = dataReader.IsDBNull("Rating") ? null : new RatingDataReaderAdapter(dataReader);
            AppInfo = new AppInfoDataReaderAdapter(dataReader);
            ActivityType = dataReader.GetInt32("ActivityType");
            EventId = dataReader.GetInt32("EventId");
            IdentityUserId = dataReader.GetString("IdentityUserId");
            BlogUrl = dataReader.IsDBNull("BlogUrl") ? null : dataReader.GetString("BlogUrl");

            UrlBuilder = new DnaUrlBuilder
                             {
                                 PostId = dataReader.GetInt32("PostId"),
                                 ForumId = dataReader.GetInt32("ForumId"),
                                 ThreadId = dataReader.GetInt32("ThreadId"),
                                 DnaUrl = dataReader.GetString("DnaUrl")
                             };
        }
        private void AddCommentForumListXML(IDnaDataReader dataReader, XmlNode commentForumList)
        {
            // start creating the comment forum structure
            XmlNode commentForum = CreateElementNode("COMMENTFORUM");
            AddAttribute(commentForum, "UID", dataReader.GetStringNullAsEmpty("uid"));
            AddAttribute(commentForum, "FORUMID", dataReader.GetInt32NullAsZero("forumID").ToString());
            AddAttribute(commentForum, "FORUMPOSTCOUNT", dataReader.GetInt32NullAsZero("forumpostcount").ToString());
            AddAttribute(commentForum, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit"));
            AddAttribute(commentForum, "CANWRITE", dataReader.GetByteNullAsZero("CanWrite").ToString());
            AddAttribute(commentForum, "NOTSIGNEDINUSERID", dataReader.GetInt32NullAsZero("NotSignedInUserID").ToString());

            AddTextTag(commentForum, "HOSTPAGEURL", dataReader.GetStringNullAsEmpty("url"));
            AddTextTag(commentForum, "TITLE", dataReader.GetStringNullAsEmpty("title"));
            AddTextTag(commentForum, "MODSTATUS", dataReader.GetByteNullAsZero("ModerationStatus"));
            AddTextTag(commentForum, "SITEID", dataReader.GetInt32NullAsZero("siteid"));
            AddTextTag(commentForum, "FASTMOD", dataReader.GetInt32NullAsZero("fastmod"));
            AddTextTag(commentForum, "CONTACTEMAIL", dataReader.GetStringNullAsEmpty("encryptedcontactemail"));

            if (dataReader.DoesFieldExist("DateCreated") && !dataReader.IsDBNull("DateCreated"))
            {
                DateTime dateCreated = dataReader.GetDateTime("DateCreated");
                AddElement(commentForum, "DATECREATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateCreated));
            }

            if (dataReader.DoesFieldExist("ForumCloseDate") && !dataReader.IsDBNull("ForumCloseDate"))
            {
                DateTime closeDate = dataReader.GetDateTime("ForumCloseDate");
                AddElement(commentForum, "CLOSEDATE", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, closeDate));
            }

            if (dataReader.DoesFieldExist("LastUpdated") && !dataReader.IsDBNull("LastUpdated"))
            {
                DateTime dateLastUpdated = dataReader.GetDateTime("LastUpdated");
                AddElement(commentForum, "LASTUPDATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateLastUpdated));
            }

            int forumId = dataReader.GetInt32NullAsZero("forumID");
 
            AddXmlTextTag(commentForum, "TERMS", "");

            commentForumList.AppendChild(commentForum);
        }
Exemple #4
0
        /// <summary>
        /// This method creates the crumbtrail for a given item
        /// </summary>
        /// <param name="reader">The DnaDataReader that contains the crumbtrail result set.</param>
        static public CrumbTrails GetCrumbtrailForItem(IDnaDataReader reader)
        {
            CrumbTrails crumbTrialList = new CrumbTrails();
            bool startOfTrail = true;
            CrumbTrail crumbTrail = null;
            while (reader.Read())
            {
                // Check to see if we're at the top level
                int treeLevel = reader.GetInt32("TreeLevel");
                if (treeLevel == 0)
                {
                    startOfTrail = true;
                }

                // Check to see if we're starting a new trail
                if (startOfTrail)
                {
                    if (crumbTrail != null)
                    {//add the previous to the list
                        crumbTrialList.CrumbTrail.Add(crumbTrail);
                    }
                    //start new
                    crumbTrail = new CrumbTrail();
                    startOfTrail = false;
                }

                CrumbTrailAncestor ancestor = new CrumbTrailAncestor();
                ancestor.Name = reader.GetString("DisplayName");
                ancestor.NodeId = reader.GetInt32("NodeID");
                ancestor.TreeLevel = treeLevel;
                ancestor.NodeType = reader.GetInt32("Type");
                if (reader.Exists("RedirectNodeID") && !reader.IsDBNull("RedirectNodeID"))
                {
                    ancestor.RedirectNode = new CrumbTrialAncestorRedirect();
                    ancestor.RedirectNode.id = reader.GetInt32("RedirectNodeID");
                    ancestor.RedirectNode.value = reader.GetString("RedirectNodeName");
                }
                crumbTrail.Ancestor.Add(ancestor);
            }
            if (crumbTrail != null)
            {//add the previous to the list
                crumbTrialList.CrumbTrail.Add(crumbTrail);
            }
            return crumbTrialList;
        }
Exemple #5
0
        /// <summary>
        /// Creates and adds the returned User Xml block to a given parent post node from the passed user parameters with a prefix
        /// ie the field name of OwnerUserName, OwnerFirstNames
        /// </summary>
        /// <param name="dataReader">Data reader object</param>
        /// <param name="userID">The users id</param>
        /// <param name="prefix">The prefix of the field names for a different user in the same result set</param>
        /// <param name="parent">The parent Node to add the user xml to</param>
        /// <returns>XmlNode Containing user XML from the stored procedure</returns>
        public void AddPrefixedUserXMLBlock(IDnaDataReader dataReader, int userID, string prefix, XmlNode parent)
        {
            string userName = "";
            if (dataReader.Exists(prefix + "UserName"))
            {
                userName = dataReader.GetStringNullAsEmpty(prefix + "UserName");
            }
            else if (dataReader.Exists(prefix + "Name"))
            {
                userName = dataReader.GetStringNullAsEmpty(prefix + "Name");
            }

            if (userName == String.Empty)
            {
                userName = "******" + userID.ToString();
            }

            string identityUserId = "";
            if (dataReader.Exists(prefix + "identityUserId"))
            {
                identityUserId = dataReader.GetStringNullAsEmpty(prefix + "identityUserId");
            }

            string emailAddress = "";
            if (dataReader.Exists(prefix + "Email"))
            {
                emailAddress = dataReader.GetStringNullAsEmpty(prefix + "Email");
            }

            double zeigeistScore = 0.0;
            if (dataReader.DoesFieldExist(prefix + "ZeitgeistScore"))
            {
                zeigeistScore = dataReader.GetDoubleNullAsZero(prefix + "ZeitgeistScore");
            }

            string siteSuffix = "";
            if (dataReader.Exists(prefix + "SiteSuffix"))
            {
                siteSuffix = dataReader.GetStringNullAsEmpty(prefix + "SiteSuffix");
            }

            string area = "";
            if (dataReader.Exists(prefix + "Area"))
            {
                area = dataReader.GetStringNullAsEmpty(prefix + "Area");
            }

            string title = "";
            if (dataReader.Exists(prefix + "Title"))
            {
                title = dataReader.GetStringNullAsEmpty(prefix + "Title");
            }

            int subQuota = 0;
            if (dataReader.Exists(prefix + "SubQuota"))
            {
                subQuota = dataReader.GetInt32NullAsZero(prefix + "SubQuota");
            }

            int allocations = 0;
            if (dataReader.Exists(prefix + "Allocations"))
            {
                allocations = dataReader.GetInt32NullAsZero(prefix + "Allocations");
            }
            

            int journal = 0;
            if (dataReader.Exists(prefix + "Journal"))
            {
                journal = dataReader.GetInt32NullAsZero(prefix + "Journal");
            }

            bool isActive = false;
            if (dataReader.Exists(prefix + "Active") && !dataReader.IsDBNull(prefix + "Active"))
            {
                isActive = dataReader.GetBoolean(prefix + "Active");
            }

            DateTime dateLastNotified = DateTime.MinValue;
            if (dataReader.Exists(prefix + "DateLastNotified") && dataReader.GetValue(prefix + "DateLastNotified") != DBNull.Value)
            {
                dateLastNotified = dataReader.GetDateTime(prefix + "DateLastNotified");
            }

            DateTime dateJoined = DateTime.MinValue;
            if (dataReader.Exists(prefix + "DateJoined") && dataReader.GetValue(prefix + "DateJoined") != DBNull.Value)
            {
                dateJoined = dataReader.GetDateTime(prefix + "DateJoined");
            }
            int forumPostedTo = -1;
            if (dataReader.Exists(prefix + "ForumPostedTo"))
            {
                forumPostedTo = dataReader.GetInt32NullAsZero(prefix + "ForumPostedTo");
            }
            int masthead = -1;
            if (dataReader.Exists(prefix + "Masthead"))
            {
                masthead = dataReader.GetInt32NullAsZero(prefix + "Masthead");
            }
            int sinbin = -1;
            if (dataReader.Exists(prefix + "SinBin"))
            {
                sinbin = dataReader.GetInt32NullAsZero(prefix + "SinBin");
            }
            int forumID = -1;
            if (dataReader.Exists(prefix + "ForumID"))
            {
                forumID = dataReader.GetInt32NullAsZero(prefix + "ForumID");
            }

            XmlNode userXML = GenerateUserXml(userID,
                                                userName,
                                                emailAddress,
                                                dataReader.GetStringNullAsEmpty(prefix + "FirstNames"),
                                                dataReader.GetStringNullAsEmpty(prefix + "LastName"),
                                                dataReader.GetInt32NullAsZero(prefix + "Status"),
                                                dataReader.GetInt32NullAsZero(prefix + "TaxonomyNode"),
                                                isActive,
                                                zeigeistScore,
                                                siteSuffix,
                                                area,
                                                title,
                                                journal,
                                                dateLastNotified,
                                                subQuota, 
                                                allocations,
                                                dateJoined,
                                                forumID,
                                                forumPostedTo,
                                                masthead,
                                                sinbin,
                                                identityUserId);


            if (userXML != null)
            {
                XmlNode importxml = parent.OwnerDocument.ImportNode(userXML, true);
                parent.AppendChild(importxml);
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates a commentinfo object
        /// </summary>
        /// <param name="reader">A reader with all information</param>
        /// <param name="site">site information</param>
        /// <returns>Comment info object</returns>
        private CommentInfo CommentCreateFromReader(IDnaDataReader reader, ISite site)
        {
            var commentInfo = new CommentInfo
                                  {
                                      Created =
                                          new DateTimeHelper(DateTime.Parse(reader.GetDateTime("Created").ToString())),
                                      User = UserReadById(reader, site),
                                      ID = reader.GetInt32NullAsZero("id")
                                  };

            commentInfo.hidden = (CommentStatus.Hidden) reader.GetInt32NullAsZero("hidden");
            if (reader.IsDBNull("poststyle"))
            {
                commentInfo.PostStyle = PostStyle.Style.richtext;
            }
            else
            {
                commentInfo.PostStyle = (PostStyle.Style) reader.GetTinyIntAsInt("poststyle");
            }

            commentInfo.IsEditorPick = reader.GetBoolean("IsEditorPick");
            commentInfo.Index = reader.GetInt32NullAsZero("PostIndex");

            //get complainant
            var replacement = new Dictionary<string, string>();
            replacement.Add("sitename", site.SiteName);
            replacement.Add("postid", commentInfo.ID.ToString());
            commentInfo.ComplaintUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                SiteList.GetSiteOptionValueString(site.SiteID, "General", "ComplaintUrl"),
                                                                                replacement);

            replacement = new Dictionary<string, string>();
            replacement.Add("commentforumid", reader.GetString("forumuid"));
            replacement.Add("sitename", site.SiteName);
            commentInfo.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.CommentForumById,
                                                                            replacement);

            replacement = new Dictionary<string, string>();
            replacement.Add("parentUri", reader.GetString("parentUri"));
            replacement.Add("postid", commentInfo.ID.ToString());
            commentInfo.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.Comment,
                                                                       replacement);

            if(reader.DoesFieldExist("nerovalue"))
            {
                commentInfo.NeroRatingValue = reader.GetInt32NullAsZero("nerovalue");
            }

            if (reader.DoesFieldExist("neropositivevalue"))
            {
                commentInfo.NeroPositiveRatingValue = reader.GetInt32NullAsZero("neropositivevalue");
            }

            if (reader.DoesFieldExist("neronegativevalue"))
            {
                commentInfo.NeroNegativeRatingValue = reader.GetInt32NullAsZero("neronegativevalue");
            }
            
            if (reader.DoesFieldExist("tweetid"))
            {
                commentInfo.TweetId = reader.GetLongNullAsZero("tweetid");
            }

            commentInfo.text = CommentInfo.FormatComment(reader.GetStringNullAsEmpty("text"), commentInfo.PostStyle, commentInfo.hidden, commentInfo.User.Editor);

            if (reader.DoesFieldExist("twitterscreenname"))
            {
                commentInfo.TwitterScreenName = reader.GetStringNullAsEmpty("twitterscreenname");
            }

            if (reader.DoesFieldExist("retweetid"))
            {
                commentInfo.RetweetId = reader.GetLongNullAsZero("retweetid");
            }

            if (reader.DoesFieldExist("retweetedby"))
            {
                commentInfo.RetweetedBy = reader.GetStringNullAsEmpty("retweetedby");
            }

            if (reader.DoesFieldExist("DmID"))
            {
                if (reader.IsDBNull("DmID") == false)
                {
                    commentInfo.DistressMessage = IncludeDistressMessage(reader, site);
                }
            }

            return commentInfo;
        }
Exemple #7
0
        /// <summary>
        /// Creates user object from given reader and user id
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        static public User CreateUserFromReader(IDnaDataReader reader, string prefix)
        {

            //IUser user = new User(_dnaDataReaderCreator, _dnaDiagnostics, _cacheManager);
            IUser user = new User();

            if (reader.Exists(prefix + "userID"))
            {
                user.UserId = reader.GetInt32NullAsZero(prefix  + "userID");
            }
            else if (reader.Exists(prefix + "ID"))
            {
                user.UserId = reader.GetInt32NullAsZero(prefix + "ID");
            }

            if (reader.Exists(prefix + "IdentityUserID"))
            {
                user.IdentityUserId = reader.GetStringNullAsEmpty(prefix + "IdentityUserId");
            }

            if (reader.Exists(prefix + "IdentityUserName"))
            {
                user.IdentityUserName = reader.GetStringNullAsEmpty(prefix + "IdentityUserName");
            }
            else if (reader.Exists(prefix + "LoginName"))
            {
                user.IdentityUserName = reader.GetStringNullAsEmpty(prefix + "LoginName");
            }

            /*
            if (reader.Exists(prefix + "FirstNames"))
            {

                user.FirstNames = reader.GetStringNullAsEmpty(prefix + "FirstNames") ?? "";
            }

            if(reader.Exists(prefix + "LastName"))
            {

                user.LastName = reader.GetStringNullAsEmpty(prefix + "LastName") ?? "";
            }
            */
            if(reader.Exists(prefix + "Status"))
            {
                
                user.Status= reader.GetInt32NullAsZero(prefix + "Status");
            }

            if(reader.Exists(prefix + "TaxonomyNode"))
            {
                
                user.TaxonomyNode= reader.GetInt32NullAsZero(prefix + "TaxonomyNode");
            }
            if (reader.Exists(prefix + "UserName"))
            {
                user.UserName = reader.GetStringNullAsEmpty(prefix + "UserName") ?? "";
            }
            else if (reader.Exists(prefix + "Name"))
            {
                user.UserName = reader.GetStringNullAsEmpty(prefix + "Name") ?? "";
            }

            if (user.UserName == String.Empty)
            {
                user.UserName = "******" + user.UserId.ToString();
            }
            /* NO NO not emails
             * if (reader.Exists(prefix + "Email"))
            {
                user.Email = reader.GetStringNullAsEmpty(prefix + "Email") ?? "";
            }
             */
            
            if (reader.Exists(prefix + "SiteSuffix"))
            {
                user.SiteSuffix = reader.GetStringNullAsEmpty(prefix + "SiteSuffix") ?? "";
            }
            if (reader.Exists(prefix + "Area"))
            {
                user.Area = reader.GetStringNullAsEmpty(prefix + "Area") ?? "";
            }
            if (reader.Exists(prefix + "Title"))
            {
                user.Title = reader.GetStringNullAsEmpty(prefix + "Title") ?? "";
            }
            if (reader.Exists(prefix + "SubQuota"))
            {
                user.SubQuota = reader.GetInt32NullAsZero(prefix + "SubQuota");
            }
            if (reader.Exists(prefix + "Allocations"))
            {
                user.Allocations = reader.GetInt32NullAsZero(prefix + "Allocations");
            }
            if (reader.Exists(prefix + "Journal"))
            {
                user.Journal = reader.GetInt32NullAsZero(prefix + "Journal");
            }
            if (reader.Exists(prefix + "Active") && !reader.IsDBNull(prefix + "Active"))
            {
                user.Active = reader.GetBoolean(prefix + "Active");
            }
            if (reader.Exists(prefix + "DateLastNotified") && reader.GetValue(prefix + "DateLastNotified") != DBNull.Value)
            {
                user.DateLastNotified = new DateElement(reader.GetDateTime(prefix + "DateLastNotified"));
            }
            if (reader.Exists(prefix + "DateJoined") && reader.GetValue(prefix + "DateJoined") != DBNull.Value)
            {
                user.DateJoined = new DateElement(reader.GetDateTime(prefix + "DateJoined"));
            }
            if (reader.Exists(prefix + "ForumPostedTo"))
            {
                user.ForumPostedTo = reader.GetInt32NullAsZero(prefix + "ForumPostedTo");
            }
            if (reader.Exists(prefix + "Masthead"))
            {
                user.MastHead = reader.GetInt32NullAsZero(prefix + "Masthead");
            }
            if (reader.Exists(prefix + "SinBin"))
            {
                user.SinBin = reader.GetInt32NullAsZero(prefix + "SinBin");
            }
            if (reader.Exists(prefix + "ForumID"))
            {
                user.ForumId = reader.GetInt32NullAsZero(prefix + "ForumID");
            }
            var siteId = 0;
            if (reader.Exists("SiteID"))
            {
                siteId = reader.GetInt32NullAsZero("SiteID");
            }
            
            
            if (siteId != 0 && user.UserId != 0)
            {
                var userGroups = (UserGroups)SignalHelper.GetObject(typeof(UserGroups));
                var groupList = userGroups.GetUsersGroupsForSite(user.UserId, siteId);
                foreach (var group in groupList)
                {
                    user.Groups.Add(new Group(){Name = group.Name.ToUpper()});
                }
            }
            else
            {

            }
             

            return (User)user;
        
        }
        /// <summary>
        /// Generates the individual Comment CommentBoxForum Xml within the Comment CommentBoxForum List xml page
        /// </summary>
        /// <param name="dataReader">SP containing the comment forums</param>
        /// <param name="commentForumList">Parent node to attach to</param>
        private void AddCommentForumListXML(IDnaDataReader dataReader, XmlNode commentForumList)
        {
            // start creating the comment forum structure
            XmlNode commentForum = CreateElementNode("COMMENTFORUM");
            AddAttribute(commentForum, "UID", dataReader.GetStringNullAsEmpty("uid"));
            AddAttribute(commentForum, "FORUMID", dataReader.GetInt32NullAsZero("forumID").ToString());
            AddAttribute(commentForum, "FORUMPOSTCOUNT", dataReader.GetInt32NullAsZero("forumpostcount").ToString());
            AddAttribute(commentForum, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit"));
            AddAttribute(commentForum, "CANWRITE", dataReader.GetByteNullAsZero("CanWrite").ToString());
            AddAttribute(commentForum, "NOTSIGNEDINUSERID", dataReader.GetInt32NullAsZero("NotSignedInUserID").ToString());

            AddTextTag(commentForum, "HOSTPAGEURL", dataReader.GetStringNullAsEmpty("url"));
            AddTextTag(commentForum, "TITLE", dataReader.GetStringNullAsEmpty("title"));
            AddTextTag(commentForum, "MODSTATUS", dataReader.GetByteNullAsZero("ModerationStatus"));
            AddTextTag(commentForum, "SITEID", dataReader.GetInt32NullAsZero("siteid"));
            AddTextTag(commentForum, "FASTMOD", dataReader.GetInt32NullAsZero("fastmod"));

            if (dataReader.DoesFieldExist("DateCreated") && !dataReader.IsDBNull("DateCreated"))
            {
                DateTime dateCreated = dataReader.GetDateTime("DateCreated");
                AddElement(commentForum, "DATECREATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateCreated));
            }

            if (dataReader.DoesFieldExist("ForumCloseDate") && !dataReader.IsDBNull("ForumCloseDate"))
            {
                DateTime closeDate = dataReader.GetDateTime("ForumCloseDate");
                AddElement(commentForum, "CLOSEDATE", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, closeDate));
            }

            if (dataReader.DoesFieldExist("LastUpdated") && !dataReader.IsDBNull("LastUpdated"))
            {
                DateTime dateLastUpdated = dataReader.GetDateTime("LastUpdated");
                AddElement(commentForum, "LASTUPDATED", DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, dateLastUpdated));
            }

            int forumId = dataReader.GetInt32NullAsZero("forumID");
            //get terms admin object
            TermsFilterAdmin termsAdmin = TermsFilterAdmin.CreateForumTermAdmin(InputContext.CreateDnaDataReaderCreator(), _cache, forumId);
            XmlDocument termNodeDoc = SerialiseToXmlDoc(termsAdmin);
            string termNodeText = termNodeDoc.DocumentElement.InnerXml.ToString();
            AddXmlTextTag(commentForum, "TERMS", termNodeText);

            commentForumList.AppendChild(commentForum);
        }
Exemple #9
0
 void TestNullableStringField(IDnaDataReader reader, string fieldName, string expected)
 {
     if (reader.IsDBNull(fieldName))
         Assert.IsNull(expected);
     else
         Assert.AreEqual(expected, reader.GetString(fieldName));
 }
Exemple #10
0
        /// <summary>
        /// CreateLinkXML from a dataReader.
        /// Allows standard Link XML to be generated from different resultsets.
        /// </summary>
        /// <param name="dataReader"></param>
        /// <param name="parent"></param>
        /// <param name="createAuthorXML"></param>
        /// <param name="createSubmitterXML"></param>
        /// <returns></returns>
        public void CreateLinkXML(IDnaDataReader dataReader, XmlNode parent, bool createSubmitterXML, bool createAuthorXML )
        {
            RootElement.RemoveAll();
            String type = dataReader.GetStringNullAsEmpty("destinationtype");
            XmlNode link = CreateElementNode("LINK");
            AddAttribute(link, "TYPE", type);
            AddAttribute(link, "LINKID", dataReader.GetInt32NullAsZero("linkid"));
            AddAttribute(link, "TEAMID", dataReader.GetInt32NullAsZero("teamid"));
            AddAttribute(link, "RELATIONSHIP", dataReader.GetStringNullAsEmpty("relationship"));
            AddAttribute(link, "PRIVATE", dataReader.GetTinyIntAsInt("private"));

            //Create appropriate URL from link type. 
            int destinationId = dataReader.GetInt32NullAsZero("DestinationID");
            switch (type)
            {
                case "article"  :
                {
                    AddAttribute(link, "DNAUID", "A" + destinationId );
                    break;
                }
                case "userpage" :
                {
                    AddAttribute(link, "DNAUID", "U" + destinationId);
                    break;
                }
                case "category" :
                {
                    AddAttribute(link, "DNAUID", "C" + destinationId);
                    break;
                }
                case "forum" :
                {
                    AddAttribute(link, "DNAUID", "F" + destinationId);
                    break;
                }
                case "thread" :
                {
                     AddAttribute(link, "DNAUID", "T" + destinationId);
                    break;
                }
                case "posting" :
                {
                    AddAttribute(link, "DNAUID", "TP" + destinationId);
                    break;
                }
                default : // "club" )
                {
                    AddAttribute(link, "DNAUID", "G" + destinationId);
                    break;
                }
            }

            //AddTextTag(link, "TITLE", dataReader.GetStringNullAsEmpty("title"));
            AddTextTag(link, "DESCRIPTION", dataReader.GetStringNullAsEmpty("linkdescription"));
            
            //Create Submitter XML if required .
            if ( createSubmitterXML )
            {
                int submitterId = dataReader.GetInt32NullAsZero("submitterid");
                if (submitterId > 0)
                {
                    XmlNode submitterXML = AddElementTag(link, "SUBMITTER");
                    User submitter = new User(InputContext);
                    submitter.AddPrefixedUserXMLBlock(dataReader, submitterId, "submitter", submitterXML);
                }
            }

            //Create author XML if required.
            if (createAuthorXML)
            {
                int authorId = dataReader.GetInt32NullAsZero("authorid");
                if (authorId > 0)
                {
                    XmlNode authorXML = AddElementTag(link, "AUTHOR");
                    User author = new User(InputContext);
                    author.AddPrefixedUserXMLBlock(dataReader, authorId, "author", authorXML);
                }
            }

            if (!dataReader.IsDBNull("datelinked"))
                AddDateXml(dataReader.GetDateTime("datelinked"),link,"DATELINKED");
            if ( !dataReader.IsDBNull("lastupdated") )
                AddDateXml(dataReader.GetDateTime("lastupdated"),link,"LASTUPDATED");

            XmlNode importXml = parent.OwnerDocument.ImportNode(link, true);
            parent.AppendChild(importXml);
        }
Exemple #11
0
        private void GetGroupedLinks(IDnaDataReader dataReader, XmlElement parent, int show)
        {
            string currentGroup = String.Empty;
            string newGroup = String.Empty;
            int count = show;
            bool groupOpen = false;
            XmlElement group = null;
            do
            {
                newGroup = dataReader.GetStringNullAsEmpty("Type");
                if (newGroup != currentGroup)
                {
                    groupOpen = false;
                }
                if (!groupOpen)
                {
                    groupOpen = true;
                    currentGroup = dataReader.GetStringNullAsEmpty("Type");

                    group = AddElementTag(parent, "GROUP");
                    AddAttribute(group, "CURRENT", dataReader.GetInt32NullAsZero("selected"));
                    AddTextTag(group, "NAME", currentGroup);
                }

	            string type = dataReader.GetStringNullAsEmpty("DestinationType");
	            int objectID = dataReader.GetInt32NullAsZero("DestinationID");

                XmlElement link = AddElementTag(group, "LINK");
                AddAttribute(link, "TYPE", type);
                AddAttribute(link, "LINKID", dataReader.GetInt32NullAsZero("linkID"));
                AddAttribute(link, "TEAMID", dataReader.GetInt32NullAsZero("TeamID"));
                AddAttribute(link, "RELATIONSHIP", StringUtils.EscapeAllXmlForAttribute(dataReader.GetStringNullAsEmpty("Relationship")));

                switch (type)
                {
                    case "article" :
	                {
		                AddAttribute(link, "DNAID", "A" + objectID.ToString());
                        break;
	                }
	                case "userpage" : 
	                {
		                AddAttribute(link, "BIO", "U" + objectID.ToString());
                        break;
	                }
	                case "category" : 
	                {
		                AddAttribute(link, "DNAID", "C" + objectID.ToString());
                        break;
	                }
	                case "forum" : 
	                {
		                AddAttribute(link, "DNAID", "F" + objectID.ToString());
                        break;
	                }
	                case "thread" : 
	                {
		                AddAttribute(link, "DNAID", "T" + objectID.ToString());
                        break;
	                }
	                case "posting" : 
	                {
		                AddAttribute(link, "DNAID", "TP" + objectID.ToString());
                        break;
	                }
	                case "club" :
	                {
		                AddAttribute(link, "DNAID", "G" + objectID.ToString());
                        break;
	                }
                    default : // "external" : 
	                {
                        AddAttribute(link, "URL", StringUtils.EscapeAllXmlForAttribute(dataReader.GetStringNullAsEmpty("URL")));
                        break;
	                }
                }
                AddAttribute(link, "PRIVATE", dataReader.GetTinyIntAsInt("Private"));

                AddTextTag(link, "TITLE", dataReader.GetStringNullAsEmpty("Title"));
                AddTextTag(link, "DESCRIPTION", dataReader.GetStringNullAsEmpty("LinkDescription"));


	            // Submitter, if we have one
	            if(dataReader.DoesFieldExist("SubmitterID"))
	            {
                    int submitterID = dataReader.GetInt32NullAsZero("SubmitterID");
                    XmlElement submitterTag = AddElementTag(link, "SUBMITTER");
                    AddIntElement(submitterTag, "USERID", submitterID);
                    //TODO Add all Submitter User fields to SP
                    //User submitter = new User(InputContext);
                    //submitter.AddPrefixedUserXMLBlock(dataReader, submitterID, "Submitter", submitterTag);
	            }
        			
                /*
	            //add information about a team which added the link:
	            CTeam team(m_InputContext);
	            if (team.GetAllTeamMembers(iTeamID))
	            {
		            CTDVString sTeam;
		            team.GetAsString(sTeam);
		            sXML << sTeam;
	            }
                */

	            // Add author block if we have one
                if (dataReader.DoesFieldExist("AuthorID"))
                {
                    int authorID = dataReader.GetInt32NullAsZero("AuthorID");
                    XmlElement authorTag = AddElementTag(link, "AUTHOR");
                    AddIntElement(authorTag, "USERID", authorID);
                    //TODO Add all Author User fields to SP
                    //User author = new User(InputContext);
                    //author.AddPrefixedUserXMLBlock(dataReader, authorID, "Author", authorTag);
                }

                // Add LastUpdated
                if (dataReader.DoesFieldExist("LastUpdated") && !dataReader.IsDBNull("LastUpdated"))
                {
                    AddDateXml(dataReader, link, "LastUpdated", "LASTUPDATED");
                }
                count--;

            } while (dataReader.Read() && count > 0);
        }
Exemple #12
0
        private void ReadTopDateRangeRecord(IDnaDataReader dataReader, ref DateRangeInfo drInfo)
        {
            dataReader.ExecuteDEBUGONLY("select top 1 * from articledaterange order by entryid desc");

            if (dataReader.Read())
            {
                drInfo.entryId= dataReader.GetInt32("EntryID");
                drInfo.startDate = dataReader.GetDateTime("StartDate");
                drInfo.endDate = dataReader.GetDateTime("EndDate");
                drInfo.timeIntervalNull = dataReader.IsDBNull("TimeInterval");
                if (!drInfo.timeIntervalNull)
                {
                    drInfo.timeInterval = dataReader.GetInt32("TimeInterval");
                }
            }
            else
            {
                Assert.Fail("Unable to read the ArticleDateRange table");
            }
        }
        private void GenerateAltIdentitiesXml(IDnaDataReader dataReader, XmlNode parentXml)
        {
            int postPassedCount = 0;
            int postFailedCount = 0;
            int postTotalCount = 0;
            int articlePassedCount = 0;
            int articleFailedCount = 0;
            int articleTotalCount = 0;

             // Add Result Data .
            while (dataReader.Read())
            {
                XmlNode memberXml = AddElementTag(parentXml,"MEMBERDETAILS");

                //AddUser XML
                XmlNode userXml = AddElementTag(memberXml, "USER");
                AddIntElement(userXml,"USERID", dataReader.GetInt32NullAsZero("userid"));
                AddTextTag(userXml, "USERNAME", dataReader.GetStringNullAsEmpty("username"));
                AddTextTag(userXml, "LOGINNAME", dataReader.GetStringNullAsEmpty("loginname"));
                AddTextTag(userXml, "EMAIL", dataReader.GetStringNullAsEmpty("email"));
                XmlNode statusXml = AddElementTag(userXml, "STATUS");
                AddAttribute(statusXml, "STATUSID", dataReader.GetInt32NullAsZero("prefstatus"));
                AddIntElement(userXml, "ACTIVE", Convert.ToInt32(dataReader.GetBoolean("active")));

                //Add Site XML.
                int siteId = dataReader.GetInt32NullAsZero("siteid");
                ISite site = InputContext.TheSiteList.GetSite(siteId);
                SiteXmlBuilder siteXmlBuilder = new SiteXmlBuilder(InputContext);
                XmlNode siteXML = siteXmlBuilder.GenerateXml(null, site);
                siteXML = ImportNode(siteXML);
                memberXml.AppendChild(siteXML);

                if (!dataReader.IsDBNull("datejoined"))
                {
                    AddDateXml(dataReader.GetDateTime("datejoined"), memberXml, "DATEJOINED");
                }
                
                //Add Stats XML
                AddIntElement(memberXml, "POSTPASSEDCOUNT", dataReader.GetInt32NullAsZero("postpassedcount"));
                AddIntElement(memberXml, "POSTFAILEDCOUNT", dataReader.GetInt32NullAsZero("postfailedcount"));
                AddIntElement(memberXml, "POSTTOTALCOUNT", dataReader.GetInt32NullAsZero("totalpostcount"));
                AddIntElement(memberXml, "ARTICLEPASSEDCOUNT", dataReader.GetInt32NullAsZero("articlepassedcount"));
                AddIntElement(memberXml, "ARTICLEFAILEDCOUNT", dataReader.GetInt32NullAsZero("articlefailedcount"));
                AddIntElement(memberXml, "ARTICLETOTALCOUNT", dataReader.GetInt32NullAsZero("totalarticlecount"));

                postPassedCount += dataReader.GetInt32NullAsZero("postpassedcount");
                postFailedCount += dataReader.GetInt32NullAsZero("postfailedcount");
                postTotalCount += dataReader.GetInt32NullAsZero("totalpostcount");
                articlePassedCount += dataReader.GetInt32NullAsZero("articlepassedcount");
                articleFailedCount += dataReader.GetInt32NullAsZero("articlefailedcount");
                articleTotalCount += dataReader.GetInt32NullAsZero("totalarticlecount");
            }

            //Add Member Details Summary XML
            XmlNode summaryXml = AddElementTag(parentXml, "SUMMARY");
            AddIntElement(summaryXml, "POSTPASSEDCOUNT", postPassedCount);
            AddIntElement(summaryXml, "POSTFAILEDCOUNT", postFailedCount);
            AddIntElement(summaryXml, "POSTTOTALCOUNT", postTotalCount);
            AddIntElement(summaryXml, "ARTICLEPASSEDCOUNT", articlePassedCount);
            AddIntElement(summaryXml,"ARTICLEFAILEDCOUNT",articleFailedCount);
            AddIntElement(summaryXml, "ARTICLETOTALCOUNT", articleTotalCount);
        }
Exemple #14
0
        /// <summary>
        /// Helper method to create the list after a specific stored procedure
		///		has been called to return an appropriate results set.
        /// </summary>
        /// <param name="articleList"></param>
        /// <param name="dataReader"></param>
        /// <param name="skip">Number of Articles to skip</param>
        /// <param name="show">Number of Articles to show</param>
        /// <returns></returns>
        public int CreateList(XmlElement articleList, IDnaDataReader dataReader, int skip, int show)
        {
            int count = show;
            bool records = true;

            //Read/skip over the skip number of rows so that the row that the first row that in the do below is 
            //the one required
            for (int i = 0; i < skip; i++)
            {
                records = dataReader.Read();
                if (!records)
                {
                    break;
                }
            }

            if (records)
            {
                do
                {
                    // Setup the article
                    XmlElement article = AddElementTag(articleList, "ARTICLE");

                    if (dataReader.DoesFieldExist("EntryID"))
                    {
                        AddIntElement(article, "ENTRY-ID", dataReader.GetInt32NullAsZero("EntryID"));
                    }
                    if (dataReader.DoesFieldExist("h2g2ID"))
                    {
                        AddAttribute(article, "H2G2ID", dataReader.GetInt32NullAsZero("h2g2ID"));
                        //TODO: remove the H2G2-ID from all schemas and skins...
                        AddIntElement(article, "H2G2-ID", dataReader.GetInt32NullAsZero("h2g2ID"));
                    }
                    if (dataReader.DoesFieldExist("SiteID"))
                    {
                        AddIntElement(article, "SITEID", dataReader.GetInt32NullAsZero("SiteID"));
                    }
                    if (dataReader.DoesFieldExist("RecommendationID"))
                    {
                        AddIntElement(article, "RECOMMENDATION-ID", dataReader.GetInt32NullAsZero("RecommendationID"));
                    }
                    if (dataReader.DoesFieldExist("NotificationSent"))
                    {
                        AddIntElement(article, "NOTIFIED", dataReader.GetBoolean("NotificationSent") ? 1 : 0);
                    }

                    User user = new User(InputContext);
                    if (dataReader.DoesFieldExist("Editor"))
                    {
                        // place all user details within a USER tag and structure them appropriately
                        // editor info
                        int editorID = dataReader.GetInt32NullAsZero("Editor");
                        XmlElement editorTag = AddElementTag(article, "EDITOR");
                        user.AddPrefixedUserXMLBlock(dataReader, editorID, "Editor", editorTag);
                    }

                    if (dataReader.DoesFieldExist("AuthorID"))
                    {
                        // author info
                        int authorID = dataReader.GetInt32NullAsZero("AuthorID");
                        XmlElement authorTag = AddElementTag(article, "AUTHOR");
                        user.AddPrefixedUserXMLBlock(dataReader, authorID, "Author", authorTag);
                    }

                    if (dataReader.DoesFieldExist("AcceptorID"))
                    {
                        // acceptor info (user that accepted a recommendation)
                        int acceptorID = dataReader.GetInt32NullAsZero("AcceptorID");
                        XmlElement acceptorTag = AddElementTag(article, "ACCEPTOR");
                        user.AddPrefixedUserXMLBlock(dataReader, acceptorID, "Acceptor", acceptorTag);
                    }

                    if (dataReader.DoesFieldExist("AllocatorID"))
                    {
                        // allocator info (user that allocated a recommendation to a sub)
                        int allocatorID = dataReader.GetInt32NullAsZero("AllocatorID");
                        XmlElement allocatorTag = AddElementTag(article, "ALLOCATOR");
                        user.AddPrefixedUserXMLBlock(dataReader, allocatorID, "Allocator", allocatorTag);
                    }

                    if (dataReader.DoesFieldExist("ScoutID"))
                    {
                        // scout info
                        int scoutID = dataReader.GetInt32NullAsZero("ScoutID");
                        XmlElement scoutTag = AddElementTag(article, "SCOUT");
                        user.AddPrefixedUserXMLBlock(dataReader, scoutID, "Scout", scoutTag);
                    }

                    if (dataReader.DoesFieldExist("SubEditorID"))
                    {
                        // sub editor info
                        int subEditorID = dataReader.GetInt32NullAsZero("SubEditorID");
                        XmlElement subEditorTag = AddElementTag(article, "SUBEDITOR");
                        user.AddPrefixedUserXMLBlock(dataReader, subEditorID, "SubEditor", subEditorTag);
                    }

                    if (dataReader.DoesFieldExist("Status"))
                    {
                        AddIntElement(article, "STATUS", dataReader.GetInt32NullAsZero("Status"));
                    }
                    if (dataReader.DoesFieldExist("RecommendationStatus"))
                    {
                        AddIntElement(article, "RECOMMENDATION-STATUS", dataReader.GetInt32NullAsZero("RecommendationStatus"));
                    }
                    if (dataReader.DoesFieldExist("SubbingStatus"))
                    {
                        AddIntElement(article, "SUBBING-STATUS", dataReader.GetInt32NullAsZero("SubbingStatus"));
                    }
                    if (dataReader.DoesFieldExist("Style"))
                    {
                        AddIntElement(article, "STYLE", dataReader.GetInt32NullAsZero("Style"));
                    }

                    if (dataReader.DoesFieldExist("Subject"))
                    {
                        AddTextTag(article, "SUBJECT", dataReader.GetStringNullAsEmpty("Subject"));
                    }

                    if (dataReader.DoesFieldExist("DateCreated"))
                    {
                        AddDateXml(dataReader, article, "DateCreated", "DATE-CREATED");
                    }
                    if (dataReader.DoesFieldExist("LastUpdated"))
                    {
                        AddDateXml(dataReader, article, "LastUpdated", "LASTUPDATED");
                    }
                    if (dataReader.DoesFieldExist("DateRecommended"))
                    {
                        AddDateXml(dataReader, article, "DateRecommended", "DATE-RECOMMENDED");
                    }
                    if (dataReader.DoesFieldExist("DecisionDate"))
                    {
                        AddDateXml(dataReader, article, "DecisionDate", "RECOMMENDATION-DECISION-DATE");
                    }
                    if (dataReader.DoesFieldExist("DateAllocated"))
                    {
                        AddDateXml(dataReader, article, "DateAllocated", "DATE-ALLOCATED");
                    }
                    if (dataReader.DoesFieldExist("DateReturned"))
                    {
                        AddDateXml(dataReader, article, "DateReturned", "DATE-RETURNED");
                    }

                    //TODO add Extra Info correctly
                    if (dataReader.DoesFieldExist("ExtraInfo"))
                    {
                        //Add Extra Info XML where it exists.
                        string extraInfo = dataReader.GetAmpersandEscapedStringNullAsEmpty("ExtraInfo");
                        if (extraInfo != string.Empty)
                        {
                            XmlDocument extraInfoXml = new XmlDocument();
                            extraInfoXml.LoadXml(extraInfo);
                            article.AppendChild(ImportNode(extraInfoXml.FirstChild));
                        }

                        //TODO Use Extra Info Class will need to change SP to get out the guide entry Type
                        //ExtraInfo extraInfo = new ExtraInfo();
                        //extraInfo.TryCreate(dataReader.GetInt32NullAsZero("Type"), dataReader.GetStringNullAsEmpty("ExtraInfo"));
                        //AddInside(article, extraInfo);
                    }

                    if (dataReader.DoesFieldExist("ForumPostCount"))
                    {
                        AddIntElement(article, "FORUMPOSTCOUNT", dataReader.GetInt32NullAsZero("ForumPostCount"));
                        AddIntElement(article, "FORUMPOSTLIMIT", InputContext.GetSiteOptionValueInt("Forum", "PostLimit"));
                    }

                    if (dataReader.DoesFieldExist("StartDate") && !dataReader.IsDBNull("StartDate"))
                    {
                        AddDateXml(dataReader, article, "StartDate", "DATERANGESTART");
                    }
                    // Take a day from the end date as stored in the database for UI purposes. 
                    // E.g. User submits a date range of 01/09/1980 to 02/09/1980. They mean for this to represent 2 days i.e. 01/09/1980 00:00 - 03/09/1980 00:00. 
                    // This gets stored in the database but for display purposes we subtract a day from the database end date to return the 
                    // original dates submitted by the user inorder to match their expectations.
                    if (dataReader.DoesFieldExist("EndDate") && !dataReader.IsDBNull("EndDate"))
                    {
                        AddDateXml(dataReader.GetDateTime("EndDate").AddDays(-1), article, "DATERANGEEND");
                    }

                    if (dataReader.DoesFieldExist("TimeInterval"))
                    {
                        AddIntElement(article, "TIMEINTERVAL", dataReader.GetInt32NullAsZero("TimeInterval"));
                    }

                    if (dataReader.DoesFieldExist("LASTPOSTED"))
                    {
                        AddDateXml(dataReader, article, "LASTPOSTED", "FORUMLASTPOSTED");
                    }
                    //////////


                    if (dataReader.DoesFieldExist("BookmarkCount"))
                    {
                        AddTextTag(article, "BOOKMARKCOUNT", dataReader.GetInt32NullAsZero("BookmarkCount"));
                    }

                    if (dataReader.DoesFieldExist("ZeitgeistScore"))
                    {
                        AddElement(article, "ZEITGEIST", "<SCORE>" + dataReader.GetDoubleNullAsZero("ZeitgeistScore") + "</SCORE>");
                    }

                    #region LocationXML
                    //***********************************************************************
                    // Location Info
                    //***********************************************************************
                    if (dataReader.DoesFieldExist("Latitude") && !dataReader.IsDBNull("Latitude"))
                    {
                        AddTextTag(article, "LATITUDE", dataReader.GetDoubleNullAsZero("Latitude").ToString());
                        AddTextTag(article, "LONGITUDE", dataReader.GetDoubleNullAsZero("Longitude").ToString());
                        if (dataReader.DoesFieldExist("Distance"))
                        {
                            if (dataReader.GetDoubleNullAsZero("Distance") < 0.0001)
                            {
                                AddTextTag(article, "DISTANCE", "0");
                            }
                            else
                            {
                                AddTextTag(article, "DISTANCE", dataReader.GetDoubleNullAsZero("Distance").ToString());
                            }
                        }
                        AddTextTag(article, "LOCATIONTITLE", dataReader.GetString("LocationTitle"));
                        AddTextTag(article, "LOCATIONDESCRIPTION", dataReader.GetString("LocationDescription"));
                        AddTextTag(article, "LOCATIONZOOMLEVEL", dataReader.GetInt32NullAsZero("LocationZoomLevel").ToString());
                        AddTextTag(article, "LOCATIONUSERID", dataReader.GetInt32NullAsZero("LocationUserID").ToString());
                        AddDateXml(dataReader.GetDateTime("LocationDateCreated"), article, "LOCATIONDATECREATED");
                    }
                    //***********************************************************************
                    #endregion

                    if (dataReader.DoesFieldExist("MediaAssetID"))
                    {
                        AddMediaAssetXml(dataReader, article, dataReader.GetInt32NullAsZero("MediaAssetID"));
                    }

                    if (dataReader.DoesFieldExist("CRPollID"))
                    {
                        AddPollXml(dataReader, article);
                    }



                    count--;

                } while (count > 0 && dataReader.Read());	// dataReader.Read won't get called if count == 0

                // See if there's an extra row waiting
                if (count == 0 && dataReader.Read())
                {
                    AddAttribute(articleList, "MORE", 1);
                }
            }
            return count;
        }
Exemple #15
0
        /// <summary>
        /// Creates a ratinginfo object
        /// </summary>
        /// <param name="reader">A reader with all information</param>
        /// <returns>Rating Info object</returns>
        public RatingInfo RatingCreateFromReader(IDnaDataReader reader, ISite site)
        {
            RatingInfo ratingInfo = new RatingInfo
            {
                Created = new DateTimeHelper(DateTime.Parse(reader.GetDateTime("Created").ToString())),
                User = base.UserReadById(reader, site),
                ID = reader.GetInt32NullAsZero("id"),
                rating = reader.GetByte("rating")
            };

            ratingInfo.hidden = (CommentStatus.Hidden)reader.GetInt32NullAsZero("hidden");
            if (reader.IsDBNull("poststyle"))
            {
                ratingInfo.PostStyle = PostStyle.Style.richtext;
            }
            else
            {
                ratingInfo.PostStyle = (PostStyle.Style)reader.GetTinyIntAsInt("poststyle");
            }

            ratingInfo.IsEditorPick = reader.GetBoolean("IsEditorPick");
            ratingInfo.Index = reader.GetInt32NullAsZero("PostIndex");

            //get complainant
            Dictionary<string, string> replacement = new Dictionary<string, string>();
            replacement.Add("sitename", site.SiteName);
            replacement.Add("postid", ratingInfo.ID.ToString());
            ratingInfo.ComplaintUri = UriDiscoverability.GetUriWithReplacments(BasePath, SiteList.GetSiteOptionValueString(site.SiteID, "General", "ComplaintUrl"), replacement);
            
            replacement = new Dictionary<string, string>();
            replacement.Add("RatingForumid", reader.GetString("forumuid"));
            replacement.Add("sitename", site.SiteName);
            ratingInfo.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.RatingsByRatingForumId, replacement);
            
            replacement = new Dictionary<string, string>();
            replacement.Add("parentUri", reader.GetString("parentUri"));
            replacement.Add("postid", ratingInfo.ID.ToString());
            ratingInfo.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.Comment, replacement);
            
            //Get Editors Pick ( this should be expanded to include any kind of poll )
            /*EditorsPick editorsPick = new EditorsPick(_dnaDiagnostics, _connection, _caching);
            if (editorsPick.LoadPollResultsForItem(commentInfo.ID) && editorsPick.Id > 0)
            {
                commentInfo.EditorsPick = new EditorsPickInfo
                {
                    Id = editorsPick.Id,
                    Response = editorsPick.Result
                };
            }*/
            ratingInfo.text = CommentInfo.FormatComment(reader.GetString("text"), ratingInfo.PostStyle, ratingInfo.hidden, ratingInfo.User.Editor);
            return ratingInfo;
        }
Exemple #16
0
        /// <summary>
        /// Creates the XML block for a posting in a thread
        /// </summary>
        /// <param name="reader">The IDnaDataReader that contains the information about the posting</param>
        /// <param name="threadNode">The node to add the posting node to</param>
        /// <param name="usersPrefix">Pass in 'First' if the post is the first post in the thread, and 'last' if it's the last.</param>
        /// <returns>The new post node</returns>
        private XmlNode CreateThreadPostingXml(IDnaDataReader reader, XmlNode threadNode, string usersPrefix)
        {
            XmlNode postingNode = AddElementTag(threadNode, usersPrefix + "POST");
            AddAttribute(postingNode, "POSTID", reader.GetInt32(usersPrefix + "PostEntryID"));
            AddAttribute(postingNode, "HIDDEN", reader.GetInt32NullAsZero(usersPrefix + "PostHidden"));

            User postingUser = new User(InputContext);
            postingUser.AddPrefixedUserXMLBlock(reader, reader.GetInt32(usersPrefix + "PostUserID"), usersPrefix + "Post", postingNode);

            if (!reader.IsDBNull(usersPrefix + "PostHidden") && reader.GetInt32(usersPrefix + "PostHidden") > 0)
            {
                AddTextElement((XmlElement)postingNode, "TEXT", "Hidden");
            }
            else
            {
                string text = reader.GetString(usersPrefix + "PostText");

                // Do the translate to plain text here!

                XmlNode textNode = AddTextElement((XmlElement)postingNode, "TEXT", text);
            }

            return postingNode;
        }
Exemple #17
0
 void TestNullableDateField(IDnaDataReader reader, string fieldName, TestDate expected)
 {
     if (reader.IsDBNull(fieldName))
         Assert.IsNull(expected);
     else
         Assert.IsTrue(expected.CheckDate(reader.GetDateTime(fieldName)));
 }
Exemple #18
0
        /// <summary>
        /// With the returned data set generate the XML for the Article Search page
        /// </summary>
        /// <param name="dataReader">The returned search resultset</param>
        /// <param name="asp">The Article Search Params</param>
        private void GenerateArticleSearchXml(IDnaDataReader dataReader, ArticleSearchParams asp)
        {
            RootElement.RemoveAll();
            XmlNode articleSearch = AddElementTag(RootElement, "ARTICLESEARCH");

            AddAttribute(articleSearch, "CONTENTTYPE", asp.ContentType);
            AddAttribute(articleSearch, "SORTBY", asp.SortBy);
            AddAttribute(articleSearch, "SKIPTO", asp.Skip);
            AddAttribute(articleSearch, "SHOW", asp.Show);
            AddAttribute(articleSearch, "DATESEARCHTYPE", asp.DateSearchType);
            AddAttribute(articleSearch, "TIMEINTERVAL", asp.TimeInterval);
            AddAttribute(articleSearch, "ARTICLESTATUS", asp.ArticleStatus);
            AddAttribute(articleSearch, "ARTICLETYPE", asp.ArticleType);
            AddAttribute(articleSearch, "LATITUDE", asp.Latitude);
            AddAttribute(articleSearch, "LONGITUDE", asp.Longitude);
            AddAttribute(articleSearch, "RANGE", asp.Range);
            AddAttribute(articleSearch, "POSTCODE", asp.PostCode);
            AddAttribute(articleSearch, "PLACENAME", asp.Placename);
            AddAttribute(articleSearch, "LOCATIONSEARCHTYPE", asp.LocationSearchType);

            //Add the new descending order attribute
            if (asp.DescendingOrder)
            {
                AddAttribute(articleSearch, "DESCENDINGORDER", 1);
            }
            else
            {
                AddAttribute(articleSearch, "DESCENDINGORDER", 0);
            }

            //Add the requested searchphraselist
            GeneratePhraseXml(asp.SearchPhraseList, (XmlElement)articleSearch);

            //Add Date Search Params if we are doing a date search
            if (asp.DateSearchType != 0)
            {
                AddDateXml(asp.StartDate, articleSearch, "DATERANGESTART");
                // Take a day from the end date as used in the database for UI purposes. 
                // E.g. User submits a date range of 01/09/1980 to 02/09/1980. They mean for this to represent 2 days i.e. 01/09/1980 00:00 - 03/09/1980 00:00. 
                // This gets used in the database but for display purposes we subtract a day from the database end date to return the 
                // original dates submitted by the user inorder to match their expectations.
                AddDateXml(asp.EndDate.AddDays(-1), articleSearch, "DATERANGEEND");
            }

            AddTextTag(articleSearch, "FREETEXTSEARCH", asp.FreeTextSearchCondition);

            XmlNode articles = AddElementTag(articleSearch, "ARTICLES");
            int total = 0;
            int count = 0;

            //Generate Hot-List from Search Results.
            PopularPhrases popularPhrases = null;
            if (InputContext.GetSiteOptionValueBool("articlesearch", "generatepopularphrases"))
            {
                popularPhrases = new PopularPhrases();
            }

            if (dataReader.HasRows)
            {
                // process first results set: the Article Key phrase results set
                Dictionary<int, ArrayList> articleKeyPhrases = new Dictionary<int, ArrayList>();
                ArrayList phraselist = new ArrayList();
                int h2g2ID = 0;

                if (dataReader.Read())
                {
                    int previousH2G2ID = 0;

                    do
                    {
                        h2g2ID = dataReader.GetInt32NullAsZero("H2G2ID");

                        if (h2g2ID != previousH2G2ID)
                        {
                            //New now have a new article so clean up the last one
                            if (previousH2G2ID != 0)
                            {
                                articleKeyPhrases.Add(previousH2G2ID, phraselist);
                                phraselist = new ArrayList();
                            }
                        }

                        //set the previous h2g2id to this one
                        previousH2G2ID = h2g2ID;

                        //Create fill an new Phrase object
                        Phrase nameSpacedPhrase = new Phrase();

                        String nameSpace = String.Empty;
                        String phraseName = dataReader.GetStringNullAsEmpty("phrase");

                        if (phraseName != String.Empty)
                        {
                            if (dataReader.Exists("namespace"))
                            {
                                nameSpace = dataReader.GetStringNullAsEmpty("namespace");
                            }
                            nameSpacedPhrase.NameSpace = nameSpace;
                            nameSpacedPhrase.PhraseName = phraseName;

                            //add it to the list
                            phraselist.Add(nameSpacedPhrase);

                            //Record Popular Phrases.
                            if (popularPhrases != null)
                            {
                                popularPhrases.AddPhrase(phraseName, nameSpace);
                            }
                        }

                    } while (dataReader.Read());
                }

                articleKeyPhrases.Add(h2g2ID, phraselist);

                dataReader.NextResult();

                if (dataReader.Read())
                {
                    total = dataReader.GetInt32NullAsZero("TOTAL");

                    //The stored procedure returns one row for each article. The article's keyphrases have been stored in articleKeyPhrases.
                    XmlNode article = CreateElementNode("ARTICLE");
                    do
                    {
                        count++;
                        h2g2ID = dataReader.GetInt32NullAsZero("H2G2ID");

                        //Start filling new article xml
                        AddAttribute(article, "H2G2ID", h2g2ID);

                        int editorID = dataReader.GetInt32NullAsZero("editor");
                        XmlNode editor = CreateElementNode("EDITOR");
                        User user = new User(InputContext);
                        user.AddUserXMLBlock(dataReader, editorID, editor);
                        article.AppendChild(editor);

                        AddTextTag(article, "STATUS", dataReader.GetInt32NullAsZero("status"));
                        AddXmlTextTag(article, "SUBJECT", dataReader.GetStringNullAsEmpty("SUBJECT"));
                        AddTextTag(article, "TYPE", dataReader.GetInt32NullAsZero("type"));

                        AddDateXml(dataReader, article, "DateCreated", "DATECREATED");
                        AddDateXml(dataReader, article, "LastUpdated", "LASTUPDATED");

                        //Add Extra Info XML where it exists.
                        string extraInfo = dataReader.GetAmpersandEscapedStringNullAsEmpty("EXTRAINFO");
                        if (extraInfo != string.Empty)
                        {

                            XmlDocument extraInfoXml = new XmlDocument();
                            extraInfoXml.LoadXml(extraInfo);
                            article.AppendChild(ImportNode(extraInfoXml.FirstChild));

                        }

                        AddTextTag(article, "NUMBEROFPOSTS", dataReader.GetInt32NullAsZero("ForumPostCount"));
                        AddDateXml(dataReader, article, "LASTPOSTED", "FORUMLASTPOSTED");
                        if (!dataReader.IsDBNull("StartDate"))
                        {
                            AddDateXml(dataReader, article, "StartDate", "DATERANGESTART");
                            // Take a day from the end date as stored in the database for UI purposes. 
                            // E.g. User submits a date range of 01/09/1980 to 02/09/1980. They mean for this to represent 2 days i.e. 01/09/1980 00:00 - 03/09/1980 00:00. 
                            // This gets stored in the database but for display purposes we subtract a day from the database end date to return the 
                            // original dates submitted by the user inorder to match their expectations.
                            AddDateXml(dataReader.GetDateTime("EndDate").AddDays(-1), article, "DATERANGEEND");

                            AddTextTag(article, "TIMEINTERVAL", dataReader.GetInt32NullAsZero("TimeInterval"));
                        }


                        if (dataReader.DoesFieldExist("BookmarkCount"))
                        {
                            AddTextTag(article, "BOOKMARKCOUNT", dataReader.GetInt32NullAsZero("BookmarkCount"));
                        }

                        if (dataReader.DoesFieldExist("ZeitgeistScore"))
                        {
                            AddElement(article, "ZEITGEIST", "<SCORE>" + dataReader.GetDoubleNullAsZero("ZeitgeistScore") + "</SCORE>");
                        }

                        

                        #region LocationXML
                        //***********************************************************************
                        // Location Info
                        //***********************************************************************
                        if (dataReader.DoesFieldExist("Latitude") && !dataReader.IsDBNull("Latitude"))
                        {
                            AddTextTag(article, "LATITUDE", dataReader.GetDoubleNullAsZero("Latitude").ToString());
                            AddTextTag(article, "LONGITUDE", dataReader.GetDoubleNullAsZero("Longitude").ToString());
                            if (dataReader.DoesFieldExist("Distance"))
                            {
                                if (dataReader.GetDoubleNullAsZero("Distance") < 0.0001)
                                {
                                    AddTextTag(article, "DISTANCE", "0");
                                }
                                else
                                {
                                    AddTextTag(article, "DISTANCE", dataReader.GetDoubleNullAsZero("Distance").ToString());
                                }
                            }
                            AddTextTag(article, "LOCATIONTITLE", dataReader.GetString("LocationTitle"));
                            AddTextTag(article, "LOCATIONDESCRIPTION", dataReader.GetString("LocationDescription"));
                            AddTextTag(article, "LOCATIONZOOMLEVEL", dataReader.GetInt32NullAsZero("LocationZoomLevel").ToString());
                            AddTextTag(article, "LOCATIONUSERID", dataReader.GetInt32NullAsZero("LocationUserID").ToString());
                            AddDateXml(dataReader.GetDateTime("LocationDateCreated"), article, "LOCATIONDATECREATED");
                        }
                        //***********************************************************************
                        #endregion
                        //***********************************************************************
                        // Media Asset Info
                        //***********************************************************************
                        int mediaAssetID = dataReader.GetInt32NullAsZero("MediaAssetID");

                        if (mediaAssetID != 0)
                        {
                            AddMediaAssetXml(dataReader, article, mediaAssetID);
                        }
                        //***********************************************************************

                        AddPollXml(dataReader, article);

                        if (articleKeyPhrases.ContainsKey(h2g2ID))
                        {
                            GeneratePhraseXml(articleKeyPhrases[h2g2ID], (XmlElement)article);
                        }

                        XmlNode previousarticle = article.CloneNode(true);
                        articles.AppendChild(previousarticle);
                        article.RemoveAll();

                    } while (dataReader.Read());
                }
            }
            articleSearch.AppendChild(articles);
            AddAttribute(articleSearch, "COUNT", count);
            AddAttribute(articleSearch, "TOTAL", total);

            if (popularPhrases != null)
            {
                //Include popularPhrase statistics.
                XmlElement popularPhrasesXml = popularPhrases.GenerateXml();
                articleSearch.AppendChild(ImportNode(popularPhrasesXml));
            }

            FileCache.PutItem(AppContext.TheAppContext.Config.CachePath, "articlesearch", _cacheName, articleSearch.OuterXml);

            //articleSearch.OwnerDocument.Save(@"c:\TEMP\Articlesearch.xml");
        }
Exemple #19
0
        private static Contribution CreateContributionInternal(IDnaDataReader reader)
        {
            Contribution contribution = new Contribution();

            // Make sure we got something back
            if (reader.HasRows && reader.Read()) 
            {
                contribution.Body = reader.GetStringNullAsEmpty("Body");
                contribution.PostIndex = reader.GetLongNullAsZero("PostIndex");
                contribution.SiteName = reader.GetStringNullAsEmpty("SiteName");
                contribution.SiteType = (SiteType)Enum.Parse(typeof(SiteType), reader.GetStringNullAsEmpty("SiteType"));
                contribution.SiteDescription = reader.GetStringNullAsEmpty("SiteDescription");
                contribution.SiteUrl = reader.GetStringNullAsEmpty("UrlName");
                contribution.FirstSubject = reader.GetStringNullAsEmpty("FirstSubject");
                contribution.Subject = reader.GetStringNullAsEmpty("Subject");
                contribution.Timestamp = new DateTimeHelper(reader.GetDateTime("TimeStamp"));
                contribution.Title = reader.GetStringNullAsEmpty("ForumTitle");
                contribution.ThreadEntryID = reader.GetInt32("ThreadEntryID");
                contribution.CommentForumUrl = reader.GetStringNullAsEmpty("CommentForumUrl");
                contribution.GuideEntrySubject = reader.GetStringNullAsEmpty("GuideEntrySubject");

                contribution.TotalPostsOnForum = reader.GetInt32NullAsZero("TotalPostsOnForum");
                contribution.AuthorUserId = reader.GetInt32NullAsZero("AuthorUserId");
                contribution.AuthorUsername = reader.GetStringNullAsEmpty("AuthorUsername");
                contribution.AuthorIdentityUsername = reader.GetStringNullAsEmpty("AuthorIdentityUsername");

                bool forumCanWrite = reader.GetByteNullAsZero("ForumCanWrite") == 1;
                bool isEmergencyClosed = reader.GetInt32NullAsZero("SiteEmergencyClosed") == 1;
                //bool isSiteScheduledClosed = reader2.GetByteNullAsZero("SiteScheduledClosed") == 1;

                DateTime closingDate = DateTime.MaxValue;
                if (reader.DoesFieldExist("forumclosedate") && !reader.IsDBNull("forumclosedate"))
                {
                    closingDate = reader.GetDateTime("forumclosedate");
                    contribution.ForumCloseDate = new DateTimeHelper(closingDate);
                }
                contribution.isClosed = (!forumCanWrite || isEmergencyClosed || (closingDate != null && DateTime.Now > closingDate));
            }
            else
            {
                throw ApiException.GetError(ErrorType.ThreadPostNotFound);
            }

            return contribution;
        }
Exemple #20
0
        /// <summary>
        /// Builds Hierarchy xml from the given datareader
        /// </summary>
        /// <param name="reader">The datset to query</param>
        /// <returns>resulting xml element</returns>
        public XmlElement GetHierarchyDetails(IDnaDataReader reader)
        {
            XmlElement hierarchyDetails = CreateElement("HIERARCHYDETAILS");

            string description = reader.GetStringNullAsEmpty("Description");
            string synonyms = reader.GetStringNullAsEmpty("Synonyms");
            int H2G2ID = reader.GetInt32NullAsZero("h2g2id");
            int nodeID = reader.GetInt32NullAsZero("nodeid");

            int userAdd = reader.GetInt32NullAsZero("UserAdd");
            int parentID = reader.GetInt32NullAsZero("ParentID");
            int typeID = reader.GetInt32NullAsZero("Type");

            AddAttribute(hierarchyDetails, "NODEID", nodeID);
            if (parentID == 0)	//is root?
            {
                AddAttribute(hierarchyDetails, "ISROOT", 1);
            }
            else
            {
                AddAttribute(hierarchyDetails, "ISROOT", 0);
            }
            AddAttribute(hierarchyDetails, "USERADD", userAdd);
            AddAttribute(hierarchyDetails, "TYPE", typeID);

            string displayName = reader.GetStringNullAsEmpty("DisplayName");
            AddTextTag(hierarchyDetails, "DISPLAYNAME", displayName);

            if (nodeID > 0)
            {
                AddTextTag(hierarchyDetails, "DESCRIPTION", description);
                AddTextTag(hierarchyDetails, "SYNONYMS", synonyms);
                if (H2G2ID > 0)
                {
                    AddIntElement(hierarchyDetails, "H2G2ID", H2G2ID);
                }

                // Check to see if the node has a redirected
                if (reader.DoesFieldExist("RedirectNodeID") && !reader.IsDBNull("RedirectNodeID"))
                {
                    string RedirectNodeName = reader.GetStringNullAsEmpty("RedirectNodeName");
                    XmlElement redirectNode = AddTextTag(hierarchyDetails, "REDIRECTNODE", RedirectNodeName);
                    AddAttribute(redirectNode, "ID", reader.GetInt32NullAsZero("RedirectNodeID"));
                }
            }
            return hierarchyDetails;
        }
Exemple #21
0
        /// <summary>
        /// With the returned data set generate the XML for the Article History page
        /// </summary>
        /// <param name="dataReader">Data set to turn into XML</param>
        /// <param name="entryID">Article to get the history of </param>
        private void GenerateArticleHistoryXml(IDnaDataReader dataReader, int entryID)
        {
            int count = 0;

            XmlElement articleHistory = AddElementTag(RootElement, "ARTICLEHISTORY");

            AddAttribute(articleHistory, "EntryID", entryID);

            if (dataReader.HasRows)
            {
                if (dataReader.Read())
                {
                    XmlElement items = AddElementTag(articleHistory, "ITEMS");

                    do
                    {
                        XmlElement item = AddElementTag(items, "ITEM");

                        AddIntElement(item, "USERID", dataReader.GetInt32NullAsZero("userid"));
                        AddIntElement(item, "ACTION", dataReader.GetInt32NullAsZero("action"));

                        AddTextTag(item, "COMMENT", dataReader.GetStringNullAsEmpty("comment"));

                        if (!dataReader.IsDBNull("dateperformed"))
                        {
                            AddDateXml(dataReader, item, "dateperformed", "DATEPERFORMED");
                        }
                        else
                        {
                            AddTextTag(item, "DATEPERFORMED", "");
                        }

                        count++;

                    } while (dataReader.Read());
                }
            }

            AddAttribute(articleHistory, "COUNT", count);
        }
Exemple #22
0
        /// <summary>
        /// This method creates the crumbtrail for a given item
        /// </summary>
        /// <param name="reader">The DnaDataReader that contains the crumbtrail result set.</param>
        private void GetCrumbtrailForItem(IDnaDataReader reader)
        {
            XmlNode crumbtrailsNode = AddElementTag(RootElement, "CRUMBTRAILS");
            bool startOfTrail = true;
            XmlNode crumbtrailNode = null;
            while (reader.Read())
            {
                // Check to see if we're at the top level
                int treeLevel = reader.GetInt32("TreeLevel");
                if (treeLevel == 0)
                {
                    startOfTrail = true;
                }
                
                // Check to see if we're starting a new trail
                if (startOfTrail)
                {
                    crumbtrailNode = AddElementTag(crumbtrailsNode, "CRUMBTRAIL");
                    startOfTrail = false;
                }

                XmlNode ancestorNode = AddElementTag(crumbtrailNode, "ANCESTOR");
                AddIntElement(ancestorNode, "NODEID", reader.GetInt32("NodeID"));
                AddTextElement((XmlElement)ancestorNode, "NAME", reader.GetString("DisplayName"));
                AddIntElement(ancestorNode, "TREELEVEL", treeLevel);
                AddIntElement(ancestorNode, "NODETYPE", reader.GetInt32("Type"));
                if (reader.Exists("RedirectNodeID") && !reader.IsDBNull("RedirectNodeID"))
                {
                    XmlNode redirectNode = AddTextElement((XmlElement)ancestorNode, "REDIRECTNODE", reader.GetString("RedirectNodeName"));
                    AddAttribute(redirectNode,"ID", reader.GetInt32("RedirectNodeID"));
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// Creates the commentforumdata from a given reader
        /// </summary>
        /// <param name="reader">The database reaser</param>
        /// <returns>A Filled comment forum object</returns>
        private CommentForum CommentForumCreateFromReader(IDnaDataReader reader)
        {
            var closingDate = reader.GetDateTime("forumclosedate");
            //if (closingDate == null)
            //{
            //    closingDate = DateTime.MaxValue;
            //}
            var site = SiteList.GetSite(reader.GetStringNullAsEmpty("sitename"));

            var commentForum = new CommentForum();

            commentForum.Title = reader.GetStringNullAsEmpty("Title");
            commentForum.Id = reader.GetStringNullAsEmpty("UID");
            commentForum.CanRead = reader.GetByteNullAsZero("canRead") == 1;
            commentForum.CanWrite = reader.GetByteNullAsZero("canWrite") == 1;
            commentForum.ParentUri = reader.GetStringNullAsEmpty("Url");
            commentForum.SiteName = reader.GetStringNullAsEmpty("sitename");
            commentForum.CloseDate = closingDate;
            commentForum.LastUpdate = reader.GetDateTime("LastUpdated");
            if (reader.GetDateTime("lastposted") > commentForum.LastUpdate)
            {
//use last posted as it is newer
                commentForum.LastUpdate = reader.GetDateTime("lastposted");
            }
            commentForum.Updated = new DateTimeHelper(commentForum.LastUpdate);
            commentForum.Created = new DateTimeHelper(reader.GetDateTime("DateCreated"));
            commentForum.commentSummary = new CommentsSummary
                                              {
                                                  Total = reader.GetInt32NullAsZero("ForumPostCount"),
                                                  EditorPicksTotal = reader.GetInt32NullAsZero("editorpickcount")
                                              };
            commentForum.ForumID = reader.GetInt32NullAsZero("forumid");
            commentForum.isClosed = !commentForum.CanWrite || site.IsEmergencyClosed ||
                                    site.IsSiteScheduledClosed(DateTime.Now) ||
                                    (DateTime.Now > closingDate);
            //MaxCharacterCount = siteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "'MaxCommentCharacterLength")
            var replacements = new Dictionary<string, string>();
            replacements.Add("commentforumid", reader.GetStringNullAsEmpty("uid"));
            replacements.Add("sitename", site.SiteName);

            if (reader.Exists("IsContactForm") && !reader.IsDBNull("IsContactForm"))
            {
                commentForum.isContactForm = true;
                commentForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.ContactFormById,
                                                                            replacements);
                commentForum.commentSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                           UriDiscoverability.UriType.ContactFormById,
                                                                                           replacements);
            }
            else
            {
                commentForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.CommentForumById,
                                                                            replacements);
                commentForum.commentSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                                           UriDiscoverability.UriType.CommentsByCommentForumId,
                                                                                           replacements);
            }

            //get moderation status
            commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Unknown;
            if (!reader.IsDBNull("moderationstatus"))
            {
//if it is set for the specific forum
                commentForum.ModerationServiceGroup =
                    (ModerationStatus.ForumStatus) (reader.GetTinyIntAsInt("moderationstatus"));
            }
            if (commentForum.ModerationServiceGroup == ModerationStatus.ForumStatus.Unknown)
            {
//else fall back to site moderation status
                switch (site.ModerationStatus)
                {
                    case ModerationStatus.SiteStatus.UnMod:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive;
                        break;
                    case ModerationStatus.SiteStatus.PreMod:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod;
                        break;
                    case ModerationStatus.SiteStatus.PostMod:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod;
                        break;
                    default:
                        commentForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive;
                        break;
                }
            }

            commentForum.NotSignedInUserId = reader.GetInt32NullAsZero("NotSignedInUserId");
            commentForum.allowNotSignedInCommenting = commentForum.NotSignedInUserId != 0;

            return commentForum;
        }
Exemple #24
0
 /// <summary>
 /// Add a date from the database in the correct DNADateFormat to the XML
 /// </summary>
 /// <param name="dataReader">Record set containing the data</param>
 /// <param name="parent">parent to add the xml to</param>
 /// <param name="columnName">Column name to extract the date data from</param>
 /// <param name="XMLName">Name of the element in the XML document to store the data data in</param>
 public void AddDateXml(IDnaDataReader dataReader, XmlNode parent, string columnName, string XMLName)
 {
     if (!dataReader.IsDBNull(columnName))
     {
         DateTime date = dataReader.GetDateTime(columnName);
         XmlElement dateXML = DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, date);
         AddElement(parent, XMLName, dateXML);
     }
 }
Exemple #25
0
        private CommentInfo IncludeDistressMessage(IDnaDataReader reader, ISite site)
        {
            var commentInfo = new CommentInfo();

            commentInfo.Created = new DateTimeHelper(DateTime.Parse(reader.GetDateTime("DmCreated").ToString()));
            commentInfo.ID = reader.GetInt32NullAsZero("DmId");
            commentInfo.User = DmUserFromReader(reader, site);

            commentInfo.hidden = (CommentStatus.Hidden)reader.GetInt32NullAsZero("DmHidden");
            if (reader.IsDBNull("DmPostStyle"))
            {
                commentInfo.PostStyle = PostStyle.Style.richtext;
            }
            else
            {
                commentInfo.PostStyle = (PostStyle.Style)reader.GetTinyIntAsInt("DmPostStyle");
            }
            commentInfo.Index = reader.GetInt32NullAsZero("DmPostIndex");

            commentInfo.text = CommentInfo.FormatComment(reader.GetStringNullAsEmpty("DmText"), 
                commentInfo.PostStyle, 
                commentInfo.hidden, 
                commentInfo.User.Editor);

            var replacement = new Dictionary<string, string>();
            replacement.Add("commentforumid", reader.GetString("forumuid"));
            replacement.Add("sitename", site.SiteName);
            commentInfo.ForumUri = UriDiscoverability.GetUriWithReplacments(BasePath,
                                                                            UriDiscoverability.UriType.CommentForumById,
                                                                            replacement);
            replacement = new Dictionary<string, string>();
            replacement.Add("parentUri", reader.GetString("parentUri"));
            replacement.Add("postid", commentInfo.ID.ToString());
            commentInfo.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.Comment,
                                                                       replacement);

            return commentInfo;
        }
Exemple #26
0
        /// <summary>
        /// Generates/fills the full forum thread posts xml document
        /// </summary>
        /// <param name="uid">The unique identifier for the Comment CommentBoxForum</param>
        /// <param name="fromPostIndex">Start Post Index</param>
        /// <param name="toPostIndex">Finish Post Index</param>
        /// <param name="show">If no to and from parameters we need the number of comments to show</param>
        /// <param name="dataReader">Dna Data Reader object</param>
        /// <param name="title">Passed in title of the comment</param>
        /// <param name="url">the passed in host page url</param>
        private void GenerateForumThreadPostsXML(string uid, int fromPostIndex, int toPostIndex, int show, IDnaDataReader dataReader, string title, string url)
        {
            int forumPostCount;
            int returnedPostCount;

            ExtractPostCount(dataReader, out forumPostCount);

            // Put the forum closing date into the xml
            XmlNode commentBox = RootElement.SelectSingleNode("COMMENTBOX");
            if (commentBox == null)
            {
                // Create this node
                commentBox = AddElementTag(RootElement, "COMMENTBOX");
            }

            // Add the closing date time to the xml, if we have one
            bool forumClosed = false;
            bool isForumCloseDateNull = dataReader.IsDBNull("ForumCloseDate");

			string existingtitle = dataReader.GetStringNullAsEmpty("commentforumtitle");
            string existingurl = dataReader.GetStringNullAsEmpty("URL");
            existingurl = StringUtils.EscapeAllXml(existingurl);
            url = StringUtils.EscapeAllXml(url);

			int forumID = dataReader.GetInt32NullAsZero("forumID");

            if (!isForumCloseDateNull)
            {
                DateTime closeDate = dataReader.GetDateTime("ForumCloseDate");
                //TODO: Write DnaComponent.AddDateElement method to encapsulate this
                XmlNode endDate = AddElementTag(commentBox, "ENDDATE");
                endDate.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, closeDate));
                forumClosed = closeDate < DateTime.Now;
            }

            returnedPostCount = CreateForumThreadPosts(uid, fromPostIndex, toPostIndex, dataReader, show, forumPostCount, commentBox);

            AddMoreAttribute(dataReader, forumPostCount, toPostIndex, returnedPostCount);

            // Modify the CanWrite flag depending on the user or if either the site or forum are closed
            UpdateCanWriteStatus(forumClosed);

            //Update the comment forum title if the passed in value is changed
            if (title != String.Empty && title != existingtitle)
            {
                UpdateCommentForumTitle(forumID, title);
                XmlNodeList commentForumTitleNodes = RootElement.SelectNodes("COMMENTBOX/FORUMTHREADPOSTS/POST/COMMENTFORUMTITLE");
                foreach (XmlNode commentForumTitle in commentForumTitleNodes)
                {
                    commentForumTitle.InnerText = title;
                }
            }

            if (url != string.Empty && url != existingurl)
            {
                UpdateCommentForumURL(forumID, url);
                XmlNode commentForumUrlNode = RootElement.SelectSingleNode("COMMENTBOX/FORUMTHREADPOSTS");
                if (commentForumUrlNode.Attributes["HOSTPAGEURL"] != null)
                {
                    commentForumUrlNode.Attributes["HOSTPAGEURL"].InnerText = url;
                }
            }

        }
Exemple #27
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataReader"></param>
        /// <param name="userSearchType"></param>
        /// <param name="searchText"></param>
        /// <param name="checkAllSites"></param>
        /// <param name="twitterAPIException"></param>
        public void GenerateMemberListXml(
            IDnaDataReader dataReader,
            int userSearchType,
            string searchText,
            bool checkAllSites,
            string twitterAPIException)
        {
            int count = 0;

            XmlNode memberList = AddElementTag(RootElement, "MEMBERLIST");
            AddAttribute(memberList, "USERSEARCHTYPE", userSearchType.ToString());
            AddAttribute(memberList, "SEARCHTEXT", searchText);
            AddAttribute(memberList, "CHECKALLSITES", checkAllSites.ToString());
            

            if (dataReader.HasRows)
            {
                if (dataReader.Read())
                {
                    XmlNode userAccounts = AddElementTag(memberList, "USERACCOUNTS");

                    //int previousUserID = 0;
                    XmlNode userAccount = null;
                    do
                    {
                        int userID = dataReader.GetInt32NullAsZero("USERID");
                        /*if (userID != previousUserID)
                        {
                            if (userAccount != null)
                            {
                                userAccounts.AppendChild(userAccount);
                            }
                            userAccount = CreateElementNode("USERACCOUNT");
                            previousUserID = userID;
                        }*/
                        userAccount = CreateElementNode("USERACCOUNT");

                        //Start filling new user xml
                        AddAttribute(userAccount, "USERID", userID);
                        AddTextTag(userAccount, "SITEID", dataReader.GetInt32NullAsZero("SITEID"));

                        AddTextTag(userAccount, "USERNAME", dataReader.GetStringNullAsEmpty("USERNAME"));
                        AddTextTag(userAccount, "LOGINNAME", dataReader.GetStringNullAsEmpty("LOGINNAME"));
                        AddTextTag(userAccount, "EMAIL", dataReader.GetStringNullAsEmpty("EMAIL"));
                        AddTextTag(userAccount, "PREFSTATUS", dataReader.GetInt32NullAsZero("PREFSTATUS"));
                        AddTextTag(userAccount, "PREFSTATUSDURATION", dataReader.GetInt32NullAsZero("PREFSTATUSDURATION"));
                        AddTextTag(userAccount, "USERSTATUSDESCRIPTION", ((ModerationStatus.UserStatus)dataReader.GetInt32NullAsZero("PREFSTATUS")).ToString());
                        if (!dataReader.IsDBNull("DATEJOINED"))
                        {
                            AddDateXml(dataReader.GetDateTime("DATEJOINED"), userAccount, "DATEJOINED");
                        }
                        if (!dataReader.IsDBNull("PREFSTATUSCHANGEDDATE"))
                        {
                            DateTime prefStatusChangedDate = dataReader.GetDateTime("PREFSTATUSCHANGEDDATE");
                            AddDateXml(prefStatusChangedDate, userAccount, "PREFSTATUSCHANGEDDATE");
                        }
                        else
                        {
                            AddTextTag(userAccount, "PREFSTATUSCHANGEDDATE", "");
                        }

                        AddTextTag(userAccount, "SHORTNAME", dataReader.GetStringNullAsEmpty("SHORTNAME"));
                        AddTextTag(userAccount, "URLNAME", dataReader.GetStringNullAsEmpty("URLNAME"));

                        if (dataReader.DoesFieldExist("IPADDRESS") && dataReader.GetStringNullAsEmpty("IPADDRESS") != String.Empty)
                        {
                            AddTextTag(userAccount, "IPADDRESS", dataReader.GetStringNullAsEmpty("IPADDRESS"));
                        }
                        if (dataReader.DoesFieldExist("BBCUID") && dataReader.GetGuidAsStringOrEmpty("BBCUID") != String.Empty)
                        {
                            AddTextTag(userAccount, "BBCUID", dataReader.GetGuidAsStringOrEmpty("BBCUID"));
                        }

                        if (userSearchType == 6)
                        {
                            AddTextTag(userAccount, "TWITTERUSERID", dataReader.GetStringNullAsEmpty("TwitterUserID"));
                        }
                        else
                        {
                            AddIntElement(userAccount, "SSOUSERID", dataReader.GetInt32NullAsZero("SSOUserID"));
                        }
                        AddTextTag(userAccount, "IDENTITYUSERID", dataReader.GetStringNullAsEmpty("IdentityUserID"));
                        AddIntElement(userAccount, "ACTIVE", dataReader.GetInt32NullAsZero("STATUS") != 0 ? 1:0);
                        userAccounts.AppendChild(userAccount);

                        count++;
                        
                    } while (dataReader.Read());

                    memberList.AppendChild(userAccounts);
                }
            }

            AddAttribute(memberList, "COUNT", count);

            AddAttribute(memberList, "TWITTEREXCEPTION", twitterAPIException);

            //FileCache.PutItem(AppContext.TheAppContext.Config.CachePath, "memberlist", _cacheName, memberList.OuterXml);

            //memberList.OwnerDocument.Save(@"c:\TEMP\memberlist.xml");
        }
Exemple #28
0
        private void GenerateXml(IDnaDataReader reader, int h2g2Id, int postId, string exLinkUrl)
        {
            XmlElement modHistory = AddElementTag(RootElement, "MODERATION-HISTORY");
            reader.Read();

            if (h2g2Id > 0)
                AddAttribute(modHistory, "H2G2ID", h2g2Id);
            else if (postId > 0)
            {
                AddAttribute(modHistory, "POSTID", postId);
                if ( reader.HasRows )
                {
                    AddAttribute(modHistory, "FORUMID", reader.GetInt32NullAsZero("forumid") );
                    AddAttribute(modHistory, "THREADID", reader.GetInt32NullAsZero("threadid") );
                }
            }
            else if (exLinkUrl != String.Empty)
                AddAttribute(modHistory, "EXLINKURL", exLinkUrl );

            if (reader.HasRows)
            {
                int rowCount = 0;
                do
                {
                    if (rowCount == 0)
                    {
                        AddXmlTextTag(modHistory, "SUBJECT", reader.GetStringNullAsEmpty("subject"));

                        if (reader.DoesFieldExist("authoruserid") && !reader.IsDBNull("authoruserid"))
                        {
                            XmlElement editorNode = AddElementTag(modHistory, "EDITOR");
                            User editor = new User(InputContext);
                            editor.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("authoruserid"), "Author", editorNode);
                        }
                    }

                    XmlElement moderation = AddElementTag(modHistory, "MODERATION");
                    AddAttribute(moderation, "MODID", reader.GetInt32NullAsZero("modid"));
                    AddIntElement(moderation, "STATUS", reader.GetInt32NullAsZero("status"));
                    AddTextElement(moderation, "URLNAME", InputContext.TheSiteList.GetSite(reader.GetInt32NullAsZero("siteid")).SiteName);
                    if (reader.DoesFieldExist("reasonid") && reader.GetInt32NullAsZero("reasonid") > 0)
                    {
                        AddIntElement(moderation, "REASONID", reader.GetInt32NullAsZero("reasonid"));
                    }

                    User user = new User(InputContext);

                    if ( !reader.IsDBNull("lockedbyuserid") )
                    {
                        XmlElement locked = AddElementTag(moderation, "LOCKED-BY");
                        user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("LockedBy"), "lockedby", locked);
                    }

                    if (!reader.IsDBNull("referredbyuserid"))
                    {
                        XmlElement referred = AddElementTag(moderation, "REFERRED-BY");
                        user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("referredbyuserid"), "referredby", referred);
                    }

                    XmlElement complaint = AddElementTag(moderation, "COMPLAINT");
                    AddTextElement(complaint, "COMPLAINT-TEXT", reader.GetStringNullAsEmpty("complainttext"));

                    if (reader.DoesFieldExist("complainantuserid") && !reader.IsDBNull("complainantuserid"))
                    {
                        user.AddPrefixedUserXMLBlock(reader, reader.GetInt32NullAsZero("complainantuserid"), "complainant", complaint);
                    }

                    AddTextElement(complaint, "IPADDRESS", reader.GetStringNullAsEmpty("ipaddress"));
                    AddTextElement(complaint, "BBCUID", reader.GetGuidAsStringOrEmpty("bbcuid").ToString());
                    AddTextElement(complaint, "EMAIL-ADDRESS", reader.GetStringNullAsEmpty("correspondenceemail"));
                    AddTextElement(moderation, "NOTES", HtmlUtils.ReplaceCRsWithBRs(reader.GetStringNullAsEmpty("notes")));

                    AddDateXml(reader.GetDateTime("datequeued"), moderation, "DATE-QUEUED");
                    if (!reader.IsDBNull("datelocked"))
                    {
                        AddDateXml(reader.GetDateTime("datelocked"), moderation, "DATE-LOCKED");
                    }

                    if (!reader.IsDBNull("datereferred"))
                    {
                        AddDateXml(reader.GetDateTime("datereferred"), moderation, "DATE-REFERRED");
                    }

                    if (!reader.IsDBNull("datecompleted"))
                    {
                        AddDateXml(reader.GetDateTime("datecompleted"), moderation, "DATE-COMPLETED");
                    }

                    ++rowCount;
                }
                while (reader.Read());
            }
        }