Beispiel #1
0
 public void Test2TestSiteID()
 {
     Console.WriteLine("Test2TestSiteID");
     Assert.AreEqual(_testSite.SiteID, 1);
     SiteXmlBuilder siteXml = new SiteXmlBuilder(_inputcontext);
     XmlNode testnode = siteXml.GenerateXml(null, _testSite);
     DnaXmlValidator validator = new DnaXmlValidator(testnode.OuterXml, _schemaUri);
     validator.Validate();
     if (testnode != null)
     {
         Assert.AreEqual(testnode.Attributes["ID"].InnerText, "1", "Site ID Attribute Xml incorrect");
     }
 }
Beispiel #2
0
 public void Test3TestSiteName()
 {
     Console.WriteLine("Test3TestSiteName");
     Assert.AreEqual(_testSite.SiteName, "h2g2");
     SiteXmlBuilder siteXml = new SiteXmlBuilder(_inputcontext);
     XmlNode testnode = siteXml.GenerateXml(null, _testSite);
     DnaXmlValidator validator = new DnaXmlValidator(testnode.OuterXml, _schemaUri);
     validator.Validate();
     if (testnode != null)
     {
         Assert.AreEqual(testnode.SelectSingleNode("NAME").InnerText, "h2g2", "Site Name Xml incorrect");
     }
 }
        /// <summary>
        /// Used to process the current request.
        /// </summary>
        public override void ProcessRequest()
        {
            //Assemble page parts.
            RootElement.RemoveAll();
            if (InputContext.ViewingUser.IsSuperUser == false && InputContext.ViewingUser.IsEditor == false)
            {
                SerialiseAndAppend(new Error { Type = "Access Denied", ErrorMessage = "Access denied" }, "");
                return;
            }
            GetQueryParameters();

            if (_modClassId == 0)
            {
                if(_siteId == 0)
                {
                    AddErrorXml("NoSites", "No site data available", null);
                return;
                }
                //get moderator stats
                _modClassId = InputContext.TheSiteList.GetSite(_siteId).ModClassID;
            }
            ModerationClass modClass = ModerationClassListCache.GetObject().ModClassList.FirstOrDefault(x => x.ClassId == _modClassId);

            ModifyUserModerationStatus(modClass);

            var userRep = UserReputation.GetUserReputation(AppContext.ReaderCreator, modClass, _userId);
            SerialiseAndAppend(userRep, "");

            var userEventList = UserEventList.GetUserEventList(modClass, _startIndex,
                _itemsPerPage, _startDate, _endDate, AppContext.ReaderCreator, _userId);
            SerialiseAndAppend(userEventList, "");

            //get sitelist
            SiteXmlBuilder siteXml = new SiteXmlBuilder(InputContext);
            siteXml.CreateXmlSiteList(InputContext.TheSiteList);
            RootElement.AppendChild(ImportNode(siteXml.RootElement.FirstChild));


            SerialiseAndAppend(SiteTypeEnumList.GetSiteTypes(), "");


        }
Beispiel #4
0
	protected void OutputSitenameOptions()
	{
        SiteXmlBuilder siteXml = new SiteXmlBuilder(_basePage);
        XmlNode sites = siteXml.GenerateAllSitesXml(_basePage.TheSiteList);
		XmlNodeList nodes = sites.SelectNodes("//SITE-LIST/SITE/NAME");
		foreach (XmlNode namenode in nodes)
		{
			Response.Write(string.Format("<option value=\"{0}\">{0}</option>", namenode.InnerText));
		}
		//Site[] sites = _basePage.TheSiteList.GetSites();
		//foreach (Site site in sites)
		//{
		//    Response.Write(string.Format("<option value=\"{0}\">{0}</option>", site.SiteName));
		//}
	}
Beispiel #5
0
 public void TestFTestSiteModerationStatus()
 {
     Console.WriteLine("TestFTestSiteModerationStatus");
     Assert.AreEqual((int)_testSite.ModerationStatus, 0);
     SiteXmlBuilder siteXml = new SiteXmlBuilder(_inputcontext);
     XmlNode testnode = siteXml.GenerateXml(null, _testSite);
     DnaXmlValidator validator = new DnaXmlValidator(testnode.OuterXml, _schemaUri);
     validator.Validate();
     if (testnode != null)
     {
         Assert.AreEqual(testnode.SelectSingleNode("MODERATIONSTATUS").InnerText, "0", "Site moderation status Xml incorrect");
     }
 }
Beispiel #6
0
        public void TestGTestSiteOptions()
        {
            Console.WriteLine("TestGTestSiteOptions");
            
            using (FullInputContext fullInputContext = new FullInputContext(""))
            {
                SiteList siteList = new SiteList(fullInputContext.ReaderCreator, fullInputContext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);

                SiteXmlBuilder siteXml = new SiteXmlBuilder(fullInputContext);
                XmlNode siteOptionsNode = siteXml.GetSiteOptionListForSiteXml(1, siteList);
                DnaXmlValidator validator = new DnaXmlValidator(siteOptionsNode.OuterXml, "SiteOptions.xsd");
                validator.Validate();
                XmlNode siteOptionNode = siteOptionsNode.SelectSingleNode("/DNAROOT/SITEOPTIONS/SITEOPTION");
                Assert.IsTrue(siteOptionNode != null, "Can't find any SITEOPTION nodes");

                XmlAttributeCollection attribs = siteOptionNode.Attributes;

                int globalAttCount = 0;
                foreach (XmlAttribute a in attribs)
                {
                    if (a.Name == "GLOBAL")
                    {
                        globalAttCount++;
                    }
                    else
                    {
                        Assert.Fail("Unknown attribute on SITEOPTION tag (" + a.Name + ")");
                    }
                }
                Assert.IsTrue(globalAttCount == 1, "There should be 1 GLOBAL attribute on the SITEOPTION tag");
            }
        }
Beispiel #7
0
        public void TestDTestScheduledClosedXml()
        {
            Console.WriteLine("TestDTestScheduledClosedXml");
            SiteXmlBuilder siteXml = new SiteXmlBuilder(_inputcontext);
            XmlNode testnode = siteXml.GenerateXml(null, _testSite);
            DnaXmlValidator validator = new DnaXmlValidator(testnode.OuterXml, _schemaUri);
            validator.Validate();
            if (testnode != null)
            {
                string testval = String.Empty;
                if (_testSite.IsSiteScheduledClosed(DateTime.Now))
                {
                    testval = "1";
                }
                else
                {
                    testval = "0";
                }

                Assert.AreEqual(testnode.SelectSingleNode("SITECLOSED/@SCHEDULEDCLOSED").InnerText, testval, "Site Scheduled Close does not match Xml");
            }
        }
Beispiel #8
0
 public void Test8TestEmergencyClose()
 {
     Console.WriteLine("Test8TestEmergencyClose");
     _testSite.IsEmergencyClosed = true;
     Assert.AreEqual(_testSite.IsEmergencyClosed, true, "Emergency Closed field failed to set");
     SiteXmlBuilder siteXml = new SiteXmlBuilder(_inputcontext);
     XmlNode testnode = siteXml.GenerateXml(null, _testSite);
     DnaXmlValidator validator = new DnaXmlValidator(testnode.OuterXml, _schemaUri);
     validator.Validate();
     if (testnode != null)
     {
         Assert.AreEqual(testnode.SelectSingleNode("SITECLOSED/@EMERGENCYCLOSED").InnerText, "1", "Site Emergency Closed Xml incorrect");
     }
 }
Beispiel #9
0
        public void Test7TestAddOpenCloseTimesTest()
        {
            Console.WriteLine("Test7TestAddOpenCloseTimesTest");
            _testSite.AddOpenCloseTime(2, 23, 55, 1);
            _testSite.AddOpenCloseTime(2, 1, 5, 0);

            SiteXmlBuilder siteXml = new SiteXmlBuilder(_inputcontext);
            XmlNode testnode = siteXml.GenerateXml(null, _testSite);
            DnaXmlValidator validator = new DnaXmlValidator(testnode.OuterXml, _schemaUri);
            validator.Validate();
            Assert.IsTrue(testnode != null, "Failed to generate xml for test site!!!");
            if (testnode != null)
            {
                Assert.AreEqual(testnode.SelectSingleNode("OPENCLOSETIMES/OPENCLOSETIME").Attributes["DAYOFWEEK"].Value, "2", "Start Day Of week incorrect");
                Assert.AreEqual(testnode.SelectSingleNode("OPENCLOSETIMES/OPENCLOSETIME/OPENTIME/HOUR").InnerText, "1", "Start Hour Of week incorrect");
                Assert.AreEqual(testnode.SelectSingleNode("OPENCLOSETIMES/OPENCLOSETIME/OPENTIME/MINUTE").InnerText, "5", "Start Minute Of week incorrect");
                Assert.AreEqual(testnode.SelectSingleNode("OPENCLOSETIMES/OPENCLOSETIME/CLOSETIME/HOUR").InnerText, "23", "End Hour Of week incorrect");
                Assert.AreEqual(testnode.SelectSingleNode("OPENCLOSETIMES/OPENCLOSETIME/CLOSETIME/MINUTE").InnerText, "55", "End Minute Of week incorrect");
            }
        }
Beispiel #10
0
        /// <summary>
        /// Create an Xml representation of the site list that the given user is an editor for
        /// </summary>
        /// <param name="userID">User to get groups for</param>
        /// <param name="isSuperUser">Whether the user is a superuser or not</param>
        /// <param name="context">The context it's called in</param>
        /// <returns>XmlElement pointing to the sites the user is editor of.</returns>
        public static XmlElement GetSitesUserIsEditorOfXML(int userID, bool isSuperUser, IInputContext context)
        {
            /*
             * <EDITOR-SITE-LIST>
             *  <SITE-LIST>
                    <SITE ID="17">
                        <NAME>1xtra</NAME>
                        <DESCRIPTION>1xtra messageboard</DESCRIPTION>
                        <SHORTNAME>1xtra</SHORTNAME>
                    </SITE>
                    <SITE ID="3">
                        <NAME>360</NAME>
                        <DESCRIPTION>360</DESCRIPTION>
                        <SHORTNAME>360</SHORTNAME>
                    </SITE>
             *  </SITE-LIST>
             * </EDITOR-SITE-LIST>
             */

            XmlDocument editorGroupsDoc = new XmlDocument();
            XmlElement root = editorGroupsDoc.CreateElement("EDITOR-SITE-LIST");

            if (isSuperUser)
            {
                SiteXmlBuilder siteXml = new SiteXmlBuilder(context);
                root.AppendChild(ImportNode(editorGroupsDoc, siteXml.GenerateAllSitesXml(context.TheSiteList).FirstChild));
            }
            else
            {
				XmlElement siteList = editorGroupsDoc.CreateElement("SITE-LIST");
               
                var siteIds = UserGroups.GetObject().GetSitesUserIsMemberOf(userID, "editor");


                foreach (int siteID in siteIds)
				{
						XmlElement siteXml = editorGroupsDoc.CreateElement("SITE");

						ISite site = context.TheSiteList.GetSite(siteID);

						siteXml.SetAttribute("ID", siteID.ToString());

						AddTextElement(siteXml, "NAME", site.SiteName);
						AddTextElement(siteXml, "DESCRIPTION", site.Description);
						AddTextElement(siteXml, "SHORTNAME", site.ShortName);
						AddTextElement(siteXml, "SSOSERVICE", site.SSOService);

						siteList.AppendChild(siteXml);

				}
                root.AppendChild(siteList);
            }
            return root;
        }
Beispiel #11
0
        /// <summary>
        /// Used to process the current request.
        /// </summary>
        public override void ProcessRequest()
        {
            //Assemble page parts.
            RootElement.RemoveAll();
            if (InputContext.ViewingUser.IsSuperUser == false && InputContext.ViewingUser.IsEditor == false)
            {
                SerialiseAndAppend(new Error { Type = "Access Denied", ErrorMessage = "Access denied" }, "");
                return;
            }
            GetQueryParameters();

            

            //get site stats
            DateTime startDate = DateTime.MinValue, endDate = DateTime.MinValue;
            GetDateRange(_days, ref startDate, ref endDate);

            //get moderator stats
            var moderatorInfo = ModeratorInfo.GetModeratorInfo(AppContext.ReaderCreator, _userId, InputContext.TheSiteList);
            var modStats = new ModStats(){Moderator = moderatorInfo};
            SiteSummaryStats stats;
            if (_siteId != 0)
            {
                modStats = ModStats.FetchModStatsBySite(AppContext.ReaderCreator, _userId, _siteId,
                    moderatorInfo, true, true);

                stats = SiteSummaryStats.GetStatsBySite(AppContext.ReaderCreator, _siteId, startDate, endDate);
            }
            else
            {
                modStats = ModStats.FetchModStatsBySiteType(AppContext.ReaderCreator, _userId, _type,
                   moderatorInfo, true, true);

                var statsUserId = _userId;
                if (InputContext.ViewingUser.IsSuperUser && statsUserId == InputContext.ViewingUser.UserID)
                {//use default user
                    statsUserId = 0;
                }

                stats = SiteSummaryStats.GetStatsByType(AppContext.ReaderCreator, _type, statsUserId, startDate, endDate);
            }
            SerialiseAndAppend(modStats, "");
            SerialiseAndAppend(stats, "");

            //check if only one site - then redirect note looking for 2 as all editors are editors of the moderation site for access...
            if (moderatorInfo.Sites.Count == 2 && _siteId == 0)
            {
                RedirectToSoleSite(moderatorInfo);
                return;
            }

            //get sitelist
            SiteXmlBuilder siteXml = new SiteXmlBuilder(InputContext);
            siteXml.CreateXmlSiteList(InputContext.TheSiteList);
            RootElement.AppendChild(ImportNode(siteXml.RootElement.FirstChild));


            SerialiseAndAppend(SiteTypeEnumList.GetSiteTypes(), "");


        }