Problem with _activeObject

Posts   
 
    
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 05-Sep-2007 19:05:31   

When I execute the following code using the TemplateStudio using debugging and inspect the varaible values in the watch window - everything is fine. However, when I generate it through LLBLGenPro it never passes the "entity != null" condition.

Here is my .LPT file:

<[ System.Diagnostics ]> 
<% 
      Debugger.Break();
      %>//This comment is emitted into my files correctly<%
      EntityDefinition entity = _activeObject as EntityDefinition;
      if (entity != null)
      {
            %>//This comment is never reached by LLBLGen, but is reached with TemplateStudio while debugging<%
      }
%>

In both places, it is being emitted with a type of "allEntities"

Thoughts anyone? -Dave

dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 05-Sep-2007 19:22:50   

Ok, so I found a way to get this to work - but now it only works in LLBLGen and not in the TemplateStudio.

<[ System.Diagnostics ]>
<% 
      Debugger.Break();
      //the next line produces an exception in TemplateStudio but not in LLBLGen
      EntityDefinition currentEntity = ((Hashtable)_activeObject)["CurrentEntity"] as EntityDefinition;         
      if (currentEntity != null)
      {
            %>//This comment works fine in LLBLGenPro<%
      }
%>

If I run this in TemplateStudio with debugging, I get the following error:

Unable to cast object of type 'SD.LLBLGen.Pro.ApplicationCore.Entities.EntityDefinition' to type 'System.Collections.Hashtable'.

which makes sense, because the _activeObject is already an EntityDefinition and doesn't need to be cast as a HashTable...

Thoughts anyone?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 06-Sep-2007 14:50:13   

Are you sure you're executing the same presets? (I assume you're using v2.0) Which specific version are you using?

The thing is: templatestudio and llblgen pro use the same code to generate code, so there's no different. If you have installed templatestudio inside the llblgenpro folder, it also should use the exact same assemblies..

Frans Bouma | Lead developer LLBLGen Pro
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Sep-2007 00:03:02   

No, the only way I could figure out to get the "debugBuild" to work was if I created a preset that used the "SD.Tasks.Base.ConsumeLptTemplate" preset (see below):

<preset name="uFACTS Debug" lastModifiedOn="2007-09-05T11:45:46.375-05:00" createdBy="Me" isSealed="false" xmlns="http://sd/llblgen/pro/presetElementDefinitions.xsd">
  <supportedPlatforms>
    <platform name=".NET 2.0" />
    <platform name=".NET 3.0" />
  </supportedPlatforms>
  <supportedTemplateGroups>
    <templateGroup name="SelfServicing" />
  </supportedTemplateGroups>
  <taskPresets>
      <taskPreset name="SD.Tasks.Base.ConsumeLptTemplate">
        <parameters>
          <parameter name="destinationFolder" value="" />
          <parameter name="templateID" value="MySampleLPT" />
          <parameter name="emitType" value="allEntities" />
          <parameter name="debugBuild" value="true" />
        </parameters>
      </taskPreset>
  </taskPresets>
</preset>

When I execute the code in my actual environment, I am using a task which is based on the the CodeEmitter task:

        <task name="MyClassGenerator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" 
            taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.CodeEmitter" description="Generates my classes (test for debug)" isOptional="true">
            <supportedPlatforms/>
            <supportedTemplateGroups/>
            <dependencies/>
            <parameters>
                <parameter name="destinationFolder" value="TestClasses"/>
                <parameter name="filenameFormat" value="[elementName]Test.[extension]"/>
                <parameter name="templateID" value="MySample"/>
                <parameter name="emitType" value="allEntities" />
                <parameter name="templateBindingDefinitionName" value=""/>
                <parameter name="failWhenExistent" value="false"/>
            </parameters>
        </task>

Inside the MySample Template, I use the syntax:

<# MySampleLPT #>

So - I guess having the different preset is causing it to execute differently... The question becomes, how can I get the debugBuild working without using the SD.Tasks.Base.ConsumeLptTemplate task?

I've looked throughout the forum and everything I've tried just gives me the assembly, except when I us the SD.Tasks.Base.ConsumeLptTemplate task - that's the only time I can get the source...

HELP!! Thanks in advance...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 11-Sep-2007 14:52:30   

The first .lpt task that's encountered in the list of tasks is used to compile the complete set of .lpt templates referenced. If there's no such task, there's no debug build but a release build. if you just have an include template, it won't produce a debug build.

The reason for this issue is the distributed nature of the code generation process. It's indeed not flexible enough and we'll redesign parts of it in the future so it will be possible to specify if you want to have a debug build of a given template, no matter if it's the last task or not.

Frans Bouma | Lead developer LLBLGen Pro
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Sep-2007 16:01:14   

When I put the "ConsumeLptTemplate" at the top of my preset file with a "Blank" LPT that only contains a breakpoint it stop when processing the ConsumeLptTemplate and I can see the code (as it has been all along). Also, in that file I see all the other code from the Lpt scripts. However, when it processes the "SD.LLBLGen.Pro.TaskPerformers.CodeEmitter" preset, it still shows the assembly in the debugger (not the source which is shown when processing the ConsumeLptTemplate)...

<preset name="My Debug" lastModifiedOn="2007-09-05T11:45:46.375-05:00" createdBy="Me" isSealed="false" xmlns="http://sd/llblgen/pro/presetElementDefinitions.xsd">
  <supportedPlatforms>
    <platform name=".NET 2.0" />
    <platform name=".NET 3.0" />
  </supportedPlatforms>
  <supportedTemplateGroups>
    <templateGroup name="SelfServicing" />
  </supportedTemplateGroups>
  <taskPresets>
      <taskPreset name="SD.Tasks.Base.ConsumeLptTemplate">
        <parameters>
          <parameter name="destinationFolder" value="" />
          <parameter name="templateID" value="MyBlankLPT" />
          <parameter name="emitType" value="allEntities" />
          <parameter name="debugBuild" value="true" />
        </parameters>
      </taskPreset>
    <taskGroupPreset name="SD.Tasks.Base.GenericTaskGroup" displayName="Generated Folders" additionalDestinationFolder="_generated">
      <taskPreset name="MyClassGenerator" />
    </taskGroupPreset>
  </taskPresets>
</preset>

Again, this wouldn't be a problem because I could use the ConsumeLptTemplate to debug my Lpt scripts individually. However, the code appears to get execute differently (see first post) when I do that.

Any additional thoughts?

dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Sep-2007 22:40:18   

I was able to avoid this problem by using the following code:

    EntityDefinition currentEntity = null;
    if (_activeObject is EntityDefinition)
    {
        currentEntity = (EntityDefinition)_activeObject;
    }
    else
    {
        currentEntity = ((Hashtable)_activeObject)["CurrentEntity"] as EntityDefinition;
    }

This way, I can use the "ConsumeLptTemplate" for debugging and then the same LPT template will work in the CodeEmitter includes...

Hope that helps others working with the same issues... -Dave