Click here to Skip to main content
12,455,517 members (63,819 online)
Click here to Skip to main content

Stats

15.7K views
960 downloads
21 bookmarked
Posted

Signum Framework Tutorials Part 2 – Southwind Logic

, 15 Nov 2012 LGPL3
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
Northwind.bak
signumframework-signumframework-c6436e1
.gitignore
Local.testsettings
README.md
Signum.Engine
ClassDiagram1.cd
Connection
DynamicQuery
Engine
Linq
ExpressionVisitor
Meta
Properties
Schema
Schema.cd
SchemaBuilder
SignumFramework.pfx
Signum.Entities
Attributes.cd
Basics
ClassDiagram1.cd
Diagram.cd
DynamicQuery
Tokens
Patterns
Properties
Reflection
Services
SignumFramework.pfx
Signum.Framework.vsmdi
Signum.Test
ClassDiagram1.cd
LinqProvider
Properties
Signum.Utilities
DataStructures
IntervalDictionaries
ExpressionTrees
Properties
Reflection
SignumFramework.pfx
Synchronization
Signum.Web
ButtonBar
ControllerAttributes
Facades
HtmlHelpers
JSRenderer
LineHelpers
Lines
Mappings
PortableAreas
Repositories
Properties
Signum
Content
Controllers
Images
asc.gif
calendar.png
desc.gif
lineButtons.gif
sign_error.gif
Models
Scripts
Views
Widgets
SignumFramework.pfx
TypeContext
Widgets
Signum.Windows
Basics
Controls
ColorUtils
Converters
DynamicQuery
EntityControls
Facades
Fluent
Images
admin.png
alert.png
calendar.png
cancel.png
close.png
entity.png
find.png
forbidden.png
newColumn.png
newFilter.png
note.png
ok.png
pin.png
reload.png
save.png
star.png
Localization
MarkupExtensions
Properties
SignumFramework.pfx
Themes
Utilities
Widgets
SignumFrameworkSetup
SignumFrameworkSetup.vdproj
logo.ico
signumFramework2.0.jpg
Snippets
DroidSansMono.ttf
RazorSingleFileGenerator.vsix
Signum.Fonts.vssettings
T4template
entity.snippet
entityWithName.snippet
expressionMethod.snippet
expressionMethodQuery.snippet
expressionProperty.snippet
field.snippet
fieldCreacion.snippet
fieldEuro.snippet
fieldInicioFin.snippet
fieldString.snippet
fiff.snippet
propiedad.snippet
tran.snippet
Template
EntityControlTemplate
MyTemplate.vstemplate
SignumEntityControl.zip
__TemplateIcon.ico
Template
MyTemplate.vstemplate
ProjectName.Entities
MyTemplate.vstemplate
Properties
__TemplateIcon.ico
ProjectName.Load
MyTemplate.vstemplate
Properties
__TemplateIcon.ico
ProjectName.Logic
MyTemplate.vstemplate
Properties
__TemplateIcon.ico
ProjectName.Web
Code
Content
smoothness
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
MyTemplate.vstemplate
Properties
Scripts
ServerCapri.svc
Views
Capri
Home
Shared
__TemplateIcon.ico
favicon.ico
ProjectName.Windows
Controls
MyTemplate.vstemplate
Properties
__TemplateIcon.ico
SignumFramework2ClientServer.zip
__TemplateIcon.ico
WizardProjectName
Test
Properties
WizardProjectName
Isolated
Properties
SignumFramework.pfx
TraceAndTestImpact.testsettings
SignumFramework2Setup.msi
.gitignore
README.md
Southwind.vssscc
Southwind
Southwind.Entities
Properties
Southwind.Load
Properties
Southwind.Logic
Properties
Southwind.Web
Code
Content
smoothness
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
Properties
Scripts
ServerSouthwind.svc
Views
Home
Shared
Southwind
favicon.ico
Southwind.Windows
Controls
Properties
Southwind.bak
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Text;
using Signum.Utilities;
using System.Collections;
using System.IO;

namespace Signum.Web
{
    public class HtmlTag : IHtmlString
    {
        TagBuilder tagBuilder;
        public TagBuilder TagBuilder
        {
            get { return tagBuilder; }
        }

        public HtmlTag(string tagName)
        {
            tagBuilder = new TagBuilder(tagName);
        }

        public HtmlTag(string tagName, string id)
        {
            tagBuilder = new TagBuilder(tagName);

            if (!string.IsNullOrEmpty(id))
                tagBuilder.GenerateId(id);
        }

        public HtmlTag(TagBuilder tagBuilder)
        {
            this.tagBuilder = tagBuilder;
        }

        public HtmlTag Class(string value)
        {
            if (!string.IsNullOrEmpty(value))
                tagBuilder.AddCssClass(value);
            return this;
        }

        public HtmlTag Id(string id)
        {
            tagBuilder.GenerateId(id);
            return this;
        }

        public HtmlTag IdName(string id)
        {
            tagBuilder.GenerateId(id);
            tagBuilder.MergeAttribute("name", id); 
            return this;
        }

        public HtmlTag Attr(string key, string value)
        {
            tagBuilder.MergeAttribute(key, value);
            return this;
        }

        public HtmlTag Attr(string key, string value, bool replaceExisting)
        {
            tagBuilder.MergeAttribute(key, value, replaceExisting);
            return this;
        }

        public HtmlTag Attrs(object attributes)
        {
            tagBuilder.MergeAttributes(new RouteValueDictionary(attributes));
            return this;
        }

        public HtmlTag Attrs(object attributes, bool replaceExisting)
        {
            tagBuilder.MergeAttributes(new RouteValueDictionary(attributes), replaceExisting);
            return this;
        }

        public HtmlTag Attrs<TKey, TValue>(IDictionary<TKey, TValue> attributes)
        {
            tagBuilder.MergeAttributes(attributes);
            return this;
        }

        public HtmlTag Attrs<TKey, TValue>(IDictionary<TKey, TValue> attributes, bool replaceExisting)
        {
            tagBuilder.MergeAttributes(attributes, replaceExisting);
            return this;

        }

        public HtmlTag SetInnerText(string innerText)
        {
            tagBuilder.SetInnerText(innerText);
            return this;
        }

        public HtmlTag InnerHtml(MvcHtmlString html)
        {
            if (MvcHtmlString.IsNullOrEmpty(html))
                tagBuilder.InnerHtml = null;
            else
                tagBuilder.InnerHtml = html.ToHtmlString();

            return this;
        }

        public HtmlTag InnerHtml(params MvcHtmlString[] html)
        {
            if (html == null)
                tagBuilder.InnerHtml = null;
            else
                tagBuilder.InnerHtml = new HtmlStringBuilder(html).ToHtml().ToHtmlString();

            return this;
        }

        public override string ToString()
        {
            throw new InvalidOperationException("Call ToHtml instead");
        }

        public MvcHtmlString ToHtml()
        {
            return this.ToHtml(TagRenderMode.Normal);
        }

        public MvcHtmlString ToHtmlSelf()
        {
            return this.ToHtml(TagRenderMode.SelfClosing);
        }

        public MvcHtmlString ToHtml(TagRenderMode renderMode)
        {
            return MvcHtmlString.Create(tagBuilder.ToString(renderMode));
        }

        public static implicit operator MvcHtmlString(HtmlTag tag)
        {
            return tag.ToHtml(TagRenderMode.Normal);
        }

        public string ToHtmlString()
        {
            return tagBuilder.ToString(TagRenderMode.Normal);
        }
    }

    public static class HtmlStringExtensions
    {
        public static MvcHtmlString Concat(this MvcHtmlString one, MvcHtmlString other)
        {
            return MvcHtmlString.Create(one.ToHtmlString() + other.ToHtmlString());
        }

        public static MvcHtmlString Surround(this MvcHtmlString html, string tagName)
        {
            return html.Surround("<" + tagName + ">", "</" + tagName + ">"); 
        }

        public static MvcHtmlString Surround(this MvcHtmlString html, string startTag, string endTag)
        {
            if (MvcHtmlString.IsNullOrEmpty(html))
                return html; 

            return MvcHtmlString.Create(startTag + html.ToHtmlString() + endTag);
        }

        public static MvcHtmlString EncodeHtml(this string htmlToEncode)
        {
            return MvcHtmlString.Create(HttpUtility.HtmlEncode(htmlToEncode));
        }
    }

    public class HtmlStringBuilder: IEnumerable
    {
        StringBuilder sb = new StringBuilder();

        public HtmlStringBuilder() { }
        public HtmlStringBuilder(IEnumerable<MvcHtmlString> elements)
        {
            if(elements != null)
                foreach (var item in elements)
                {
                    sb.AppendLine(item.ToHtmlString());
                }
        }

        public void Add(MvcHtmlString html)
        {
            if (!MvcHtmlString.IsNullOrEmpty(html))
                sb.Append(html.ToHtmlString());
        }

        public void AddLine(MvcHtmlString html)
        {
            if (!MvcHtmlString.IsNullOrEmpty(html))
                sb.AppendLine(html.ToHtmlString());
        }

        public IDisposable Surround(string tagName)
        {
            return Surround(new HtmlTag(tagName));
        }

        public IDisposable Surround(HtmlTag div)
        {
            AddLine(div.ToHtml(TagRenderMode.StartTag));

            return new Disposable(() => AddLine(div.ToHtml(TagRenderMode.EndTag)));
        }

        public MvcHtmlString ToHtml()
        {
            return MvcHtmlString.Create(sb.ToString());
        }

        public override string ToString()
        {
            throw new InvalidOperationException("Call ToHtml instead");
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException("just to use collection initializers");
        }

        public System.IO.TextWriter TextWriter { get { return new StringWriter(sb); } }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

Olmo del Corral
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 15 Nov 2012
Article Copyright 2011 by Olmo del Corral
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid