Subboards implemented; 'Common' context initial commit; UserSettings initial commit

main
Inga 🏳‍🌈 15 years ago
parent c572207c2a
commit bab06318a4
  1. 2
      Builder/IISMainHandler/build.txt
  2. 5
      Common/Common.csproj
  3. 13
      Common/IOutputParams.cs
  4. 25
      Common/UserContext.cs
  5. 9
      Common/UserSettingsGateway.cs
  6. 22
      Common/dataobjects/AnonymousUserSettings.cs
  7. 67
      Common/dataobjects/Board.cs
  8. 4
      Common/dataobjects/Category.cs
  9. 18
      Common/dataobjects/IUserSettings.cs
  10. 8
      Core/Util.cs
  11. 2
      IISMainHandler/TemplateEngine.cs
  12. 16
      IISMainHandler/WebContext.cs
  13. 7
      IISMainHandler/designs/Classic.cs
  14. 2
      IISMainHandler/designs/IDesign.cs
  15. 7
      IISMainHandler/designs/Lite.cs
  16. 13
      IISMainHandler/handlers/AbstractGetHandler.cs
  17. 12
      IISMainHandler/handlers/BoardsHandler.cs
  18. 2
      IISMainHandler/handlers/RootHandler.cs
  19. 17
      templates/Full/Boards.xslt

@ -48,8 +48,13 @@
<Compile Include="Config.cs" />
<Compile Include="dataobjects\Board.cs" />
<Compile Include="dataobjects\Category.cs" />
<Compile Include="dataobjects\IUserSettings.cs" />
<Compile Include="dataobjects\AnonymousUserSettings.cs" />
<Compile Include="IOutputParams.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlObject.cs" />
<Compile Include="UserContext.cs" />
<Compile Include="UserSettingsGateway.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common {
public interface IOutputParams {
string preprocessBodyIntermediate(string bodyIntermediate);
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common {
abstract public class UserContext {
public Common.Config config {
get {
return Common.Config.instance;
}
}
abstract public IOutputParams outputParams {
get;
}
abstract public dataobjects.IUserSettings userSettings {
get;
}
}
}

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common {
class UserSettingsGateway {
}
}

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common.dataobjects {
public class AnonymousUserSettings : IUserSettings {
public int threadsPerPage {
get {
return 20;
}
}
public int postsPerPage {
get {
return 40;
}
}
}
}

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FLocal.Core;
using FLocal.Core.DB;
namespace FLocal.Common.dataobjects {
public class Board : SqlObject<Board> {
@ -17,6 +19,7 @@ namespace FLocal.Common.dataobjects {
public const string FIELD_TOTALTHREADS = "TotalThreads";
public const string FIELD_NAME = "Name";
public const string FIELD_DESCRIPTION = "Comment";
public const string FIELD_PARENTBOARDID = "ParentBoardId";
public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } }
@ -32,8 +35,8 @@ namespace FLocal.Common.dataobjects {
}
}
private int _categoryId;
public int categoryId {
private int? _categoryId;
public int? categoryId {
get {
this.LoadIfNotLoaded();
return this._categoryId;
@ -41,7 +44,7 @@ namespace FLocal.Common.dataobjects {
}
public Category category {
get {
return Category.LoadById(this.categoryId);
return Category.LoadById(this.categoryId.Value);
}
}
@ -85,22 +88,54 @@ namespace FLocal.Common.dataobjects {
}
}
private int? _parentBoardId;
public int? parentBoardId {
get {
this.LoadIfNotLoaded();
return this._parentBoardId;
}
}
protected override void doFromHash(Dictionary<string, string> data) {
this._sortOrder = int.Parse(data[TableSpec.FIELD_SORTORDER]);
this._categoryId = int.Parse(data[TableSpec.FIELD_CATEGORYID]);
if(data[TableSpec.FIELD_LASTPOSTID] != "") {
this._lastPostId = int.Parse(data[TableSpec.FIELD_LASTPOSTID]);
} else {
this._lastPostId = null;
}
this._categoryId = Util.ParseInt(data[TableSpec.FIELD_CATEGORYID]);
this._lastPostId = Util.ParseInt(data[TableSpec.FIELD_LASTPOSTID]);
this._totalPosts = int.Parse(data[TableSpec.FIELD_TOTALPOSTS]);
this._totalThreads = int.Parse(data[TableSpec.FIELD_TOTALTHREADS]);
this._name = data[TableSpec.FIELD_NAME];
this._description = data[TableSpec.FIELD_DESCRIPTION];
this._parentBoardId = Util.ParseInt(data[TableSpec.FIELD_PARENTBOARDID]);
}
private readonly object subBoards_Locker = new object();
public IEnumerable<Board> subBoards {
get {
return
from id in Cache<IEnumerable<int>>.instance.get(
this.subBoards_Locker,
() => {
IEnumerable<int> ids = from stringId in Config.instance.mainConnection.LoadIdsByConditions(
TableSpec.instance,
new FLocal.Core.DB.conditions.ComparisonCondition(
TableSpec.instance.getColumnSpec(Board.TableSpec.FIELD_PARENTBOARDID),
FLocal.Core.DB.conditions.ComparisonType.EQUAL,
this.id.ToString()
),
Diapasone.unlimited,
new JoinSpec[0]
) select int.Parse(stringId);
Board.LoadByIds(ids);
return ids;
}
)
let board = Board.LoadById(id)
orderby board.sortOrder, board.id
select board;
}
}
private bool hasNewPosts() {
return Core.Util.RandomInt(0, 1) == 0;
return Core.Util.RandomInt(0, 1000) < 500;
}
private XElement exportLastPostInfo() {
@ -111,8 +146,8 @@ namespace FLocal.Common.dataobjects {
}
}
public XElement exportToXmlForMainPage() {
return new XElement("board",
public XElement exportToXmlForMainPage(UserContext context) {
XElement result = new XElement("board",
new XElement("id", this.id),
new XElement("sortOrder", this.sortOrder),
new XElement("categoryId", this.categoryId),
@ -123,6 +158,14 @@ namespace FLocal.Common.dataobjects {
new XElement("hasNewPosts", this.hasNewPosts() ? "true" : "false"),
new XElement("lastPostInfo", this.exportLastPostInfo())
);
if(!this.parentBoardId.HasValue) {
result.Add(new XElement("subBoards",
from board in this.subBoards select board.exportToXmlForMainPage(context)
));
}
return result;
}
}

@ -96,11 +96,11 @@ namespace FLocal.Common.dataobjects {
}
}
public XElement exportToXmlForMainPage() {
public XElement exportToXmlForMainPage(UserContext context) {
return new XElement("category",
new XElement("name", this.name),
new XElement("sortOrder", this.sortOrder),
new XElement("boards", from board in this.subBoards select board.exportToXmlForMainPage())
new XElement("boards", from board in this.subBoards select board.exportToXmlForMainPage(context))
);
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Common.dataobjects {
public interface IUserSettings {
int threadsPerPage {
get;
}
int postsPerPage {
get;
}
}
}

@ -112,6 +112,14 @@ namespace FLocal.Core {
return RandomString(length, RandomSource.LETTERS);
}
public static int? ParseInt(string raw) {
if(raw == "") {
return null;
} else {
return int.Parse(raw);
}
}
}
}

@ -34,7 +34,7 @@ namespace FLocal.IISHandler {
public static string Compile(string templateName, XDocument data) {
StringBuilder builder = new StringBuilder();
using(XmlWriter writer = XmlWriter.Create(builder, new XmlWriterSettings { Indent = true, NewLineHandling = NewLineHandling.None})) {
using(XmlWriter writer = XmlWriter.Create(builder, new XmlWriterSettings { Indent = false })) {
using(XmlReader reader = data.CreateReader()) {
TemplateCacher.instance.getCompiledTransform(templateName).Transform(reader, writer);
}

@ -5,7 +5,7 @@ using System.Text;
using System.Web;
namespace FLocal.IISHandler {
class WebContext {
class WebContext : Common.UserContext {
public readonly HttpContext httpcontext;
@ -21,15 +21,21 @@ namespace FLocal.IISHandler {
}
}
public designs.IDesign design {
public override Common.dataobjects.IUserSettings userSettings {
get {
return new designs.Classic();
return new Common.dataobjects.AnonymousUserSettings();
}
}
public override Common.IOutputParams outputParams {
get {
return this.design;
}
}
public Common.Config config {
public designs.IDesign design {
get {
return Common.Config.instance;
return new designs.Classic();
}
}

@ -10,5 +10,12 @@ namespace FLocal.IISHandler.designs {
return "Full";
}
}
string FLocal.Common.IOutputParams.preprocessBodyIntermediate(string bodyIntermediate) {
return bodyIntermediate.
Replace("<f:img><f:src>", "<img src=\"").
Replace("</f:src><f:alt>", "\" alt=\"").
Replace("</f:alt></f:img>", "\"/>");
}
}
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
namespace FLocal.IISHandler.designs {
interface IDesign {
interface IDesign : Common.IOutputParams {
string fsname {
get;

@ -10,5 +10,12 @@ namespace FLocal.IISHandler.designs {
return "Lite";
}
}
string FLocal.Common.IOutputParams.preprocessBodyIntermediate(string bodyIntermediate) {
return bodyIntermediate.
Replace("<f:img><f:src>", "<a href=\"").
Replace("</f:src><f:alt>", "\">").
Replace("</f:alt></f:img>", "</a>");
}
}
}

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FLocal.Common;
namespace FLocal.IISHandler.handlers {
abstract class AbstractGetHandler : ISpecificHandler {
@ -10,7 +12,16 @@ namespace FLocal.IISHandler.handlers {
get;
}
abstract protected System.Xml.Linq.XDocument getData(WebContext context);
abstract protected XElement[] getSpecificData(WebContext context);
private XDocument getData(WebContext context) {
return new XDocument(
new XElement("root",
new XElement("title", Config.instance.AppInfo),
this.getSpecificData(context)
)
);
}
public void Handle(WebContext context) {
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));

@ -17,16 +17,8 @@ namespace FLocal.IISHandler.handlers {
}
}
override protected XDocument getData(WebContext context) {
Board board1 = Board.LoadById(1);
Board board2 = Board.LoadById(2);
Board board3 = Board.LoadById(4);
return new XDocument(
new XElement("root",
new XElement("title", Config.instance.AppInfo),
new XElement("categories", from category in Category.allCategories select category.exportToXmlForMainPage())
)
);
override protected XElement[] getSpecificData(WebContext context) {
return new XElement[] { new XElement("categories", from category in Category.allCategories select category.exportToXmlForMainPage(context)) };
}
}

@ -15,7 +15,7 @@ namespace FLocal.IISHandler.handlers {
}
}
override protected XDocument getData(WebContext context) {
override protected XElement[] getSpecificData(WebContext context) {
throw new NotImplementedException();
}

@ -106,6 +106,14 @@
</td>
<td class="forumdescript"><xsl:value-of select="description"/></td>
</tr>
<xsl:if test="subBoards/board">
<tr>
<td class="forumdescript">&#160;</td>
<td class="forumdescript" style="padding-top:0.3em">
<xsl:apply-templates select="subBoards/board"/>
</td>
</tr>
</xsl:if>
</table>
</td>
<td width="7%" align="center" class="threadtotal" nowrap="nowrap"><xsl:value-of select="totalThreads"/></td>
@ -134,4 +142,13 @@
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="subBoards/board">
<span style="margin-left:0.5em;margin-right:0.5em">
<a>
<xsl:attribute name="href">/Threads/<xsl:value-of select="id"/>/</xsl:attribute>
<xsl:value-of select="description"/>
</a>
</span>
</xsl:template>
</xsl:stylesheet>
Loading…
Cancel
Save