Click here to Skip to main content
15,881,872 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 2 – Southwind Logic

Rate me:
Please Sign up or sign in to vote.
4.45/5 (6 votes)
15 Nov 2012LGPL325 min read 31.3K   1K   22  
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
using System;
using System.Windows.Markup;
using Signum.Utilities;

namespace Signum.Windows
{
    [MarkupExtensionReturnType(typeof(Uri))]
    public class PackUriExtension : MarkupExtension
    {
        public Location Location { get; set; }

        [ConstructorArgument("path")]
        public string Path { get; set; }

        string assemblyName;
        public string AssemblyName
        {
            get { return assemblyName; }
            set
            {
                assemblyName = value;
                Location = Location.ReferencedAssembly;
            }
        }

        public PackUriExtension()
        {
            Location = Location.LocalAssembly;
        }
        public PackUriExtension(string path)
        {
            this.Path = path;
            Location = Location.LocalAssembly;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            switch (Location)
            {
                case Location.LocalAssembly: return PackUriHelper.Local(Path);
                case Location.ReferencedAssembly: return PackUriHelper.Reference(Path, AssemblyName);
                case Location.SiteOfOrigin: return PackUriHelper.SiteOfOrigin(Path);
                default: throw new NotSupportedException();
            }
        }
    }

    public enum Location
    {
        // For files in the local assembly
        // eg Build Action = Page | Resource | Content
        LocalAssembly,

        // For files in the referenced assembly
        // eg Build Action = Page | Resource
        ReferencedAssembly,

        // For files at the site of origin
        // eg Build Action = None
        SiteOfOrigin
    }

    public static class PackUriHelper
    {
        public static Uri Local(string path)
        {
            return new Uri("pack://application:,,,/{0}".Formato(path), UriKind.Absolute);
        }

        public static Uri Reference(string path, Type assemblyTypeExample)
        {
            return Reference(path, assemblyTypeExample.Assembly.GetName().Name);
        }

        public static Uri Reference(string path, string assemblyName)
        {
            return new Uri("pack://application:,,,/{0};component/{1}".Formato(assemblyName, path), UriKind.Absolute);
        }

        public static Uri SiteOfOrigin(string path)
        {
            return new Uri("pack://siteoforigin:,,,/{0}".Formato(path), UriKind.Absolute);
        }
    }
}

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)


Written By
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...

Comments and Discussions