本文整理汇总了C#中Roadkill.Core.Mvc.ViewModels.PageViewModel类的典型用法代码示例。如果您正苦于以下问题:C# PageViewModel类的具体用法?C# PageViewModel怎么用?C# PageViewModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PageViewModel类属于Roadkill.Core.Mvc.ViewModels命名空间,在下文中一共展示了PageViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
/// <summary>
/// Adds the specified page to the search index.
/// </summary>
/// <param name="model">The page to add.</param>
/// <exception cref="SearchException">An error occured with the lucene.net IndexWriter while adding the page to the index.</exception>
public virtual void Add(PageViewModel model)
{
try
{
EnsureDirectoryExists();
StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
using (IndexWriter writer = new IndexWriter(FSDirectory.Open(new DirectoryInfo(IndexPath)), analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED))
{
Document document = new Document();
document.Add(new Field("id", model.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("content", model.Content, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contentsummary", GetContentSummary(model), Field.Store.YES, Field.Index.NO));
document.Add(new Field("title", model.Title, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("tags", model.SpaceDelimitedTags(), Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("createdby", model.CreatedBy, Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("createdon", model.CreatedOn.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("contentlength", model.Content.Length.ToString(), Field.Store.YES, Field.Index.NO));
writer.AddDocument(document);
writer.Optimize();
}
}
catch (Exception ex)
{
if (!ApplicationSettings.IgnoreSearchIndexErrors)
throw new SearchException(ex, "An error occured while adding page '{0}' to the search index", model.Title);
}
}
示例2: UpdateHomePage
/// <summary>
/// Updates the home page item in the cache.
/// </summary>
/// <param name="item">The updated homepage item.</param>
public void UpdateHomePage(PageViewModel item)
{
if (!_applicationSettings.UseObjectCache)
return;
_cache.Remove(CacheKeys.HomepageKey());
_cache.Add(CacheKeys.HomepageKey(), item, new CacheItemPolicy());
}
示例3: PageContent_Constructor_Should_Throw_Exception_When_MarkupConverter_IsNull
public void PageContent_Constructor_Should_Throw_Exception_When_MarkupConverter_IsNull()
{
// Arrange
PageContent content = new PageContent();
content.Page = new Page();
// Act + Assert
PageViewModel model = new PageViewModel(content, null);
}
示例4: empty_constructor_should_fill_property_defaults
public void empty_constructor_should_fill_property_defaults()
{
// Arrange + act
PageViewModel model = new PageViewModel();
// Assert
Assert.That(model.IsCacheable, Is.True);
Assert.That(model.PluginHeadHtml, Is.EqualTo(""));
Assert.That(model.PluginFooterHtml, Is.EqualTo(""));
}
示例5: IsNew_Should_Be_True_When_Id_Is_Not_Set
public void IsNew_Should_Be_True_When_Id_Is_Not_Set()
{
// Arrange
PageViewModel model = new PageViewModel();
// Act
model.Id = 0;
// Assert
Assert.That(model.IsNew, Is.True);
}
示例6: Content_Should_Be_Empty_And_Not_Null_When_Set_To_Null
public void Content_Should_Be_Empty_And_Not_Null_When_Set_To_Null()
{
// Arrange
PageViewModel model = new PageViewModel();
// Act
model.Content = null;
// Assert
Assert.That(model.Content, Is.EqualTo(string.Empty));
}
示例7: VerifyRawTags_With_Ok_Characters_Should_Succeed
public void VerifyRawTags_With_Ok_Characters_Should_Succeed()
{
// Arrange
PageViewModel model = new PageViewModel();
model.RawTags = "tagone, anothertag, tag-2, code, c++";
// Act
ValidationResult result = PageViewModel.VerifyRawTags(model, null);
// Assert
Assert.That(result, Is.EqualTo(ValidationResult.Success));
}
示例8: VerifyRawTags_With_Empty_String_Should_Succeed
public void VerifyRawTags_With_Empty_String_Should_Succeed()
{
// Arrange
PageViewModel model = new PageViewModel();
model.RawTags = "";
// Act
ValidationResult result = PageViewModel.VerifyRawTags(model, null);
// Assert
Assert.That(result, Is.EqualTo(ValidationResult.Success));
}
示例9: VerifyRawTags_With_Bad_Characters_Should_Fail
public void VerifyRawTags_With_Bad_Characters_Should_Fail()
{
// Arrange
PageViewModel model = new PageViewModel();
model.RawTags = "&&+some,tags,only,^^,!??malicious,#monkey,would,use";
// Act
ValidationResult result = PageViewModel.VerifyRawTags(model, null);
// Assert
Assert.That(result, Is.Not.EqualTo(ValidationResult.Success));
}
示例10: CommaDelimitedTags_Should_Return_Tags_In_Csv_Form
public void CommaDelimitedTags_Should_Return_Tags_In_Csv_Form()
{
// Arrange
PageViewModel model = new PageViewModel();
model.RawTags = "tag1, tag2, tag3";
// Act
string joinedTags = model.CommaDelimitedTags();
// Assert
Assert.That(joinedTags, Is.EqualTo("tag1,tag2,tag3"));
}
示例11: Add
// <summary>
/// Adds an item to the cache.
/// </summary>
/// <param name="id">The page's Id.</param>
/// <param name="version">The pages content's version.</param>
/// <param name="item">The page.</param>
public void Add(int id, int version, PageViewModel item)
{
if (!_applicationSettings.UseObjectCache)
return;
if (!item.IsCacheable)
return;
string key = CacheKeys.PageViewModelKey(id, version);
_cache.Add(key, item, new CacheItemPolicy());
Log("Added key {0} to cache [Id={1}, Version{2}]", key, id, version);
}
示例12: Post_Should_Add_Page
public void Post_Should_Add_Page()
{
// Arrange
PageViewModel model = new PageViewModel();
model.Title = "Hello world";
model.RawTags = "tag1, tag2";
model.Content = "Some content";
// Act
_pagesController.Post(model);
// Assert
Assert.That(_pageService.AllPages().Count(), Is.EqualTo(1));
}
示例13: AddPage
/// <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);
page.ProjectStart = model.ProjectStart;
page.ProjectEnd = model.ProjectEnd;
page.ProjectEstimatedTime = model.ProjectEstimatedTime;
page.ProjectLanguage = model.ProjectLanguage;
page.ProjectStatus = model.ProjectStatus;
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, 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
}
return savedModel;
}
catch (DatabaseException e)
{
throw new DatabaseException(e, "An error occurred while adding page '{0}' to the database", model.Title);
}
}
示例14: put_should_update_page
public void put_should_update_page()
{
// Arrange
PageContent pageContent = AddPage("test", "this is page 1");
PageViewModel viewModel = new PageViewModel(pageContent.Page);
viewModel.Title = "New title";
WebApiClient apiclient = new WebApiClient();
// Act
WebApiResponse response = apiclient.Put<PageViewModel>("Pages/Put", viewModel);
// Assert
IPageRepository repository = GetRepository();
Page page = repository.AllPages().FirstOrDefault();
Assert.That(page.Title, Is.EqualTo("New title"), response);
}
示例15: CompareVersions
/// <summary>
/// Compares a page version to the previous version.
/// </summary>
/// <param name="mainVersionId">The id of the version to compare</param>
/// <returns>Returns a IEnumerable of two versions, where the 2nd item is the previous version.
/// If the current version is 1, or a previous version cannot be found, then the 2nd item will be null.</returns>
/// <exception cref="HistoryException">An database error occurred while comparing the two versions.</exception>
public IEnumerable<PageViewModel> CompareVersions(Guid mainVersionId)
{
try
{
List<PageViewModel> versions = new List<PageViewModel>();
PageContent mainContent = Repository.GetPageContentById(mainVersionId);
versions.Add(new PageViewModel(mainContent, _markupConverter));
if (mainContent.VersionNumber == 1)
{
versions.Add(null);
}
else
{
PageViewModel model = _pageViewModelCache.Get(mainContent.Page.Id, mainContent.VersionNumber - 1);
if (model == null)
{
PageContent previousContent = Repository.GetPageContentByPageIdAndVersionNumber(mainContent.Page.Id, mainContent.VersionNumber - 1);
if (previousContent == null)
{
model = null;
}
else
{
model = new PageViewModel(previousContent, _markupConverter);
_pageViewModelCache.Add(mainContent.Page.Id, mainContent.VersionNumber - 1, model);
}
}
versions.Add(model);
}
return versions;
}
catch (ArgumentNullException ex)
{
throw new HistoryException(ex, "An ArgumentNullException occurred comparing the version history for version id {0}", mainVersionId);
}
catch (DatabaseException ex)
{
throw new HistoryException(ex, "A HibernateException occurred comparing the version history for version id {0}", mainVersionId);
}
}