Esempio n. 1
0
        protected void Application_Start(object sender, EventArgs e)
        {
            //System.Diagnostics.Debugger.Launch();
            if (ConfigurationManager.AppSettings["MaintenanceMode"] == "1")
            {//do nothing if in maintenance
                return;
            }

            Statistics.InitialiseIfEmpty(null, false);
            dnaDiagnostics = new DnaDiagnostics(RequestIdGenerator.GetNextRequestId(), DateTime.Now);
            connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
            readerCreator = new DnaDataReaderCreator(connectionString, dnaDiagnostics);

            try
            {
                emailServerAddress = ConfigurationManager.AppSettings["EmailServer"];
            }
            catch
            {
                dnaDiagnostics.WriteWarningToLog("BBC.Dna.Services.Application_Start", "Unable to find config email server address - no emails will be sent!");
            }

            try
            {
                fileCacheFolder = ConfigurationManager.AppSettings["FileCacheFolder"];
            }
            catch
            {
                fileCacheFolder = Environment.GetEnvironmentVariable("Temp");
                dnaDiagnostics.WriteWarningToLog("BBC.Dna.Services.Application_Start", "Unable to find config file cache folder - Defaulting to the system temp folder!");
            }

            ICacheManager cacheManager = null;
            try
            {
                cacheManager = CacheFactory.GetCacheManager("Memcached");
            }
            catch (Exception error)
            {
                dnaDiagnostics.WriteWarningToLog("BBC.Dna.Services.Application_Start", "Unable to use memcached cachemanager - falling back to static inmemory");
                dnaDiagnostics.WriteExceptionToLog(error);
                cacheManager = new StaticCacheManager();
            }


            siteList = new SiteList(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var bannedEmails = new BannedEmails(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var userGroups = new UserGroups(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var profanityFilter = new ProfanityFilter(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var moderationClasses = new ModerationClassListCache(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            BBC.Dna.Objects.SmileyTranslator.LoadSmileys(readerCreator);
        }
        public void GetAllModerationClassesFromDb_NoReads_ReturnsEmptyList()
        {
            var reader = Mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(false);

            var readerCreator = Mocks.DynamicMock<IDnaDataReaderCreator>();
            readerCreator.Stub(x => x.CreateDnaDataReader("getmoderationclasslist")).Return(reader);

            var cache = Mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains("")).Constraints(Is.Anything()).Return(false);
            var diag = Mocks.DynamicMock<IDnaDiagnostics>();

            Mocks.ReplayAll();

            var actual = new ModerationClassListCache(readerCreator, diag, cache, null, null); ;
            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.GetObjectFromCache().ModClassList.Count);
        }
Esempio n. 3
0
		/// <summary>
		/// Designed to be called once at application Start-up
		/// </summary>
		/// <param name="rootPath">The folder that's the root of the application</param>
		public static void OnDnaStartup(string rootPath)
		{
#if DEBUG
            /**************************************
             *                                    *
             *    DEBUGGING FROM THE WORD GO!     *
             *                                    *
             **************************************/
            // System.Diagnostics.Debugger.Launch();
#endif

			_appContext = new AppContext(rootPath);

            _dnaCacheManager = CacheFactory.GetCacheManager();
		    

			DnaDiagnostics.Initialise(TheAppContext.Config.InputLogFilePath, "DNALOG");
#if DEBUG
			DnaDiagnostics.WriteHeader("OnDnaStartup - DEBUG");
#else
                DnaDiagnostics.WriteHeader("OnDnaStartup - RELEASE");
#endif

			Statistics.InitialiseIfEmpty(/*TheAppContext*/);

            //load the smiley list
            SmileyTranslator.LoadSmileys(ReaderCreator);

            ICacheManager cacheMemcachedManager = null;
            try
            {
                cacheMemcachedManager = CacheFactory.GetCacheManager("Memcached");
            }
            catch (Exception error)
            {
                DnaDiagnostics.Default.WriteWarningToLog("OnDnaStartup", "Unable to use memcached cachemanager - falling back to static inmemory");
                DnaDiagnostics.Default.WriteExceptionToLog(error);
                cacheMemcachedManager = new StaticCacheManager();
            }

            //new signal objects below here
            _appContext.TheSiteList = new SiteList(AppContext.ReaderCreator, DnaDiagnostics.Default, cacheMemcachedManager, TheAppContext._dnaConfig.RipleyServerAddresses, TheAppContext._dnaConfig.DotNetServerAddresses);
            var bannedEmails = new BannedEmails(AppContext.ReaderCreator, DnaDiagnostics.Default, cacheMemcachedManager, TheAppContext._dnaConfig.RipleyServerAddresses, TheAppContext._dnaConfig.DotNetServerAddresses);
            var userGroups = new UserGroups(AppContext.ReaderCreator, DnaDiagnostics.Default, cacheMemcachedManager, TheAppContext._dnaConfig.RipleyServerAddresses, TheAppContext._dnaConfig.DotNetServerAddresses);
            var profanityFilter = new ProfanityFilter(AppContext.ReaderCreator, DnaDiagnostics.Default, cacheMemcachedManager, TheAppContext._dnaConfig.RipleyServerAddresses, TheAppContext._dnaConfig.DotNetServerAddresses);
            var moderationClasses = new ModerationClassListCache(AppContext.ReaderCreator, DnaDiagnostics.Default, cacheMemcachedManager, TheAppContext._dnaConfig.RipleyServerAddresses, TheAppContext._dnaConfig.DotNetServerAddresses);

            // Setup the banned user agents list
            InitialiseBannedUserAgents();
		}
        public static ModerationClassListCache InitialiseClasses()
        {
            MockRepository _mocks = new MockRepository();
            var cacheObj = GetModerationClassList();

            var cache = _mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains(ModerationClassListCache.GetCacheKey("LASTUPDATE"))).Return(false);
            cache.Stub(x => x.Contains(ModerationClassListCache.GetCacheKey())).Return(true);
            cache.Stub(x => x.GetData(ModerationClassListCache.GetCacheKey())).Return(cacheObj);

            var reader = _mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(false);


            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getmoderationclasslist")).Return(reader);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var tmp =  new ModerationClassListCache(creator, diag, cache, null, null);
            SignalHelper.AddObject(typeof(ModerationClassListCache), tmp);
            return tmp;
        }
        public void TermsFilterImportPage_AddSingleReferTermToAll_PassesValidation()
        {
            //refresh mod classes
            SendSignal();

            //set up data
            var reason = "this has a reason";
            var term = "potato";
            var action = TermAction.Refer;

            var moderationClasses = new ModerationClassListCache(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);


            var moderationClassList = moderationClasses.GetObjectFromCache();

            var termsLists = new TermsLists();
            foreach (var modClass in moderationClassList.ModClassList)
            {
                var termsList = new TermsList { ModClassId = modClass.ClassId };
                termsList.Terms.Add(new TermDetails { Value = term, Action = action });
                termsLists.Termslist.Add(termsList);
            }
            Assert.AreNotEqual(0, termsLists.Termslist.Count);

            var postParams = new Queue<KeyValuePair<string, string>>();
            postParams.Enqueue(new KeyValuePair<string, string>("reason", reason));
            postParams.Enqueue(new KeyValuePair<string, string>("termtext", term));
            postParams.Enqueue(new KeyValuePair<string, string>("action_modclassid_all", action.ToString()));



            var request = new DnaTestURLRequest(SiteName) { UseEditorAuthentication = true };
            request.SetCurrentUserSuperUser();
            request.RequestPage("termsfilterimport?action=UPDATETERMS&skin=purexml", postParams);
            ValidateResponse(request);

            //check correct error message returned
            ValidateOkResult(request, "TermsUpdateSuccess", "Term updated successfully.");
            //check history table
            termsLists = ValidateHistory(request, reason, termsLists);
            //Check that all terms are actually associated
            ValidateTermAssociations(request, termsLists);

        }