Beispiel #1
0
        /// <summary>
        /// Creates a new reviewforum in the database
        /// </summary>
        /// <param name="forumName"></param>
        /// <param name="URLFriendlyName"></param>
        /// <param name="incubateTime"></param>
        /// <param name="recommend"></param>
        /// <param name="siteID"></param>
        /// <param name="userID"></param>
        public void CreateAndInitialiseNewReviewForum(string forumName, string URLFriendlyName, int incubateTime, bool recommend,int siteID, int userID)
        {        	
	        _urlFriendlyName = URLFriendlyName;
	        _reviewForumName = forumName;

	        // Get the user information

	        if (_reviewForumName == String.Empty || _urlFriendlyName == String.Empty || _urlFriendlyName.IndexOf(" ") >= 0 || siteID <= 0 || incubateTime < 0)
	        {
                throw new DnaException("INVALID PARAMETERS - Invalid parameters in CreateAndInitialiseNewReviewForum.");

                /*
		        TDVASSERT(forumName != String.Empty ,"NULL forumname in CReviewForum::AddNewReviewForum");
		        TDVASSERT(_urlFriendlyName != String.Empty ,"NULL forumname in CReviewForum::AddNewReviewForum");
		        TDVASSERT(_urlFriendlyName.Find(" ") < 0,"Spaces found in the URL");
		        TDVASSERT(incubateTime >= 0, "Invalid incubate time in CReviewForum::AddNewReviewForum");
		        TDVASSERT(siteID > 0,"invalid siteid in CReviewForum::AddNewReviewForum");
		        TDVASSERT(userID > 0,"invalid userid in CReviewForum::AddNewReviewForum");
		        return false;*/
	        }

	        ExtraInfo extrainfo = new ExtraInfo();
	        int typeID = (int) GuideEntry.GuideEntryType.TYPEREVIEWFORUM;
            if (!extrainfo.TryCreate(typeID, ""))
	        {
                throw new DnaException("ReviewForum - InitialiseAndCreateNewReviewForum - Failed to create extrainfo for reviewforum due bad element");
	        }
	        //pass in the object -not the string!
        	
	        int reviewForumID = 0;
            string hash = String.Empty;
            string hashString = forumName + "<:>" + URLFriendlyName + "<:>" + userID + "<:>" + siteID + "<:>" + extrainfo.RootElement.OuterXml + "<:>" + incubateTime + "<:>" + recommend;

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("addnewreviewforum"))
            {
                dataReader.AddParameter("URLName", URLFriendlyName);
                dataReader.AddParameter("ReviewForumName", forumName);
                dataReader.AddParameter("Incubate", incubateTime);
                dataReader.AddParameter("Recommend", recommend);
                dataReader.AddParameter("SiteID", siteID);
                dataReader.AddParameter("userid", userID);
                dataReader.AddParameter("extra", extrainfo.RootElement.OuterXml);
                dataReader.AddParameter("Type", typeID);
                dataReader.AddParameter("Hash", DnaHasher.GenerateHash(hashString));
                dataReader.Execute();
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    reviewForumID = dataReader.GetInt32NullAsZero("ReviewForumID");
                }
            }
            if (reviewForumID > 0)
            {
                _recommend = recommend;
                _incubateTime = incubateTime;
                _siteID = siteID;
                _reviewForumID = reviewForumID;

                _initialised = true;
            }
        }    
Beispiel #2
0
        /// <summary>
        /// Used to make sure that the input for the guide body parses correctly as valid XML
        /// </summary>
        /// <returns>A string that represents the XML for the guide body</returns>
        private string TryParseGuideBody()
        {
            XmlDocument bodyDoc = new XmlDocument();
            XmlNode guideBody = null;
            try
            {
                // Load the body text into an XmlDoc to parse
                bodyDoc.LoadXml(Entities.GetEntities() + "<GUIDE><BODY>" + _template.UIFields["Body"].RawValue + "</BODY></GUIDE>");
                guideBody = bodyDoc.SelectSingleNode("//GUIDE");
            }
            catch (XmlException ex)
            {
                AddErrorXml("GuideXML", "The body text contains invalid XML - " + ex.Message, _typedArticleNode);
                return "";
            }

            // Create the extra info block
            int type = _template.UIFields["Type"].ValueInt;
            ExtraInfo extraInfo = new ExtraInfo();
            extraInfo.TryCreate(type, "");

            // Now add all the non required fields to the Guide
            Dictionary<string, UIField>.Enumerator validFields = _template.UIFields.GetEnumerator();
            while (validFields.MoveNext())
            {
                // Check to see if we've got a non require field
                UIField currentField = validFields.Current.Value;
                if (!currentField.Required)
                {
                    // Add the field to the extra info
                    extraInfo.AddExtraInfoTagValue(currentField.Name, currentField.ValueString);

                    // Add the element to the 
                    XmlDocument fieldDoc = new XmlDocument();
                    try
                    {
                        // Load the text into an XmlDoc to parse
                        fieldDoc.LoadXml("<" + currentField.Name.ToUpper() + ">" + currentField.RawValue + "</" + currentField.Name.ToUpper() + ">");
                        XmlNode bodyNode = bodyDoc.SelectSingleNode("//BODY");
                        XmlNode importNode = bodyDoc.ImportNode(fieldDoc.FirstChild,true);
                        bodyDoc.DocumentElement.InsertAfter(importNode, bodyNode);
                    }
                    catch (XmlException ex)
                    {
                        AddErrorXml("GuideXML", "The " + currentField.Name + " contains invalid XML - " + ex.Message, _typedArticleNode);
                        return "";
                    }
                }
            }

            // Add the guidebody to the page
            _typedArticleNode.AppendChild(_typedArticleNode.OwnerDocument.ImportNode(guideBody,true));
            AddInside(_typedArticleNode, extraInfo);

            // Get the text to insert into the database
            return guideBody.OuterXml.ToString();
        }
Beispiel #3
0
        /// <summary>
        /// This method reads in the entry form the database and sets up all the member fields
        /// </summary>
        /// <param name="safeToCache">A flag to state whether or not this entry is safe to cache. Usually set to false whhen an error occures.</param>
        /// <param name="failingGracefully">A flag that states whether or not this method is failing gracefully.</param>
        private void GetEntryFromDataBase(ref bool safeToCache, ref bool failingGracefully)
        {
            // fetch all the lovely intellectual property from the database
            using (IDnaDataReader reader = InputContext.CreateDnaDataReader("getarticlecomponents2"))
            {
                // Add the entry id and execute
                reader.AddParameter("EntryID", EntryID);
                reader.Execute();

                // Make sure we got something back
                if (!reader.HasRows || !reader.Read())
                {
                    // Fail gracefully
                    XmlNode articleTag = AddElementTag(RootElement, "ARTICLE");
                    XmlNode guideTag = AddElementTag(articleTag, "GUIDE");
                    XmlNode bodyTag = AddElementTag(guideTag, "BODY");
                    AddElementTag(bodyTag, "NOENTRYYET");
                    failingGracefully = true;
                    safeToCache = false;
                }
                else
                {
                    // Go though the results untill we get the main article
                    do
                    {
                        if (reader.GetInt32("IsMainArticle") == 1)
                        {
                            // Now start reading in all the values for the entry
                            _h2g2ID = reader.GetInt32("h2g2ID");
                            _entryID = reader.GetInt32("EntryID");
                            _forumID = reader.GetInt32("ForumID");
                            _status = reader.GetInt32("Status");
                            _style = reader.GetInt32("Style");
                            _editor = reader.GetInt32("Editor");
                            _siteID = reader.GetInt32("SiteID");
                            _submittable = reader.GetTinyIntAsInt("Submittable");
                            _type = reader.GetInt32("Type");
                            if (!reader.IsDBNull("ModerationStatus"))
                            {
                                _moderationStatus = reader.GetTinyIntAsInt("ModerationStatus");
                            }
                            _subject = reader.GetString("subject");
                            _text = reader.GetString("text");
                            string extraInfo = reader.GetString("extrainfo");

                            _extraInfo = new ExtraInfo();
                            _extraInfo.TryCreate(_type, extraInfo);

                            if (reader.IsDBNull("Hidden"))
                            {
                                _hiddenStatus = 0;
                            }
                            else
                            {
                                _hiddenStatus = reader.GetInt32("Hidden");
                            }

                            _dateCreated = reader.GetDateTime("DateCreated");
                            _lastUpdated = reader.GetDateTime("LastUpdated");
                            _preProcessed = reader.GetInt32("PreProcessed");
                            _defaultCanRead = (reader.GetTinyIntAsInt("CanRead") > 0);
                            _defaultCanWrite = (reader.GetTinyIntAsInt("CanWrite") > 0);
                            _defaultCanChangePermissions = (reader.GetTinyIntAsInt("CanChangePermissions") > 0);

                            if (reader.IsDBNull("TopicID"))
                            {
                                _topicID = 0;
                            }
                            else
                            {
                                _topicID = reader.GetInt32("TopicID");
                            }

                            if (reader.IsDBNull("BoardPromoID"))
                            {
                                _boardPromoID = 0;
                            }
                            else
                            {
                                _boardPromoID = reader.GetInt32("BoardPromoID");
                            }

                            if (!reader.IsDBNull("StartDate"))
                            {
                                _dateRangeStart = reader.GetDateTime("StartDate");
                            }

                            if (!reader.IsDBNull("EndDate"))
                            {
                                _dateRangeEnd = reader.GetDateTime("EndDate");
                            }

                            if (reader.IsDBNull("TimeInterval"))
                            {
                                _rangeInterval = -1; // default value
                            }
                            else
                            {
                                _rangeInterval = reader.GetInt32("TimeInterval");
                            }
                        }
                    }
                    while (reader.Read());
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// This method gets all the related articles for a given article h2g2ID
        /// </summary>
        /// <param name="h2g2ID">The id of the article you want to get the related articles for</param>
        public void GetRelatedArticles(int h2g2ID)
        {
            // Create the datareader to get the articles
            using (IDnaDataReader reader = InputContext.CreateDnaDataReader("getrelatedarticles"))
            {
                reader.AddParameter("h2g2ID", h2g2ID);
                reader.AddParameter("CurrentSiteID", 0);
                reader.Execute();

                XmlNode relatedArticlesNode = AddElementTag(RootElement, "RELATEDARTICLES");

                // Add each article in turn
                while (reader.Read())
                {
                    XmlNode relatedArticleNode = AddElementTag(relatedArticlesNode, "ARTICLEMEMBER");
                    AddIntElement(relatedArticleNode, "H2G2ID", h2g2ID);
                    string articleName = reader.GetString("Subject");
                    AddTextElement((XmlElement)relatedArticleNode, "NAME", articleName);
                    if (_includeStrippedNames)
                    {
                        string strippedName = StringUtils.StrippedName(articleName);
                        AddTextElement((XmlElement)relatedArticleNode, "STRIPPEDNAME", strippedName);
                    }
                    XmlNode userNode = AddElementTag(relatedArticleNode, "EDITOR");
                    User articleEditor = new User(InputContext);
                    articleEditor.AddPrefixedUserXMLBlock(reader, reader.GetInt32("Editor"), "Editor", userNode);
                    int status = reader.GetInt32("Status");
                    XmlNode statusNode = AddTextElement((XmlElement)relatedArticleNode, "STATUS", GuideEntry.GetDescriptionForStatusValue(status));
                    AddAttribute(statusNode, "TYPE", status);
                    ExtraInfo articleExtraInfo = new ExtraInfo();
                    int articleType = reader.GetInt32("Type");
                    int articleHidden = 0;
                    if (reader.Exists("Hidden") && !reader.IsDBNull("Hidden"))
                    {
                        articleHidden = reader.GetInt32("Hidden");
                    }
                    
                    // Create and add the article extra info
                    articleExtraInfo.TryCreate(articleType, reader.GetString("ExtraInfo"));
                    AddInside(relatedArticleNode, articleExtraInfo);

                    if (reader.Exists("DateCreated"))
                    {
                        XmlNode dateCreatedNode = AddElementTag(relatedArticleNode, "DATECREATED");
                        dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true));
                    }
                    if (reader.Exists("Lastupdated"))
                    {
                        XmlNode dateCreatedNode = AddElementTag(relatedArticleNode, "LASTUPDATE");
                        dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true));
                    }

                    // NOW ADD KEYPHRASES, MEDIA ASSETS, POLLS
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// This methos gets the list of related clubs for a given article
        /// </summary>
        /// <param name="h2g2ID">The id of the article you want to get the related clubs for</param>
        public void GetRelatedClubs(int h2g2ID)
        {
            // Create a data reader to get all the clubs
            using (IDnaDataReader reader = InputContext.CreateDnaDataReader("getrelatedclubs"))
            {
                reader.AddParameter("h2g2ID", h2g2ID);
                reader.Execute();

                XmlNode relatedClubsNode = AddElementTag(RootElement, "RELATEDCLUBS");
                
                // Add each club member in turn
                while (reader.Read())
                {
                    XmlNode clubNode = AddElementTag(relatedClubsNode, "CLUBMEMBER");
                    AddIntElement(clubNode, "CLUBID", reader.GetInt32("ClubID"));
                    AddTextElement((XmlElement)clubNode, "NAME", reader.GetString("Subject"));
                    ExtraInfo clubExtraInfo = new ExtraInfo();
                    clubExtraInfo.TryCreate(reader.GetInt32("Type"),reader.GetString("ExtraInfo"));
                    clubNode.AppendChild(ImportNode(clubExtraInfo.RootElement.FirstChild));
                    if (reader.Exists("DateCreated"))
                    {
                        XmlNode dateCreatedNode = AddElementTag(clubNode, "DATECREATED");
                        dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true));
                    }
                    if (reader.Exists("Lastupdated"))
                    {
                        XmlNode dateCreatedNode = AddElementTag(clubNode, "LASTUPDATE");
                        dateCreatedNode.AppendChild(DnaDateTime.GetDateTimeAsElement(RootElement.OwnerDocument, reader.GetDateTime("DateCreated"), true));
                    }

                    // NEED TO ADD EDITOR, CLUBMEMBERS, LOCAL, EXTRAINFO, STRIPPED NAME... CHECK CLUB MEMBERS
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Sets the extra info xml from the string and the type
 /// </summary>
 /// <param name="extraInfo"></param>
 /// <param name="type"></param>
 public void SetExtraInfo(string extraInfo, int type)
 {
     _extraInfo.RemoveAll();
     _extraInfo = CreateElement("ExtraInfo");
     ExtraInfo extraInfoObject = new ExtraInfo();
     extraInfoObject.TryCreate(type, extraInfo);
     _extraInfo.AppendChild(ImportNode(extraInfoObject.RootElement.FirstChild));
 }