Control RootNamespace for code generation

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 25-Sep-2006 04:29:30   

Otis says support for this is coming in 2.1 but I'm too impatient. So I give u: "RootNamespaceController" - TaskPerformer. Impressive name eh?

Add a task to append a namespace in ur preset, then add another to remove the namespace change.


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using SD.LLBLGen.Pro.ApplicationCore;
using SD.LLBLGen.Pro.GeneratorCore;

namespace OAMPS.TaskPerformers
{
    public class RootNamespaceController : TaskPerformerBase
    {
        bool result = false;

        public override void Perform(SD.LLBLGen.Pro.ApplicationCore.IGenerator executingGenerator, SD.LLBLGen.Pro.ApplicationCore.ITask taskDefinition, Dictionary<string, SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskParameter> parameters)
        {
            if (parameters == null)
            {
                throw new GeneratorAbortException("No parameters have been specified. Aborting generator.", taskDefinition);
            }
            if (parameters.Count <= 0)
            {
                throw new GeneratorAbortException("No parameters have been specified. Aborting generator.", taskDefinition);
            }

            string appendNamespace;
            bool removeAppendendedNamespace = false;

            if (!parameters.ContainsKey("appendNamespace"))
            {
                throw new GeneratorAbortException("Mandatory parameter 'appendNamespace' not found. Aborting generator.", taskDefinition);
            }

            appendNamespace = parameters["appendNamespace"].Value;

            if (parameters.ContainsKey("removeAppendendedNamespace"))
                removeAppendendedNamespace = parameters["removeAppendendedNamespace"].Value.ToLower(CultureInfo.InvariantCulture) == "true";

            string ns = executingGenerator.ProjectDefinition.RootNameSpace;

            if (removeAppendendedNamespace)
            {
                if (ns.EndsWith(appendNamespace))
                    executingGenerator.ProjectDefinition.RootNameSpace = ns.Substring(0, ns.Length - appendNamespace.Length - 1);
                else
                {
                    base.AddNewLogNode(taskDefinition.ElementLogNode, LogNodeType.ErrorDescription, "Namespace {0} not changed.", new object[] { executingGenerator.ProjectDefinition.RootNameSpace });
                }
            }
            else
                executingGenerator.ProjectDefinition.RootNameSpace = string.Concat(ns, ".", appendNamespace);

            base.LogLine("Namespace changed to " + executingGenerator.ProjectDefinition.RootNameSpace, "RootNamespaceController", true, true);
            base.AddNewLogNode(taskDefinition.ElementLogNode, LogNodeType.ActionDescription, "Namespace changed to {0}", new object[] { executingGenerator.ProjectDefinition.RootNameSpace });


            result = true;
        }

        public override void Perform(SD.LLBLGen.Pro.ApplicationCore.IGenerator executingGenerator, SD.LLBLGen.Pro.ApplicationCore.ITask taskDefinition)
        {
            throw new GeneratorAbortException("No parameters have been specified. Aborting generator.", taskDefinition);
        }

        public override bool PerformResult
        {
            get { return result; }
        }
    }
}

Heres a sample task for ur custom tasks file:


  <taskGroup name="Control namespace">
    <task name="Append Namespace" assemblyFilename="OAMPS.TaskPerformers.dll" taskPerformerClass="OAMPS.TaskPerformers.RootNamespaceController">
      <parameters>
        <parameter name="appendNamespace" isOptional="false" description="The namespace to append." />
        <parameter name="removeAppendendedNamespace" defaultValue="false" isOptional="false" description="True to remove the appended namespace or false to append it." />
      </parameters>
    </task>
    <task name="Remove Namespace" assemblyFilename="OAMPS.TaskPerformers.dll" taskPerformerClass="OAMPS.TaskPerformers.RootNamespaceController">
      <parameters>
        <parameter name="appendNamespace" isOptional="false" description="The namespace to append." />
        <parameter name="removeAppendendedNamespace" defaultValue="true" isOptional="false" description="True to remove the appended namespace or false to append it." />
      </parameters>
    </task>
  </taskGroup>

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 25-Sep-2006 10:01:48   

Thanks! simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 26-Sep-2006 13:04:12   

Uploaded! simple_smile

Frans Bouma | Lead developer LLBLGen Pro
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 26-Sep-2006 16:13:26   

Hi Frans,

I've finally realised that Otis == Frans flushed

Whats the svn path to find these, i looked under svndisappointed /www.sd.nl/llblgen but couldn't see it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 26-Sep-2006 16:16:58   

worldspawn wrote:

Hi Frans,

I've finally realised that Otis == Frans flushed

heh simple_smile

Whats the svn path to find these, i looked under svndisappointed /www.sd.nl/llblgen but couldn't see it.

These aren't in the subversion repository, they're just available in the 3rd party section. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 05-Oct-2006 23:49:26   

I downloaded this task performer from the 3rd party link and build the DLL. What I dont understand is how can this task perfromer be useful in having a different nameSpace for the BL. Problem: LLBL project reqquires specifying a rootNamesape for the generated DAL. If I generate the BL tier, I want it to have imports (using) for the DAL's nameSpace AND also for it to have its own different rootNameSpace

Solution: LLBL project can have a "BL RootNameSpace" property that can be referenced in a TDL template so that <[RootNamespace]> reference the RootNameSpace property <[BLRootNamespace]> references the BL RootNameSpace property

Having two (or maybe even more) RootNameSpace properties allows for building TDL templates in LLBL for different types of applications; BL, WinUI, WebUI, WebServices so that each can have its own nameSpace and also reference the nameSpace of the DAL.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 06-Oct-2006 09:42:40   

True, it's on the v2.1 feature list so it will be build in, however for the time being you've to do it with these intermediate solutions.

The philosophy behind the single rootnamespace is the following: the Microsoft guidelines say that a namespace should have a standard format: for example Company.Tool. etc. So it's my understanding that these ROOT namespaces dont change across tiers. What changes is the sub namespace inside the rootnamespace, which is controllable with a hardcoded name inside the templates (e.g. <[Rootnamespace]>.Gui )

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 06-Oct-2006 09:58:57   

Ok.. I get the idea. With this RootNameSpace controller I can give my LLBL project a RootNameSapce (companyName.projectName) and then use the RootNameSpaceController to "Apppend/Remove" (DAL) when generating the DAL project and "Append/Remove" (BL) when generating the BL project. Its a novel idea that has one shortcoming. What if I want to import/using both the (DAL) and (BL) namesapces in one TDL template file!! That will only be possible if I standarize on always using DAL and BL for these projects. I guess as you said thats a solution better than not having any... tell we get the new v2.1 feature...

Thanks alot worldspawn for sharing this.. simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 06-Oct-2006 13:55:13   

It's a feature which is apparently needed so I'll make sure it's added to v2.1. In what form is not defined yet, but it's requested a lot so I think it's necessary to add it simple_smile

Frans Bouma | Lead developer LLBLGen Pro
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 19-Oct-2006 01:04:17   

Your welcome smile