/// <summary>
        /// Adds the page to the database.
        /// </summary>
        /// <param name="model">The summary details for the page.</param>
        /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns>
        /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public PageViewModel AddPage(PageViewModel model)
        {
            try
            {
                string currentUser   = _context.CurrentUsername;
                var    currentUserId = _context.CurrentUserId;

                Page page = new Page();
                page.Title                      = model.Title;
                page.Tags                       = model.CommaDelimitedTags();
                page.CreatedBy                  = AppendIpForDemoSite(currentUser);
                page.CreatedOn                  = DateTime.UtcNow;
                page.ModifiedOn                 = DateTime.UtcNow;
                page.ModifiedBy                 = AppendIpForDemoSite(currentUser);
                page.ProjectStart               = model.ProjectStart;
                page.ProjectEnd                 = model.ProjectEnd;
                page.ProjectEstimatedTime       = model.ProjectEstimatedTime;
                page.ProjectLanguage            = model.ProjectLanguage;
                page.ProjectStatus              = model.ProjectStatus;
                page.ProjectAgileLifeCyclePhase = model.ProjectAgileLifeCyclePhase;
                page.Department                 = model.Department;
                page.FundingBoundary            = model.FundingBoundary;
                page.orgID                      = model.orgID;

                // Double check, incase the HTML form was faked.
                if (_context.IsAdmin)
                {
                    page.IsLocked = model.IsLocked;
                }


                PageContent pageContent = Repository.AddNewPage(page, model.Content, AppendIpForDemoSite(currentUser), DateTime.UtcNow, model.ProjectStart, model.ProjectEnd, model.ProjectEstimatedTime, model.ProjectStatus, Phase2Params.FromModel(model), model.ProjectLanguage, model.orgID);

                _listCache.RemoveAll();
                _pageViewModelCache.RemoveAll(); // completely clear the cache to update any reciprocal links.

                // Update the lucene index
                PageViewModel savedModel = new PageViewModel(pageContent, _markupConverter);
                try
                {
                    _searchService.Add(savedModel);
                }
                catch (SearchException)
                {
                    // TODO: log
                }

                Repository.SetContributeAutoApprovedInProject(savedModel.Id, currentUserId, savedModel.orgID);
                return(savedModel);
            }
            catch (DatabaseException e)
            {
                throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", model.Title);
            }
        }
Beispiel #2
0
        public void removeall_should_remove_listcache_keys_only()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            cache.Add("site.blah", "xyz", new CacheItemPolicy());

            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Beispiel #3
0
        public void should_not_removeall_if_cache_disabled()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = false
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            var tags1 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags1"));
            var tags2 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags2"));

            Assert.That(tags1, Is.Not.Null);
            Assert.That(tags2, Is.Not.Null);
        }
Beispiel #4
0
        public void should_removeall_items()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            Assert.That(cache.CacheItems.Count, Is.EqualTo(0));
        }
Beispiel #5
0
        /// <summary>
        /// Clears all wiki pages from the database.
        /// </summary>
        /// <returns>Redirects to the Tools action.</returns>
        public ActionResult ClearPages()
        {
            TempData["SuccessMessage"] = SiteStrings.SiteSettings_Tools_ClearDatabase_Message;
            _pageService.ClearPageTables();
            _listCache.RemoveAll();
            _pageViewModelCache.RemoveAll();

            return(RedirectToAction("Index"));
        }
Beispiel #6
0
        public ActionResult Clear()
        {
            _pageViewModelCache.RemoveAll();
            _listCache.RemoveAll();
            _siteCache.RemoveAll();
            TempData["CacheCleared"] = true;

            return(RedirectToAction("Index"));
        }
Beispiel #7
0
        /// <summary>
        /// Adds the page to the database.
        /// </summary>
        /// <param name="model">The summary details for the page.</param>
        /// <returns>A <see cref="PageViewModel"/> for the newly added page.</returns>
        /// <exception cref="DatabaseException">An databaseerror occurred while saving.</exception>
        /// <exception cref="SearchException">An error occurred adding the page to the search index.</exception>
        public PageViewModel AddPage(PageViewModel model)
        {
            try
            {
                string currentUser = _context.CurrentUsername;

                Page page = new Page();
                page.Title      = model.Title;
                page.Tags       = model.CommaDelimitedTags();
                page.CreatedBy  = AppendIpForDemoSite(currentUser);
                page.CreatedOn  = DateTime.UtcNow;
                page.ModifiedOn = DateTime.UtcNow;
                page.ModifiedBy = AppendIpForDemoSite(currentUser);

                // Double check, incase the HTML form was faked.
                if (_context.IsAdmin)
                {
                    page.IsLocked = model.IsLocked;
                }

                PageContent pageContent = Repository.AddNewPage(page, model.Content, AppendIpForDemoSite(currentUser), DateTime.UtcNow);

                _listCache.RemoveAll();
                _pageViewModelCache.RemoveAll();                 // completely clear the cache to update any reciprocal links.

                // Update the lucene index
                PageViewModel savedModel = new PageViewModel(pageContent, _markupConverter);
                try
                {
                    _searchService.Add(savedModel);
                }
                catch (SearchException)
                {
                    // TODO: log
                }

                return(savedModel);
            }
            catch (DatabaseException e)
            {
                throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", model.Title);
            }
        }
Beispiel #8
0
        public void RemoveAll_Should_Remove_ListCache_Keys_Only()
        {
            // Arrange
            CacheMock cache = new CacheMock();
            cache.Add("site.blah", "xyz", new CacheItemPolicy());

            ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true };

            List<string> tagCacheItems1 = new List<string>() { "1", "2" };
            List<string> tagCacheItems2 = new List<string>() { "1", "2" };
            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
        public ActionResult Edit(PluginViewModel model)
        {
            TextPlugin plugin = _pluginFactory.GetTextPlugin(model.Id);

            if (plugin == null)
            {
                return(RedirectToAction("Index"));
            }

            // Update the plugin settings with the values from the summary
            plugin.Settings.IsEnabled = model.IsEnabled;

            foreach (SettingValue summaryValue in model.SettingValues)
            {
                SettingValue pluginValue = plugin.Settings.Values.FirstOrDefault(x => x.Name == summaryValue.Name);
                if (pluginValue != null)
                {
                    pluginValue.Value = summaryValue.Value;
                }
            }

            // Update the plugin last saved date - this is important for 304 modified tracking
            // when the browser caching option is turned on.
            SiteSettings settings = SettingsService.GetSiteSettings();

            settings.PluginLastSaveDate = DateTime.UtcNow;
            SettingsViewModel settingsViewModel = new SettingsViewModel(ApplicationSettings, settings);

            SettingsService.SaveSiteSettings(settingsViewModel);

            // Save and clear the cached settings
            _settingsRepository.SaveTextPluginSettings(plugin);
            _siteCache.RemovePluginSettings(plugin);

            // Clear all other caches if the plugin has been enabled or disabled.
            _viewModelCache.RemoveAll();
            _listCache.RemoveAll();

            return(RedirectToAction("Index"));
        }
Beispiel #10
0
		public void Should_RemoveAll_Items()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = true };

			List<string> tagCacheItems1 = new List<string>() { "1", "2" };
			List<string> tagCacheItems2 = new List<string>() { "1", "2" };
			AddToCache(cache, "all.tags1", tagCacheItems1);
			AddToCache(cache, "all.tags2", tagCacheItems2);

			ListCache listCache = new ListCache(settings, cache);

			// Act
			listCache.RemoveAll();

			// Assert
			Assert.That(cache.CacheItems.Count, Is.EqualTo(0));
		}
Beispiel #11
0
		public void Should_Not_RemoveAll_If_Cache_Disabled()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings settings = new ApplicationSettings() { UseObjectCache = false };

			List<string> tagCacheItems1 = new List<string>() { "1", "2" };
			List<string> tagCacheItems2 = new List<string>() { "1", "2" };
			AddToCache(cache, "all.tags1", tagCacheItems1);
			AddToCache(cache, "all.tags2", tagCacheItems2);

			ListCache listCache = new ListCache(settings, cache);

			// Act
			listCache.RemoveAll();

			// Assert
			var tags1 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags1"));
			var tags2 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags2"));

			Assert.That(tags1, Is.Not.Null);
			Assert.That(tags2, Is.Not.Null);
		}