refactoring

This commit is contained in:
Paul Schneider 2015-10-17 19:07:54 +02:00
commit bb5e34a61d
29 changed files with 609 additions and 272 deletions

View file

@ -30,8 +30,6 @@ using System.ComponentModel.DataAnnotations;
namespace Yavsc.Model.Blogs
{
/// <summary>
/// Base post.
/// </summary>
@ -55,8 +53,6 @@ namespace Yavsc.Model.Blogs
}
}
/// <summary>
/// The posted.
/// </summary>
@ -139,12 +135,10 @@ namespace Yavsc.Model.Blogs
set;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Yavsc.Model.Blogs.BlogEntry"/> is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
public bool Visible { get; set ; }
}
}

View file

@ -0,0 +1,42 @@
//
// BasePostInfo.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Configuration;
using System.Collections.Generic;
using Yavsc.Model.Blogs;
using System.Linq;
using Yavsc.Model.Circles;
namespace Yavsc.Model.Blogs
{
/// <summary>
/// Base post info.
/// </summary>
public class BasePostInfo: BasePost {
/// <summary>
/// The intro.
/// </summary>
public string Intro;
}
}

View file

@ -18,15 +18,17 @@ namespace Yavsc.Model.Blogs
public BlogEntryCollection ()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.Blogs.BlogEntryCollection"/> class.
/// </summary>
/// <param name="items">Items.</param>
public BlogEntryCollection(IEnumerable<BlogEntry> items)
public BlogEntryCollection (IEnumerable<BlogEntry> items)
{
if (items!=null)
if (items != null)
this.AddRange (items);
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="Yavsc.Model.Blogs.BlogEntryCollection"/>.
/// </summary>
@ -57,115 +59,81 @@ namespace Yavsc.Model.Blogs
{
return this.Where (x => x.Title == title).ToArray ();
}
/// <summary>
/// Filters the current collection for a given user by its name.
/// Assumes that this user is not an author of any of these posts.
/// </summary>
/// <param name="username">Username.</param>
public BlogEntryCollection FilterFor(string username)
public BlogEntryCollection FilterFor (string username)
{
BlogEntryCollection res = new BlogEntryCollection ();
foreach (BlogEntry be in this) {
if (be.Visible &&
(be.AllowedCircles == null ||
(username!= null && CircleManager.DefaultProvider.Matches
(be.AllowedCircles,username))))
{
res.Add(be);
}
if (be.Visible &&
(be.AllowedCircles == null ||
(username != null && CircleManager.DefaultProvider.Matches
(be.AllowedCircles, username)))) {
res.Add (be);
}
}
return res;
}
/// <summary>
/// Base post info.
/// </summary>
public class BasePostInfo: BasePost {
/// <summary>
/// The intro.
/// </summary>
public string Intro;
}
/// <summary>
/// Post info.
/// </summary>
public class PostInfoByTitle : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Author;
}
/// <summary>
/// Post info by user.
/// </summary>
public class PostInfoByUser : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Title;
}
/// <summary>
/// Groups by title.
/// </summary>
public IEnumerable<IGrouping<string,PostInfoByTitle>> GroupByTitle()
public IEnumerable<IGrouping<string,PostInfoByTitle>> GroupByTitle ()
{
bool truncated;
return from be in this
orderby be.Posted descending
group
new PostInfoByTitle { Author=be.Author, Id=be.Id,
Posted=be.Posted, Modified=be.Modified,
Intro = MarkdownHelper.MarkdownIntro(be.Content, out truncated),
group
new PostInfoByTitle { Author = be.Author, Id = be.Id,
Posted = be.Posted, Modified = be.Modified,
Intro = MarkdownHelper.MarkdownIntro (be.Content, out truncated),
Visible = be.Visible,
Photo = be.Photo
}
by be.Title
into titlegroup
select titlegroup;
select titlegroup;
}
/// <summary>
/// Groups by user.
/// </summary>
/// <returns>The by user.</returns>
public IEnumerable<IGrouping<string,PostInfoByUser>> GroupByUser()
public IEnumerable<IGrouping<string,PostInfoByUser>> GroupByUser ()
{
bool truncated;
return from be in this
orderby be.Posted descending
group
new PostInfoByUser {
Title=be.Title,
Id=be.Id,
Posted=be.Posted,
Modified=be.Modified,
Intro = MarkdownHelper.MarkdownIntro(be.Content, out truncated) ,
group
new PostInfoByUser {
Title = be.Title,
Id = be.Id,
Posted = be.Posted,
Modified = be.Modified,
Intro = MarkdownHelper.MarkdownIntro (be.Content, out truncated),
Photo = be.Photo,
Visible = be.Visible
}
by be.Author
into usergroup
select usergroup;
select usergroup;
}
/// <summary>
/// Gets the titles.
/// </summary>
/// <value>The titles.</value>
public string[] Titles { get {
public string[] Titles {
get {
string[] result = this.Select (x => x.Title).Distinct ().ToArray ();
if (result == null)
return new string[0];
return result;
} }
}
}
}
}

View file

@ -19,6 +19,8 @@ namespace Yavsc.Model.Blogs
/// <param name="postid">Postid.</param>
public abstract BlogEntry GetPost (long postid);
public abstract TagInfo GetTagInfo (string tagname);
/// <summary>
/// Gets the post collection from a given user and at a given title.
/// </summary>

View file

@ -0,0 +1,44 @@
//
// PostInfoByTitle.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Configuration;
using System.Collections.Generic;
using Yavsc.Model.Blogs;
using System.Linq;
using Yavsc.Model.Circles;
namespace Yavsc.Model.Blogs
{
/// <summary>
/// Post info.
/// </summary>
public class PostInfoByTitle : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Author;
}
}

View file

@ -0,0 +1,43 @@
//
// PostInfoByUser.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Configuration;
using System.Collections.Generic;
using Yavsc.Model.Blogs;
using System.Linq;
using Yavsc.Model.Circles;
namespace Yavsc.Model.Blogs
{
/// <summary>
/// Post info by user.
/// </summary>
public class PostInfoByUser : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Title;
}
}

View file

@ -0,0 +1,60 @@
//
// TagInfo.cs
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
namespace Yavsc.Model.Blogs
{
/// <summary>
/// Tag info.
/// </summary>
public abstract class TagInfo
{
string name;
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name {
get {
return name;
}
set {
name = value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.Blogs.TagInfo"/> class.
/// </summary>
/// <param name="tagname">Tagname.</param>
public TagInfo (string tagname)
{
Name = tagname;
}
/// <summary>
/// Gets the titles.
/// </summary>
/// <value>The titles.</value>
public abstract IEnumerable<BasePostInfo> Titles { get; }
}
}